Example usage for java.util LinkedHashMap entrySet

List of usage examples for java.util LinkedHashMap entrySet

Introduction

In this page you can find the example usage for java.util LinkedHashMap entrySet.

Prototype

public Set<Map.Entry<K, V>> entrySet() 

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:com.cloud.utils.db.SqlGenerator.java

public List<Pair<String, Attribute[]>> buildInsertSqls() {
    LinkedHashMap<String, ArrayList<Attribute>> map = new LinkedHashMap<String, ArrayList<Attribute>>();
    for (Class<?> table : _tables) {
        map.put(DbUtil.getTableName(table), new ArrayList<Attribute>());
    }/*from  w  w w . j  a va  2  s  .  co  m*/

    for (Attribute attr : _attributes) {
        if (attr.isInsertable()) {
            ArrayList<Attribute> attrs = map.get(attr.table);
            assert (attrs != null) : "Null set of attributes for " + attr.table;
            attrs.add(attr);
        }
    }

    List<Pair<String, Attribute[]>> sqls = new ArrayList<Pair<String, Attribute[]>>(map.size());
    for (Map.Entry<String, ArrayList<Attribute>> entry : map.entrySet()) {
        ArrayList<Attribute> attrs = entry.getValue();
        StringBuilder sql = buildInsertSql(entry.getKey(), attrs);
        Pair<String, Attribute[]> pair = new Pair<String, Attribute[]>(sql.toString(),
                attrs.toArray(new Attribute[attrs.size()]));
        sqls.add(pair);
    }

    return sqls;
}

From source file:org.apache.flink.api.java.typeutils.runtime.kryo.KryoSerializer.java

@SuppressWarnings("unchecked")
@Override/*  w  w w.  j a v a2 s  .  c o m*/
public CompatibilityResult<T> ensureCompatibility(TypeSerializerConfigSnapshot<?> configSnapshot) {
    if (configSnapshot instanceof KryoSerializerConfigSnapshot) {
        final KryoSerializerConfigSnapshot<T> config = (KryoSerializerConfigSnapshot<T>) configSnapshot;

        if (type.equals(config.getTypeClass())) {
            LinkedHashMap<String, KryoRegistration> reconfiguredRegistrations = config.getKryoRegistrations();

            // reconfigure by assuring that classes which were previously registered are registered
            // again in the exact same order; new class registrations will be appended.
            // this also overwrites any dummy placeholders that the restored old configuration has
            reconfiguredRegistrations.putAll(kryoRegistrations);

            // check if there is still any dummy placeholders even after reconfiguration;
            // if so, then this new Kryo serializer cannot read old data and is therefore incompatible
            for (Map.Entry<String, KryoRegistration> reconfiguredRegistrationEntry : reconfiguredRegistrations
                    .entrySet()) {
                if (reconfiguredRegistrationEntry.getValue().isDummy()) {
                    LOG.warn("The Kryo registration for a previously registered class {} does not have a "
                            + "proper serializer, because its previous serializer cannot be loaded or is no "
                            + "longer valid but a new serializer is not available",
                            reconfiguredRegistrationEntry.getKey());

                    return CompatibilityResult.requiresMigration();
                }
            }

            // there's actually no way to tell if new Kryo serializers are compatible with
            // the previous ones they overwrite; we can only signal compatibility and hope for the best
            this.kryoRegistrations = reconfiguredRegistrations;
            return CompatibilityResult.compatible();
        }
    }

    return CompatibilityResult.requiresMigration();
}

From source file:Simulator.PerformanceCalculation.java

JPanel minmaxwaitTime2(boolean minCheck) {
    LinkedHashSet no = new LinkedHashSet();
    LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>();

    for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) {
        TraceObject traceObject = entry.getValue();

        if (wait1.get(traceObject.getSurgeonId()) == null) {
            ArrayList details = new ArrayList();
            details.add(traceObject.getWaitTime2());
            wait1.put(traceObject.getSurgeonId(), details);
        } else {//from  w w w. j a  va 2s.co  m
            wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime2());
        }

        no.add(traceObject.getSurgeonId());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();

    LinkedHashMap<Integer, Double> average = new LinkedHashMap<>();

    for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) {
        Integer integer = entry.getKey();
        ArrayList<Double> arrayList = entry.getValue();
        double value = 0;
        if (minCheck) {
            value = Collections.min(arrayList);
            value = value / 600;
        } else {
            value = Collections.max(arrayList);
            value = value / 600;
        }

        average.put(integer, value);
    }

    XYSeries series = new XYSeries("Surgeon Minimum Wait Time 2");
    for (int i = 1; i <= average.size(); i++) {
        series.add(i, average.get(i));
    }
    dataset.addSeries(series);
    String name;
    if (minCheck) {
        name = "Minimum";
    } else {
        name = "Maximum";
    }
    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(name + " Wait Time 2 For Patients", // Title
            "Surgeon ID", // x-axis Label
            "Time (Days)", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

    XYPlot xyPlot = (XYPlot) chart.getPlot();

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
    renderer.setBaseShapesVisible(true);
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setVerticalTickLabels(true);

    return new ChartPanel(chart);
}

