Example usage for java.util LinkedHashMap keySet

List of usage examples for java.util LinkedHashMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

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

Usage

From source file:org.jsweet.transpiler.candies.CandiesProcessor.java

private LinkedHashMap<File, CandyDescriptor> getCandiesDescriptorsFromClassPath(
        TranspilationHandler transpilationHandler) throws IOException {
    LinkedHashMap<File, CandyDescriptor> jarFilesCollector = new LinkedHashMap<>();
    for (String classPathEntry : classPath.split("[" + System.getProperty("path.separator") + "]")) {
        if (classPathEntry.endsWith(".jar")) {
            File jarFile = new File(classPathEntry);
            try (JarFile jarFileHandle = new JarFile(jarFile)) {
                JarEntry candySpecificEntry = jarFileHandle
                        .getJarEntry("META-INF/maven/" + JSweetConfig.MAVEN_CANDIES_GROUP);
                JarEntry candySpecificEntry2 = jarFileHandle.getJarEntry("META-INF/candy-metadata.json");
                boolean isCandy = candySpecificEntry != null || candySpecificEntry2 != null;
                if (isCandy) {
                    CandyDescriptor descriptor = CandyDescriptor.fromCandyJar(jarFileHandle,
                            candiesJavascriptOutDir.getAbsolutePath());

                    checkCandyVersion(descriptor, transpilationHandler);
                    jarFilesCollector.put(jarFile, descriptor);
                }/*from w ww.  j a  v a 2s.c  o m*/
            }

        }
    }
    logger.info(jarFilesCollector.keySet().size() + " candies found in classpath");

    return jarFilesCollector;
}

From source file:ubic.gemma.core.visualization.ExperimentalDesignVisualizationServiceImpl.java

