class NcFileStitcher {

    static void setGlobalAttributes(SlstrNFileWritable nFileWriteable, List<Attribute>[] globalAttributeLists,
                                    String parentDirectoryName, Date creationDate) throws IOException {
        final DateFormatConverter globalAttributesDateFormatConverter =
                new DateFormatConverter(new SimpleDateFormat("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"));
        List<String> namesOfAddedAttributes = new ArrayList<>();
        for (int i = 0; i < globalAttributeLists.length; i++) {
            List<Attribute> globalAttributes = globalAttributeLists[i];
            for (Attribute globalAttribute : globalAttributes) {
                final String globalAttributeName = globalAttribute.getFullName();
                if (!namesOfAddedAttributes.contains(globalAttributeName)) {
                    if (globalAttributeName.equals(PRODUCT_NAME)) {
                        nFileWriteable.addGlobalAttribute(PRODUCT_NAME, parentDirectoryName);
                    } else if (globalAttributeName.equals(CREATION_TIME)) {
                        nFileWriteable.addGlobalAttribute(CREATION_TIME,
                                                          globalAttributesDateFormatConverter.format(creationDate));
                    } else if (globalAttribute.isArray()) {
                        final Array values = globalAttribute.getValues();
                        for (int j = i; j < globalAttributeLists.length; j++) {
                            final Attribute otherGlobalAttribute =
                                    getAttributeFromList(globalAttributeName, globalAttributeLists[j]);
                            if (otherGlobalAttribute != null && values != otherGlobalAttribute.getValues() && !otherGlobalAttribute.getFullName().equals(globalAttribute.getFullName())) {
                                nFileWriteable.addGlobalAttribute(globalAttributeName + "_" + j,
                                                                  otherGlobalAttribute.getValues().toString());
                                break;
                            }
                        }
                        nFileWriteable.addGlobalAttribute(globalAttributeName, values.toString());
                    } else if (globalAttribute.getDataType().isNumeric()) {
                        final Number value = globalAttribute.getNumericValue();
                        for (int j = i; j < globalAttributeLists.length; j++) {
                            final Attribute otherGlobalAttribute =
                                    getAttributeFromList(globalAttributeName, globalAttributeLists[j]);
                            if (otherGlobalAttribute != null && !value.equals(otherGlobalAttribute.getNumericValue())) {
                                nFileWriteable.addGlobalAttribute(globalAttributeName + "_" + j,
                                                                  otherGlobalAttribute.getNumericValue());
                                break;
                            }
                        }
                        nFileWriteable.addGlobalAttribute(globalAttributeName, value.toString());
                    } else {
                        final String value = globalAttribute.getStringValue();
                        for (int j = i; j < globalAttributeLists.length; j++) {
                            final Attribute otherGlobalAttribute =
                                    getAttributeFromList(globalAttributeName, globalAttributeLists[j]);
                            if ((otherGlobalAttribute != null && otherGlobalAttribute.getStringValue() != null)) {
                                if (!value.equals(otherGlobalAttribute.getStringValue())) {
                                    nFileWriteable.addGlobalAttribute(globalAttributeName + "_" + j,
                                            otherGlobalAttribute.getStringValue());
                                    break;

                                }
                            }
                        }
                        if (value != null) {
                            nFileWriteable.addGlobalAttribute(globalAttributeName, value);
                        }
                    }
                }
                namesOfAddedAttributes.add(globalAttributeName);
            }
        }
    }

}