From source file:Simulator.PerformanceCalculation.java

JPanel minmaxwaitTime1(boolean minCheck) {
    LinkedHashSet no = new LinkedHashSet();
    LinkedHashMap<Integer, ArrayList<Double>> wait1 = new LinkedHashMap<>();

    for (Map.Entry<Integer, TraceObject> entry : l.getLocalTrace().entrySet()) {
        TraceObject traceObject = entry.getValue();

        if (wait1.get(traceObject.getSurgeonId()) == null) {
            ArrayList details = new ArrayList();
            details.add(traceObject.getWaitTime1());
            wait1.put(traceObject.getSurgeonId(), details);
        } else {/*from  w w w  .  java  2s .c  o  m*/
            wait1.get(traceObject.getSurgeonId()).add(traceObject.getWaitTime1());
        }

        no.add(traceObject.getSurgeonId());
    }

    XYSeriesCollection dataset = new XYSeriesCollection();

    LinkedHashMap<Integer, Double> average = new LinkedHashMap<>();

    for (Map.Entry<Integer, ArrayList<Double>> entry : wait1.entrySet()) {
        Integer integer = entry.getKey();
        ArrayList<Double> arrayList = entry.getValue();
        double value = 0;
        if (minCheck) {
            value = Collections.min(arrayList);
            value = value / 600;
        } else {
            value = Collections.max(arrayList);
            value = value / 600;
        }

        average.put(integer, value);
    }

    XYSeries series = new XYSeries("Surgeon Minimum Wait Time 1");
    for (int i = 1; i <= average.size(); i++) {
        series.add(i, average.get(i));
    }
    dataset.addSeries(series);
    String name;
    if (minCheck) {
        name = "Minimum";
    } else {
        name = "Maximum";
    }
    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart(name + " Wait Time 1 For Patients", // Title
            "Surgeon ID", // x-axis Label
            "Time (Days)", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

    XYPlot xyPlot = (XYPlot) chart.getPlot();

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
    renderer.setBaseShapesVisible(true);
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setVerticalTickLabels(true);

    return new ChartPanel(chart);
}

From source file:ma.glasnost.orika.metadata.ScoringClassMapBuilder.java

/**
 * Gets all of the property expressions for a given type, including all nested properties.
 * If the type of a property is not immutable and has any nested properties, it will not
 * be included. (Note that the 'class' property is explicitly excluded.)
 * /*ww w . ja v a 2s  . c o  m*/
 * @param type the type for which to gather properties
 * @return the map of nested properties keyed by expression name
 */
protected Map<String, Property> getPropertyExpressions(Type<?> type) {

    PropertyResolverStrategy propertyResolver = getPropertyResolver();

    Map<String, Property> properties = new HashMap<String, Property>();
    LinkedHashMap<String, Property> toProcess = new LinkedHashMap<String, Property>(
            propertyResolver.getProperties(type));

    if (type.isMap() || type.isList() || type.isArray()) {
        Property selfReferenceProperty = new Property.Builder().name("").getter("").setter(" = %s")
                .type(TypeFactory.valueOf(type)).build((PropertyResolver) propertyResolver);
        toProcess.put("", selfReferenceProperty);
    }

    while (!toProcess.isEmpty()) {

        Entry<String, Property> entry = toProcess.entrySet().iterator().next();
        if (!entry.getKey().equals("class")) {
            Property owningProperty = entry.getValue();
            Type<?> propertyType = owningProperty.getType();
            if (!ClassUtil.isImmutable(propertyType)) {
                Map<String, Property> props = propertyResolver.getProperties(propertyType);
                if (propertyType.isMap()) {
                    Map<String, Property> valueProperties = getPropertyExpressions(
                            propertyType.getNestedType(1));
                    for (Entry<String, Property> prop : valueProperties.entrySet()) {
                        Property elementProp = new NestedElementProperty(entry.getValue(), prop.getValue(),
                                propertyResolver);
                        String key = entry.getKey() + PropertyResolver.ELEMENT_PROPERT_PREFIX + prop.getKey()
                                + PropertyResolver.ELEMENT_PROPERT_SUFFIX;
                        toProcess.put(key, elementProp);
                    }
                } else if (propertyType.isList()) {
                    Map<String, Property> valueProperties = getPropertyExpressions(
                            propertyType.getNestedType(0));
                    for (Entry<String, Property> prop : valueProperties.entrySet()) {
                        Property elementProp = new NestedElementProperty(owningProperty, prop.getValue(),
                                propertyResolver);
                        String key = entry.getKey() + PropertyResolver.ELEMENT_PROPERT_PREFIX
                                + prop.getValue().getExpression() + PropertyResolver.ELEMENT_PROPERT_SUFFIX;
                        toProcess.put(key, elementProp);
                    }
                } else if (propertyType.isArray()) {
                    Map<String, Property> valueProperties = getPropertyExpressions(
                            propertyType.getComponentType());
                    for (Entry<String, Property> prop : valueProperties.entrySet()) {
                        Property elementProp = new NestedElementProperty(entry.getValue(), prop.getValue(),
                                propertyResolver);
                        String key = entry.getKey() + PropertyResolver.ELEMENT_PROPERT_PREFIX + prop.getKey()
                                + PropertyResolver.ELEMENT_PROPERT_SUFFIX;
                        toProcess.put(key, elementProp);
                    }
                } else if (!props.isEmpty()) {
                    for (Entry<String, Property> property : props.entrySet()) {
                        if (!property.getKey().equals("class")) {
                            String expression = entry.getKey() + "." + property.getKey();
                            toProcess.put(expression, resolveProperty(type, expression));
                        }
                    }
                } else {
                    properties.put(entry.getKey(), resolveProperty(type, entry.getKey()));
                }
            } else {
                properties.put(entry.getKey(), resolveProperty(type, entry.getKey()));
            }
        }
        toProcess.remove(entry.getKey());
    }
    return properties;
}

From source file:at.ac.tuwien.inso.subcat.miner.SvnMiner.java

private void processCommit(String aAuthor, Date aDate, LinkedHashMap<String, FileStats> pathslist, String aMsg,
        String revision) throws SQLException, IOException {
    //TODO: Errorhandling to indicate that the SVN Log is not complete, e.g. Revisions for files are missing to have a complete file history

    Identity author = resolveIdentity(aAuthor);

    Identity committer = resolveIdentity(aAuthor);

    Date date = aDate;//from www  . j a v a 2 s . co m
    String msg = aMsg;

    // Lemmatize input - delivers String List, convert it to string
    msg = StringUtils.join(lemmatizer.lemmatize(msg), ", ");

    int filecount = pathslist.size();

    assert (date != null || msg != null || pathslist != null);

    Commit commit = model.addCommit(revision, project, author, committer, date, msg, filecount, 0, 0);

    Map<String, ManagedFile> commitFileCache = new HashMap();

    for (Map.Entry<String, FileStats> item : pathslist.entrySet()) {
        if (stopped == true) {
            break;
        }

        FileStats stats = item.getValue();
        String path = item.getKey();

        switch (stats.type) {
        case ADD:
            ManagedFile addedFile = model.addManagedFile(project, path);
            model.addFileChange(commit, addedFile, 0, 0, 0, 0, 0);
            fileCache.put(path, addedFile);
            commitFileCache.put(path, addedFile);
            break;

        case DELETE:
            //TODO: Evaluate whether a file may be added and deleted in the same commit and add commitfilecache logic
            //TODO: Identify reason, why SVN logs sometimes contain modifies and deletes to files that do not exist and are not renamed either
            if (!stats.isFile) {
                removeBulk(path, commit);
            } else {
                if (fileCache.get(path) != null) {
                    ManagedFile deletedFile = fileCache.get(path);
                    model.addFileDeletion(deletedFile, commit);
                    fileCache.remove(stats.oldPath);
                } else {
                    reporter.warning(this.getName(),
                            "could not find: " + path + " to delete in Revision " + revision + " @ SvnMiner");
                }

            }

            break;

        case MODIFY:
            if (stats.isFile) {
                //TODO: Identify reason, why SVN logs sometimes contain modifies and deletes to files that do not exist and are not renamed either
                if (fileCache.get(path) != null) {
                    ManagedFile modifiedFile = fileCache.get(path);

                    //Check if file exists in the commit already and skip the file, if it does
                    if (!commitFileCache.containsKey(path)) {
                        model.addFileChange(commit, modifiedFile, 0, 0, 0, 0, 0);
                        commitFileCache.put(path, modifiedFile);
                    }
                } else {
                    reporter.warning(this.getName(),
                            "could not find: " + path + " to modify in Revision " + revision + " @ SvnMiner");
                }
            }
            break;

        case RENAME:
            //TODO: SVN ADD and DELETE in the same commit is used as rename in SVN - this differentiation has not been implemented yet

            if (!stats.isFile) {
                renameBulk(stats.oldPath, path, commit, commitFileCache);
            } else {
                ManagedFile copyFile = model.addManagedFile(project, path);
                model.addFileChange(commit, copyFile, 0, 0, 0, 0, 0);
                fileCache.put(path, copyFile);
                commitFileCache.put(path, copyFile);
                //we dont remove during rename in SVN, since RENAME might also mean a copy command
                //fileCache.remove (stats.oldPath);
            }

            break;

        default:
            assert (false);
        }
    }

    emitTasksProcessed(1);

}

From source file:com.aliyun.odps.mapred.bridge.LOTGenerator.java

private Filter genPartitionFilter(LogicalOperatorTree.Builder tree, String sourceId,
        List<LinkedHashMap<String, String>> partList, String parentId) {
    LogicalOperator.Builder builder = LogicalOperator.newBuilder();
    Filter.Builder fb = Filter.newBuilder();

    List<ScalarExpression> parts = new ArrayList<ScalarExpression>();

    for (LinkedHashMap<String, String> partSpec : partList) {
        ScalarExpression lastCol = null;
        for (Map.Entry<String, String> e : partSpec.entrySet()) {
            ScalarExpression.Builder colBuilder = ScalarExpression.newBuilder();

            ScalarFunction.Builder eqBuilder = ScalarFunction.newBuilder();
            eqBuilder.setProject(project);
            eqBuilder.setName("EQ");

            ScalarExpression.Builder keyBuilder = ScalarExpression.newBuilder();
            Reference.Builder keyReference = Reference.newBuilder();
            keyReference.setName(e.getKey());
            keyReference.setFrom(sourceId);
            keyBuilder.setReference(keyReference.build());
            eqBuilder.addParameters(keyBuilder.build());

            ScalarExpression.Builder valueBuilder = ScalarExpression.newBuilder();
            Constant.Builder valueConstant = Constant.newBuilder();
            valueConstant.setString(e.getValue());
            valueBuilder.setConstant(valueConstant.build());
            eqBuilder.addParameters(valueBuilder.build());

            colBuilder.setExpression(eqBuilder.build());

            if (lastCol == null) {
                lastCol = colBuilder.build();
            } else {
                ScalarExpression.Builder newColBuilder = ScalarExpression.newBuilder();
                ScalarFunction.Builder andBuilder = ScalarFunction.newBuilder();
                andBuilder.setProject(project);
                andBuilder.setName("AND");
                andBuilder.addParameters(lastCol);
                andBuilder.addParameters(colBuilder.build());
                newColBuilder.setExpression(andBuilder.build());
                lastCol = newColBuilder.build();
            }/*from   w  w  w  .j av  a  2 s . c  o m*/
        }
        parts.add(lastCol);
    }

    // generate condition expression as binary tree, to limit nesting depth
    List<ScalarExpression> children = parts;
    while (children.size() > 1) {
        List<ScalarExpression> parents = new ArrayList<ScalarExpression>(children.size() / 2 + 1);
        for (int i = 0; i < children.size(); i += 2) {
            ScalarExpression eLeft = children.get(i);
            if (i + 1 >= children.size()) {
                parents.add(eLeft);
            } else {
                ScalarExpression eRight = children.get(i + 1);
                ScalarExpression.Builder parentBuilder = ScalarExpression.newBuilder();
                ScalarFunction.Builder orBuilder = ScalarFunction.newBuilder();
                orBuilder.setProject(project);
                orBuilder.setName("OR");
                orBuilder.addParameters(eLeft);
                orBuilder.addParameters(eRight);
                parentBuilder.setExpression(orBuilder.build());
                parents.add(parentBuilder.build());
            }
        }
        children = parents;
    }
    ScalarExpression partCond = children.get(0);

    fb.setCondition(partCond);
    fb.setParentId(parentId);
    fb.setId("FIL_" + opId++);

    Filter filter = fb.build();

    builder.setFilter(filter);
    tree.addOperators(builder.build());
    return filter;
}

From source file:ubic.gemma.web.controller.expression.experiment.DEDVController.java

private LinkedHashSet<ExperimentalFactor> getFactorNames(
        LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> eeLayouts) {
    LinkedHashSet<ExperimentalFactor> factorNames = new LinkedHashSet<>(); // need uniqueness & order
    for (BioAssayValueObject ba : eeLayouts.keySet()) {
        LinkedHashMap<ExperimentalFactor, Double> factorMap = eeLayouts.get(ba);
        for (Entry<ExperimentalFactor, Double> pair : factorMap.entrySet()) {
            if (pair.getKey() != null) {
                factorNames.add(pair.getKey());
            }/*  w w w . j a  v a 2s  . c o  m*/
        }
    }
    return factorNames;
}

From source file:com.aliyun.odps.mapred.bridge.LOTGenerator.java

private DataSink genTableSink(LogicalOperatorTree.Builder tree, TableInfo tableInfo, String parentId,
        boolean overwrite) {
    LogicalOperator.Builder builder = LogicalOperator.newBuilder();

    DataSink.Builder db = DataSink.newBuilder();

    TableSink.Builder tw = TableSink.newBuilder();
    tw.setProject(tableInfo.getProjectName() == null ? project : tableInfo.getProjectName());
    tw.setTable(tableInfo.getTableName());
    tw.setIsOverwrite(overwrite);//  w  w  w . ja v  a  2  s. c  o m

    LinkedHashMap<String, String> partSpec = tableInfo.getPartSpec();
    if (!partSpec.isEmpty()) {
        PartitionSpec.Builder pb = PartitionSpec.newBuilder();
        for (Map.Entry<String, String> e : partSpec.entrySet()) {
            PartitionSpec.Items.Builder ib = PartitionSpec.Items.newBuilder();
            ib.setKey(e.getKey());
            Constant.Builder cb = Constant.newBuilder();
            cb.setString(e.getValue());
            ib.setValue(cb.build());
            pb.addItems(ib.build());
        }
        tw.setPartition(pb.build());
    }

    db.setTableSink(tw.build());

    db.setParentId(parentId);
    db.setId("DataSink_" + opId++);

    DataSink dataSink = db.build();
    builder.setDataSink(dataSink);

    tree.addOperators(builder.build());

    return dataSink;
}

From source file:pl.betoncraft.betonquest.editor.model.QuestPackage.java

/**
 * Loads a package using a hashmap containing all data. The key is a file
 * name, the value is a hashmap containing keys and values of that YAML
 * file./* w w w.  j ava2 s.  c  om*/
 * 
 * @param map
 */
public QuestPackage(PackageSet set, String id, HashMap<String, LinkedHashMap<String, String>> data) {
    this.set = set;
    packName = new SimpleStringProperty(id);
    try {
        // handling journal.yml
        HashMap<String, String> journalMap = data.get("journal");
        if (journalMap != null) {
            int journalIndex = 0;
            for (Entry<String, String> entry : journalMap.entrySet()) {
                String value = entry.getValue();
                String[] parts = entry.getKey().split("\\.");
                // getting the right entry
                JournalEntry journalEntry = newByID(parts[0], name -> new JournalEntry(this, name));
                if (journalEntry.getIndex() < 0)
                    journalEntry.setIndex(journalIndex++);
                // handling entry data
                if (parts.length > 1) {
                    String lang = parts[1];
                    if (!languages.containsKey(lang)) {
                        languages.put(lang, 1);
                    } else {
                        languages.put(lang, languages.get(lang) + 1);
                    }
                    journalEntry.getText().addLang(lang, value);
                } else {
                    journalEntry.getText().setDef(value);
                }
            }
        }
        // handling items.yml
        HashMap<String, String> itemsMap = data.get("items");
        if (itemsMap != null) {
            int itemIndex = 0;
            for (String key : itemsMap.keySet()) {
                Item item = newByID(key, name -> new Item(this, name));
                item.getInstruction().set(itemsMap.get(key));
                if (item.getIndex() < 0)
                    item.setIndex(itemIndex++);
            }
        }
        // handling conditions.yml
        HashMap<String, String> conditionsMap = data.get("conditions");
        if (conditionsMap != null) {
            int conditionIndex = 0;
            for (String key : conditionsMap.keySet()) {
                Condition condition = newByID(key, name -> new Condition(this, name));
                condition.getInstruction().set(conditionsMap.get(key));
                if (condition.getIndex() < 0)
                    condition.setIndex(conditionIndex++);
            }
        }
        // handling event.yml
        HashMap<String, String> eventsMap = data.get("events");
        if (eventsMap != null) {
            int eventIndex = 0;
            for (String key : eventsMap.keySet()) {
                Event event = newByID(key, name -> new Event(this, name));
                event.getInstruction().set(eventsMap.get(key));
                if (event.getIndex() < 0)
                    event.setIndex(eventIndex++);
            }
        }
        // handling objectives.yml
        HashMap<String, String> objectivesMap = data.get("objectives");
        if (objectivesMap != null) {
            int objectiveIndex = 0;
            for (String key : objectivesMap.keySet()) {
                Objective objective = newByID(key, name -> new Objective(this, name));
                objective.getInstruction().set(objectivesMap.get(key));
                if (objective.getIndex() < 0)
                    objective.setIndex(objectiveIndex++);
            }
        }
        // handling conversations/
        int convIndex = 0;
        for (Entry<String, LinkedHashMap<String, String>> entry : data.entrySet()) {
            String key = entry.getKey();
            HashMap<String, String> value = entry.getValue();
            if (key.startsWith("conversations.")) {
                HashMap<String, String> convData = value;
                String convName = key.substring(14);
                Conversation conv = newByID(convName, name -> new Conversation(this, name));
                if (conv.getIndex() < 0)
                    conv.setIndex(convIndex++);
                int playerIndex = 0;
                int npcIndex = 0;
                // handling conversation.yml
                for (Entry<String, String> subEntry : convData.entrySet()) {
                    String subKey = subEntry.getKey();
                    String subValue = subEntry.getValue();
                    // reading NPC name, optionally in multiple languages
                    if (subKey.equals("quester")) {
                        conv.getNPC().setDef(subValue);
                    } else if (subKey.startsWith("quester.")) {
                        String lang = subKey.substring(8);
                        if (!languages.containsKey(lang)) {
                            languages.put(lang, 1);
                        } else {
                            languages.put(lang, languages.get(lang) + 1);
                        }
                        conv.getNPC().addLang(lang, subValue);
                    }
                    // reading the stop option
                    else if (subKey.equals("stop")) {
                        conv.getStop().set(subValue.equalsIgnoreCase("true"));
                    }
                    // reading starting options
                    else if (subKey.equals("first")) {
                        String[] pointerNames = subValue.split(",");
                        ArrayList<IdWrapper<NpcOption>> options = new ArrayList<>(pointerNames.length);
                        for (int i = 0; i < pointerNames.length; i++) {
                            IdWrapper<NpcOption> startingOption = new IdWrapper<>(this,
                                    conv.newNpcOption(pointerNames[i].trim()));
                            options.add(i, startingOption);
                            startingOption.setIndex(i);
                        }
                        conv.getStartingOptions().addAll(options);
                    }
                    // reading final events
                    else if (subKey.equals("final")) {
                        String[] eventNames = subValue.split(",");
                        ArrayList<IdWrapper<Event>> events = new ArrayList<>(eventNames.length);
                        for (int i = 0; i < eventNames.length; i++) {
                            IdWrapper<Event> finalEvent = new IdWrapper<>(this,
                                    newByID(eventNames[i].trim(), name -> new Event(this, name)));
                            events.add(i, finalEvent);
                            finalEvent.setIndex(i);
                        }
                        conv.getFinalEvents().addAll(events);
                    }
                    // reading NPC options
                    else if (subKey.startsWith("NPC_options.")) {
                        String[] parts = subKey.split("\\.");
                        if (parts.length > 1) {
                            String optionName = parts[1];
                            // resolving an option
                            NpcOption option = conv.newNpcOption(optionName);
                            if (option.getIndex() < 0)
                                option.setIndex(npcIndex++);
                            if (parts.length > 2) {
                                // getting specific values
                                switch (parts[2]) {
                                case "text":
                                    if (parts.length > 3) {
                                        String lang = parts[3];
                                        if (!languages.containsKey(lang)) {
                                            languages.put(lang, 1);
                                        } else {
                                            languages.put(lang, languages.get(lang) + 1);
                                        }
                                        option.getText().addLang(lang, subValue);
                                    } else {
                                        option.getText().setDef(subValue);
                                    }
                                    break;
                                case "event":
                                case "events":
                                    String[] eventNames = subValue.split(",");
                                    ArrayList<IdWrapper<Event>> events = new ArrayList<>(eventNames.length);
                                    for (int i = 0; i < eventNames.length; i++) {
                                        IdWrapper<Event> event = new IdWrapper<>(this,
                                                newByID(eventNames[i].trim(), name -> new Event(this, name)));
                                        events.add(i, event);
                                        event.setIndex(i);
                                    }
                                    option.getEvents().addAll(events);
                                    break;
                                case "condition":
                                case "conditions":
                                    String[] conditionNames = subValue.split(",");
                                    ArrayList<ConditionWrapper> conditions = new ArrayList<>(
                                            conditionNames.length);
                                    for (int i = 0; i < conditionNames.length; i++) {
                                        String name = conditionNames[i].trim();
                                        boolean negated = false;
                                        while (name.startsWith("!")) {
                                            name = name.substring(1, name.length());
                                            negated = true;
                                        }
                                        ConditionWrapper condition = new ConditionWrapper(this,
                                                newByID(name, idString -> new Condition(this, idString)));
                                        condition.setNegated(negated);
                                        conditions.add(i, condition);
                                        condition.setIndex(i);
                                    }
                                    option.getConditions().addAll(conditions);
                                    break;
                                case "pointer":
                                case "pointers":
                                    String[] pointerNames = subValue.split(",");
                                    ArrayList<IdWrapper<ConversationOption>> options = new ArrayList<>(
                                            pointerNames.length);
                                    for (int i = 0; i < pointerNames.length; i++) {
                                        IdWrapper<ConversationOption> pointer = new IdWrapper<>(this,
                                                conv.newPlayerOption(pointerNames[i].trim()));
                                        options.add(i, pointer);
                                        pointer.setIndex(i);
                                    }
                                    option.getPointers().addAll(options);
                                    break;
                                }
                            }
                        }
                    }
                    // reading player options
                    else if (subKey.startsWith("player_options.")) {
                        String[] parts = subKey.split("\\.");
                        if (parts.length > 1) {
                            String optionName = parts[1];
                            // resolving an option
                            PlayerOption option = conv.newPlayerOption(optionName);
                            if (option.getIndex() < 0) {
                                option.setIndex(playerIndex++);
                            }
                            if (parts.length > 2) {
                                // getting specific values
                                switch (parts[2]) {
                                case "text":
                                    if (parts.length > 3) {
                                        String lang = parts[3];
                                        if (!languages.containsKey(lang)) {
                                            languages.put(lang, 1);
                                        } else {
                                            languages.put(lang, languages.get(lang) + 1);
                                        }
                                        option.getText().addLang(lang, subValue);
                                    } else {
                                        option.getText().setDef(subValue);
                                    }
                                    break;
                                case "event":
                                case "events":
                                    String[] eventNames = subValue.split(",");
                                    ArrayList<IdWrapper<Event>> events = new ArrayList<>(eventNames.length);
                                    for (int i = 0; i < eventNames.length; i++) {
                                        IdWrapper<Event> event = new IdWrapper<>(this,
                                                newByID(eventNames[i].trim(), name -> new Event(this, name)));
                                        events.add(i, event);
                                        event.setIndex(i);
                                    }
                                    option.getEvents().addAll(events);
                                    break;
                                case "condition":
                                case "conditions":
                                    String[] conditionNames = subValue.split(",");
                                    ArrayList<ConditionWrapper> conditions = new ArrayList<>(
                                            conditionNames.length);
                                    for (int i = 0; i < conditionNames.length; i++) {
                                        String name = conditionNames[i].trim();
                                        boolean negated = false;
                                        while (name.startsWith("!")) {
                                            name = name.substring(1, name.length());
                                            negated = true;
                                        }
                                        ConditionWrapper condition = new ConditionWrapper(this,
                                                newByID(name, idString -> new Condition(this, idString)));
                                        condition.setNegated(negated);
                                        conditions.add(i, condition);
                                        condition.setIndex(i);
                                    }
                                    option.getConditions().addAll(conditions);
                                    break;
                                case "pointer":
                                case "pointers":
                                    String[] pointerNames = subValue.split(",");
                                    ArrayList<IdWrapper<ConversationOption>> options = new ArrayList<>(
                                            pointerNames.length);
                                    for (int i = 0; i < pointerNames.length; i++) {
                                        IdWrapper<ConversationOption> pointer = new IdWrapper<>(this,
                                                conv.newNpcOption(pointerNames[i].trim()));
                                        options.add(i, pointer);
                                        pointer.setIndex(i);
                                    }
                                    option.getPointers().addAll(options);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        // handling main.yml
        LinkedHashMap<String, String> config = data.get("main");
        for (Entry<String, String> entry : config.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            // handling variables
            if (key.startsWith("variables.")) {
                variables.add(new GlobalVariable(this, key.substring(10), value));
            }
            // handling global locations
            else if (key.startsWith("global_locations")) {
                for (String globLoc : value.split(",")) {
                    locations.add(new GlobalLocation(newByID(globLoc, name -> new Objective(this, name))));
                }
            }
            // handling static events
            else if (key.startsWith("static_events.")) {
                StaticEvent staticEvent = new StaticEvent(this, key.substring(14));
                staticEvent.getEvent().set(newByID(value, name -> new Event(this, name)));
                staticEvents.add(staticEvent);
            }
            // handling NPC-conversation bindings
            else if (key.startsWith("npcs.")) {
                npcBindings.add(new NpcBinding(this, key.substring(5),
                        newByID(value, name -> new Conversation(this, name))));
            }
            // handling quest cancelers
            else if (key.startsWith("cancel.")) {
                String[] parts = key.split("\\.");
                if (parts.length > 1) {
                    // getting the right canceler or creating new one
                    QuestCanceler canceler = newByID(parts[1], name -> new QuestCanceler(this, name));
                    // handling canceler properties
                    if (parts.length > 2) {
                        switch (parts[2]) {
                        case "name":
                            if (parts.length > 3) {
                                String lang = parts[3];
                                if (!languages.containsKey(lang)) {
                                    languages.put(lang, 1);
                                } else {
                                    languages.put(lang, languages.get(lang) + 1);
                                }
                                canceler.getName().addLang(lang, value);
                            } else {
                                canceler.getName().setDef(value);
                            }
                            break;
                        case "events":
                            String[] eventNames = value.split(",");
                            ArrayList<IdWrapper<Event>> events = new ArrayList<>(eventNames.length);
                            for (int i = 0; i < eventNames.length; i++) {
                                IdWrapper<Event> event = new IdWrapper<>(this,
                                        newByID(eventNames[i].trim(), name -> new Event(this, name)));
                                events.add(i, event);
                                event.setIndex(i);
                            }
                            canceler.getEvents().addAll(events);
                            break;
                        case "conditions":
                            String[] conditionNames = value.split(",");
                            ArrayList<ConditionWrapper> conditions = new ArrayList<>(conditionNames.length);
                            for (int i = 0; i < conditionNames.length; i++) {
                                String name = conditionNames[i].trim();
                                boolean negated = false;
                                while (name.startsWith("!")) {
                                    name = name.substring(1, name.length());
                                    negated = true;
                                }
                                ConditionWrapper condition = new ConditionWrapper(this,
                                        newByID(name, idString -> new Condition(this, idString)));
                                condition.setNegated(negated);
                                conditions.add(i, condition);
                                condition.setIndex(i);
                            }
                            canceler.getConditions().addAll(conditions);
                            break;
                        case "objectives":
                            String[] objectiveNames = value.split(",");
                            ArrayList<IdWrapper<Objective>> objectives = new ArrayList<>(objectiveNames.length);
                            for (int i = 0; i < objectiveNames.length; i++) {
                                IdWrapper<Objective> wrapper = new IdWrapper<>(this,
                                        newByID(objectiveNames[i].trim(), name -> new Objective(this, name)));
                                objectives.add(i, wrapper);
                                wrapper.setIndex(i);
                            }
                            canceler.getObjectives().addAll(objectives);
                            break;
                        case "tags":
                            String[] tagNames = value.split(",");
                            ArrayList<IdWrapper<Tag>> tags = new ArrayList<>(tagNames.length);
                            for (int i = 0; i < tagNames.length; i++) {
                                IdWrapper<Tag> wrapper = new IdWrapper<>(this,
                                        newByID(tagNames[i].trim(), name -> new Tag(this, name)));
                                tags.add(i, wrapper);
                                wrapper.setIndex(i);
                            }
                            canceler.getTags().addAll(tags);
                            break;
                        case "points":
                            String[] pointNames = value.split(",");
                            ArrayList<IdWrapper<PointCategory>> points = new ArrayList<>(pointNames.length);
                            for (int i = 0; i < pointNames.length; i++) {
                                IdWrapper<PointCategory> wrapper = new IdWrapper<>(this,
                                        newByID(pointNames[i].trim(), name -> new PointCategory(this, name)));
                                points.add(i, wrapper);
                                wrapper.setIndex(i);
                            }
                            canceler.getPoints().addAll(points);
                            break;
                        case "journal":
                            String[] journalNames = value.split(",");
                            ArrayList<IdWrapper<JournalEntry>> journal = new ArrayList<>(journalNames.length);
                            for (int i = 0; i < journalNames.length; i++) {
                                IdWrapper<JournalEntry> wrapper = new IdWrapper<>(this,
                                        newByID(journalNames[i].trim(), name -> new JournalEntry(this, name)));
                                journal.add(i, wrapper);
                                wrapper.setIndex(i);
                            }
                            canceler.getJournal().addAll(journal);
                            break;
                        case "loc":
                            canceler.setLocation(value);
                            break;
                        }
                    }
                }
            }
            // handling journal main page
            else if (key.startsWith("journal_main_page")) {
                String[] parts = key.split("\\.");
                if (parts.length > 1) {
                    MainPageLine line = newByID(parts[1], name -> new MainPageLine(this, name));
                    if (parts.length > 2) {
                        switch (parts[2]) {
                        case "text":
                            if (parts.length > 3) {
                                String lang = parts[3];
                                if (!languages.containsKey(lang)) {
                                    languages.put(lang, 1);
                                } else {
                                    languages.put(lang, languages.get(lang) + 1);
                                }
                                line.getText().addLang(lang, value);
                            } else {
                                line.getText().setDef(value);
                            }
                            break;
                        case "priority":
                            try {
                                line.getPriority().set(Integer.parseInt(value));
                            } catch (NumberFormatException e) {
                                // TODO error, need a number
                            }
                            break;
                        case "conditions":
                            String[] conditionNames = value.split(",");
                            ArrayList<ConditionWrapper> conditions = new ArrayList<>(conditionNames.length);
                            for (int i = 0; i < conditionNames.length; i++) {
                                String name = conditionNames[i].trim();
                                boolean negated = false;
                                while (name.startsWith("!")) {
                                    name = name.substring(1, name.length());
                                    negated = true;
                                }
                                ConditionWrapper condition = new ConditionWrapper(this,
                                        newByID(name, idString -> new Condition(this, idString)));
                                condition.setNegated(negated);
                                conditions.add(i, condition);
                                condition.setIndex(i);
                            }
                            line.getConditions().addAll(conditions);
                            break;
                        }
                    }
                }
            }
            // handling default language
            else if (key.equalsIgnoreCase("default_language")) {
                defLang = value;
            }
        }
        // check which language is used most widely and set it as default
        if (defLang == null) {
            int max = 0;
            String maxLang = null;
            for (Entry<String, Integer> entry : languages.entrySet()) {
                if (entry.getValue() > max) {
                    max = entry.getValue();
                    maxLang = entry.getKey();
                }
            }
            defLang = maxLang;
        }
    } catch (Exception e) {
        ExceptionController.display(e);
    }
}