@Override
public Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> sortVectorDataByDesign(
        Collection<DoubleVectorValueObject> dedVs) {

    // cachedLayouts.clear(); // uncomment FOR DEBUGGING.

    if (dedVs == null) {
        return new HashMap<>(0);
    }/*from  w  w  w.  j  av  a  2  s. com*/

    Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> returnedLayouts = new HashMap<>(
            dedVs.size());

    StopWatch timer = new StopWatch();
    timer.start();

    /*
     * This is shared across experiments that might show up in the dedVs; this should be okay...saves computation.
     * This is the only slow part.
     */
    this.prepare(dedVs);

    /*
     * This loop is not a performance issue.
     */
    Map<DoubleVectorValueObject, List<BioAssayValueObject>> newOrderingsForBioAssayDimensions = new HashMap<>();
    for (DoubleVectorValueObject vec : dedVs) {

        if (vec.isReorganized()) {
            continue;
        }

        assert !vec.getBioAssays().isEmpty();

        LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout = null;

        if (cachedLayouts.containsKey(vec.getExpressionExperiment().getId())) {
            layout = cachedLayouts.get(vec.getExpressionExperiment().getId());
        } else if (vec.getExpressionExperiment().getClass()
                .isInstance(ExpressionExperimentSubsetValueObject.class)) {
            // subset.
            layout = cachedLayouts.get(((ExpressionExperimentSubsetValueObject) vec.getExpressionExperiment())
                    .getSourceExperiment());
        }

        if (layout == null || layout.isEmpty()) {
            log.error("Did not find cached layout for " + vec.getId());
            continue;
        }

        List<BioAssayValueObject> newOrdering = new ArrayList<>(layout.keySet());

        newOrdering.retainAll(vec.getBioAssays());

        /*
         * This can happen if the vectors are out of whack with the bioassays - e.g. two platforms were used but
         * merging is not done. See bug 3775. Skipping the ordering is not the right thing to do.
         */
        if (newOrdering.isEmpty()) {

            boolean allNaN = this.allNaN(vec);

            if (allNaN) {
                // reordering will have no effect.
                continue;
            }

            /*
             * Add to the layout.
             */
            layout = this.extendLayout(vec, vec.getExpressionExperiment().getId());
            newOrdering = new ArrayList<>(layout.keySet());
            newOrdering.retainAll(vec.getBioAssays());
            assert !newOrdering.isEmpty();
        }

        newOrderingsForBioAssayDimensions.put(vec, newOrdering);

        Map<BioAssayValueObject, Integer> ordering = this.getOrdering(newOrdering);

        Long eeId;
        eeId = vec.getExpressionExperiment().getId(); // might be subset id.

        if (!returnedLayouts.containsKey(eeId)) {
            if (vec.isSliced()) {
                LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> trimmedLayout = new LinkedHashMap<>();

                for (BioAssayValueObject baVo : newOrdering) {
                    trimmedLayout.put(baVo, layout.get(baVo));
                }

                returnedLayouts.put(eeId, trimmedLayout);

            } else {
                returnedLayouts.put(eeId, layout);
            }
        }

        /*
         * Might be a faster way.
         */
        double[] data = vec.getData();
        double[] dol = ArrayUtils.clone(data);

        // assert ordering.size() == data.length : "got " + ordering.size() + " expected " + data.length;

        List<BioAssayValueObject> oldOrdering = vec.getBioAssayDimension().getBioAssays();
        int j = 0;
        if (log.isTraceEnabled())
            log.trace("Old order: " + StringUtils.join(ArrayUtils.toObject(data), ","));
        for (BioAssayValueObject ba : oldOrdering) {

            if (ordering.get(ba) == null) {
                assert Double.isNaN(dol[j]);
                j++;
                continue;
            }

            assert ordering.containsKey(ba);
            assert ordering.get(ba) != null;

            Integer targetIndex = ordering.get(ba);

            data[targetIndex] = dol[j++];

        }
        if (log.isTraceEnabled())
            log.trace("New order: " + StringUtils.join(ArrayUtils.toObject(data), ","));

        vec.setReorganized(true);

    }

    for (DoubleVectorValueObject vec : dedVs) {
        if (vec.getBioAssayDimension().isReordered())
            continue;
        List<BioAssayValueObject> newOrdering = newOrderingsForBioAssayDimensions.get(vec);
        if (newOrdering == null)
            continue; // data was empty, etc.
        vec.getBioAssayDimension().reorder(newOrdering);
    }

    if (timer.getTime() > 1500) {
        log.info("Sort vectors by design: " + timer.getTime() + "ms");
    }

    return returnedLayouts;

}

From source file:org.powertac.common.config.Configurator.java

/**
 * Creates and configures instances of the given class. In the configuration,
 * we expect to see a property of the form pkg.class.instances = a, b, c, ...
 * where a, b, c, etc. are the names of instances of the class to be created
 * and configured. These names are provided to the instances through their
 * constructors, and are expected to show up in the configuration as
 * instance names in clauses of the form
 * pkg.class.name.property = value.//from   w w w. j  a  v  a2  s.  co  m
 * Returns empty list in case instances cannot be created.
 */
public Collection<?> configureInstances(Class<?> type) {
    // If we don't have a configuration, we cannot do much.
    if (config == null) {
        log.error("Cannot configure - no Configuration set");
        return new ArrayList<Object>();
    }

    // compute the key for the instance list
    String classname = type.getName();
    log.debug("configuring instances for type " + classname);
    Configuration subset = extractSubsetForClassname(classname);
    // we should have a clause with the key "instances" giving the item
    // names, and a set of clauses for each item
    if (null == createdInstances.get(type)) {
        createdInstances.put(type, new HashSet<>());
    }
    Set<String> existingNames = createdInstances.get(type);
    List<Object> rawNames = subset.getList("instances");
    List<String> names = rawNames.stream().map(n -> n.toString()).filter(n -> !n.isEmpty())
            .collect(Collectors.toList());
    if (names.size() == 0) {
        log.warn("No instance names specified for class " + classname);
        return names;
    }
    dumpInstanceListMaybe(type, existingNames, names);

    // for each name, create an instance, add it to the result, and
    // configure it.
    LinkedHashMap<String, Object> itemMap = new LinkedHashMap<String, Object>();
    for (String name : names) {
        existingNames.add(name);
        try {
            Constructor<?> constructor = type.getConstructor(String.class);
            Object item = constructor.newInstance(name);
            itemMap.put(name, item);
        } catch (Exception e) {
            log.error("Unable to create instance " + name + " of class " + type + ": " + e.toString());
        }
    }
    // We now have a map of names and items to be configured.
    // We iterate through the map to avoid problems with items that did
    // not get created, although that seems far-fetched.
    for (String name : itemMap.keySet()) {
        configureInstance(itemMap.get(name), subset.subset(name), name);
    }
    return itemMap.values();
}

From source file:de.ingrid.importer.udk.strategy.v1.IDCStrategy1_0_9.java

/** Add gui ids of all NEW OPTIONAL fields to sys_gui table ! (mandatory fields not added, behavior not changeable) */
protected void updateSysGui() throws Exception {
    if (log.isInfoEnabled()) {
        log.info("Updating sys_gui...");
    }/*  w  ww. j  a v  a  2 s . c o  m*/

    if (log.isInfoEnabled()) {
        log.info("Add ids of new OPTIONAL fields !...");
    }

    LinkedHashMap<String, Integer> newSysGuis = new LinkedHashMap<String, Integer>();
    Integer initialBehaviour = -1; // default behaviour, optional field only shown if section expanded ! 
    //      Integer remove = 0; // do NOT show if section reduced (use case for optional fields ? never used) !
    //      Integer mandatory = 1; // do also show if section reduced (even if field optional) !

    newSysGuis.put("3260", initialBehaviour);
    newSysGuis.put("3630", initialBehaviour);
    newSysGuis.put("3600", initialBehaviour);
    newSysGuis.put("3640", initialBehaviour);
    newSysGuis.put("3645", initialBehaviour);
    newSysGuis.put("3650", initialBehaviour);
    newSysGuis.put("3670", initialBehaviour);

    Iterator<String> itr = newSysGuis.keySet().iterator();
    while (itr.hasNext()) {
        String key = itr.next();
        jdbc.executeUpdate("INSERT INTO sys_gui (id, gui_id, behaviour) VALUES (" + getNextId() + ", '" + key
                + "', " + newSysGuis.get(key) + ")");
    }

    if (log.isInfoEnabled()) {
        log.info("Updating sys_gui... done");
    }
}

From source file:de.ingrid.importer.udk.strategy.v2.IDCStrategy2_3_0.java

/** Add gui ids of all NEW OPTIONAL fields to sys_gui table ! (mandatory fields not added, behavior not changeable) */
protected void updateSysGui() throws Exception {
    if (log.isInfoEnabled()) {
        log.info("Updating sys_gui...");
    }/*from   w  w  w . j  ava2 s . c  o m*/

    if (log.isInfoEnabled()) {
        log.info("Add ids of new DataQuality Tables (OPTIONAL by default) !...");
    }

    LinkedHashMap<String, Integer> newSysGuis = new LinkedHashMap<String, Integer>();
    Integer initialBehaviour = -1; // default behaviour, optional field only shown if section expanded ! 
    //      Integer remove = 0; // do NOT show if section reduced (use case for optional fields ? never used) !
    //      Integer mandatory = 1; // do also show if section reduced (even if field optional) !

    // add  new sysgui Ids (dq tables)
    newSysGuis.put("7509", initialBehaviour);
    newSysGuis.put("7510", initialBehaviour);
    newSysGuis.put("7512", initialBehaviour);
    newSysGuis.put("7513", initialBehaviour);
    newSysGuis.put("7514", initialBehaviour);
    newSysGuis.put("7515", initialBehaviour);
    newSysGuis.put("7517", initialBehaviour);
    newSysGuis.put("7520", initialBehaviour);
    newSysGuis.put("7525", initialBehaviour);
    newSysGuis.put("7526", initialBehaviour);
    newSysGuis.put("7527", initialBehaviour);

    Iterator<String> itr = newSysGuis.keySet().iterator();
    while (itr.hasNext()) {
        String key = itr.next();
        jdbc.executeUpdate("INSERT INTO sys_gui (id, gui_id, behaviour) VALUES (" + getNextId() + ", '" + key
                + "', " + newSysGuis.get(key) + ")");
    }

    if (log.isInfoEnabled()) {
        log.info("Updating sys_gui... done");
    }
}

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());
            }/*from w w  w .jav a2 s. c  o  m*/
        }
    }
    return factorNames;
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

private void showWidgetThemeDialog() {

    // set themes list
    LinkedHashMap<String, String> themeList = global.mThemeManager.getThemeList(ThemeManager.LISTMODE_ALL);
    themeList.put("app_select", "Use App theme");
    final String[] keys = themeList.keySet().toArray(new String[themeList.keySet().size()]);
    String curTheme = mSharedPreferences.getString("widgettheme-" + mAppWidgetId, "app_select");
    int curIndex = 0;
    for (int i = 0; i < keys.length; i++) {
        if (keys[i].equals(curTheme)) {
            curIndex = i;/*  ww w. ja  v  a2s .  c o  m*/
            break;
        }
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Select Widget Theme")
            .setSingleChoiceItems(themeList.values().toArray(new String[themeList.values().size()]), curIndex,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            needsThemeUpdate = true;
                            SharedPreferences.Editor editor = mSharedPreferences.edit();
                            editor.putString("widgettheme-" + mAppWidgetId, keys[i]);
                            System.out.println(keys[i]);
                            editor.apply();
                            dialogInterface.cancel();
                        }
                    })
            .setPositiveButton("Close", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).show();
}

From source file:edu.jhuapl.openessence.datasource.jdbc.JdbcOeDataSource.java

protected void addGroupByClauses(final StringBuilder query, final LinkedHashMap<String, String> columns)
        throws OeDataSourceException {

    query.append(" GROUP BY ");

    final List<String> groupBySql = new ArrayList<String>();
    for (final String column : columns.keySet()) {
        String sqlSnippet = "";
        //added to check for an alias on sort
        DimensionBean bean = this.getBean(column);
        if (bean != null && bean.getSqlColAlias() != null && !"".equals(bean.getSqlColAlias())) {
            sqlSnippet = bean.getSqlColAlias();
        } else {/*from  w ww.j  a v  a 2 s  .  com*/
            sqlSnippet = columns.get(column);
        }
        if (sqlSnippet != null) {
            groupBySql.add(sqlSnippet);
        } else {
            throw new OeDataSourceException("You cannot use this dimension '" + column
                    + "' in groupby until you properly configure its sql column name. Please adjust your groovy definition file.");
        }
    }
    //query.append(StringUtils.collectionToDelimitedString(columns.values(), ","));
    query.append(StringUtils.collectionToDelimitedString(groupBySql, ", "));
}

From source file:org.apache.axis2.engine.MessageContextSaveCTest.java

/**
 * Compare two mappings containing object graph info.
 * This uses the class name and object ID.
 * <p/>//from  w w  w  . j  av  a 2s .c  o  m
 * Strict comparison includes the object hash codes. If
 * you expect the same object to be represented in
 * both maps, you may want to use Strict checking.
 * <p/>
 *
 * @param map1   The first object graph info map
 * @param map2   The second object graph info map
 * @param strict TRUE if strict comparison
 * @return Outcome of the comparison: TRUE if equivalent, FALSE otherwise
 */
private boolean compareObjectGraphInfo(LinkedHashMap map1, LinkedHashMap map2, boolean strict) {
    String title = "MessageContextSaveCTest: compareObjectGraphInfo(): ";

    if ((map1 != null) && (map2 != null)) {
        if (map1.size() != map2.size()) {
            log.debug(title + "Object graph info mappings are different sizes.");
            return false;
        }

        Iterator it = map1.keySet().iterator();

        while (it.hasNext()) {
            // the key is the class name associated with the object
            String key = (String) it.next();

            // skip certain objects, those will always be unique
            if ((key.indexOf("MessageContext") == -1) && (key.indexOf("OperationContext") == -1)
                    && (key.indexOf("ConfigurationContext") == -1)
                    && (key.indexOf("AxisConfiguration") == -1)) {
                // the class names listed above were not found
                // so we're dealing with the other objects
                MetaDataEntry value1 = (MetaDataEntry) map1.get(key);
                MetaDataEntry value2 = (MetaDataEntry) map2.get(key);

                if ((value1 != null) && (value2 != null)) {
                    // check the object identification
                    String name1 = value1.getName();
                    String name2 = value2.getName();

                    if ((name1 != null) && (name2 != null)) {
                        if (name1.equals(name2) == false) {
                            log.debug(title + "name1 [" + name1 + "]  !=   name2 [" + name2 + "]");
                            return false;
                        }
                    } else if ((name1 == null) && (name2 == null)) {
                        // ok
                    } else {
                        // mismatch
                        log.debug(title + "name1 [" + name1 + "]  !=   name2 [" + name2 + "]");
                        return false;
                    }

                    // Strict testing means checking the object hashcodes.
                    // Use this option when you expect the same
                    // objects in the map.
                    if (strict) {
                        String code1 = value1.getExtraName();
                        String code2 = value2.getExtraName();

                        if ((code1 != null) && (code2 != null)) {
                            if (code1.equals(code2) == false) {
                                log.debug(title + "name [" + name1 + "]  code1 [" + code1 + "]  !=   code2 ["
                                        + code2 + "]");
                                return false;
                            }
                        } else if ((code1 == null) && (code2 == null)) {
                            // ok
                        } else {
                            // mismatch
                            log.debug(title + "name [" + name1 + "]code1 [" + code1 + "]  !=   code2 [" + code2
                                    + "]");
                            return false;
                        }
                    }
                } else if ((value1 == null) && (value2 == null)) {
                    // ok
                } else {
                    // mismatch
                    log.debug(title + "value1 [" + value1 + "]  !=   value2 [" + value2 + "]");
                    return false;
                }
            }
        }

        return true;

    } else if ((map1 == null) && (map2 == null)) {
        return true;
    } else {
        log.debug(title + "mismatch: one or more of the maps are null.  ");
        return false;
    }

}

From source file:com.grarak.kerneladiutor.fragments.tools.ProfileFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (data == null)
        return;/*from ww w  . ja v a2 s .com*/
    if (requestCode == 0 || requestCode == 2) {
        LinkedHashMap<String, String> commandsList = new LinkedHashMap<>();
        ArrayList<String> ids = data.getStringArrayListExtra(ProfileActivity.RESULT_ID_INTENT);
        ArrayList<String> commands = data.getStringArrayListExtra(ProfileActivity.RESULT_COMMAND_INTENT);
        for (int i = 0; i < ids.size(); i++) {
            commandsList.put(ids.get(i), commands.get(i));
        }

        if (requestCode == 0) {
            create(commandsList);
        } else {
            Profiles.ProfileItem profileItem = mProfiles.getAllProfiles()
                    .get(data.getIntExtra(ProfileActivity.POSITION_INTENT, 0));

            for (Profiles.ProfileItem.CommandItem commandItem : profileItem.getCommands()) {
                if (ids.contains(commandItem.getPath())) {
                    profileItem.delete(commandItem);
                }
            }

            for (String path : commandsList.keySet()) {
                profileItem.putCommand(new Profiles.ProfileItem.CommandItem(path, commandsList.get(path)));
            }
            mProfiles.commit();
        }
    } else if (requestCode == 1) {
        ImportProfile importProfile = new ImportProfile(data.getStringExtra(FilePickerActivity.RESULT_INTENT));

        if (!importProfile.readable()) {
            Utils.toast(R.string.import_malformed, getActivity());
            return;
        }

        if (!importProfile.matchesVersion()) {
            Utils.toast(R.string.import_wrong_version, getActivity());
            return;
        }

        showImportDialog(importProfile);
    } else if (requestCode == 3) {
        reload();
    }
}