Example usage for java.util LinkedHashSet add

List of usage examples for java.util LinkedHashSet add

Introduction

In this page you can find the example usage for java.util LinkedHashSet add.

Prototype

boolean add(E e);

Source Link

Document

Adds the specified element to this set if it is not already present (optional operation).

Usage

From source file:org.pentaho.di.i18n.GlobalMessageUtil.java

/**
 * Returns a {@link LinkedHashSet} of {@link Locale}s for consideration when localizing text. The
 * {@link LinkedHashSet} contains the user selected preferred {@link Locale}, the failover {@link Locale}
 * ({@link Locale#ENGLISH}) and the {@link Locale#ROOT}.
 *
 * @return Returns a {@link LinkedHashSet} of {@link Locale}s for consideration when translating text
 *///from www .  ja  v  a2  s. co m
public static LinkedHashSet<Locale> getActiveLocales() {
    // Use a LinkedHashSet to maintain order
    final LinkedHashSet<Locale> activeLocales = new LinkedHashSet<>();
    // Example: messages_fr_FR.properties
    activeLocales.add(langChoice.getDefaultLocale());
    // Example: messages_en_US.properties
    activeLocales.add(FAILOVER_LOCALE);
    // Example: messages.properties
    activeLocales.add(Locale.ROOT);
    return activeLocales;
}

From source file:org.nuxeo.ecm.core.client.NuxeoApp.java

public static Collection<File> getBundleFiles(File baseDir, String bundles, String delim) throws IOException {
    LinkedHashSet<File> result = new LinkedHashSet<File>();
    StringTokenizer tokenizer = new StringTokenizer(bundles, delim == null ? " \t\n\r\f" : delim);
    while (tokenizer.hasMoreTokens()) {
        String tok = tokenizer.nextToken();
        List<File> files = expandFiles(baseDir, tok);
        for (File file : files) {
            result.add(file.getCanonicalFile());
        }/* w  w  w .  jav  a 2  s.  c  om*/
    }
    return result;
}

From source file:com.janrain.backplane2.server.Scope.java

/**
 * @return a new Scope consisting of all scope values present in the first one, less the auth-req scope values in 'revoke'
 *//*from w w w .ja  va 2  s  . c  o  m*/
public static Scope revoke(@NotNull Scope scope, @NotNull Scope revoke) {
    Map<BackplaneMessage.Field, LinkedHashSet<String>> newScope = new LinkedHashMap<BackplaneMessage.Field, LinkedHashSet<String>>();

    for (BackplaneMessage.Field scopeKey : scope.getScopeMap().keySet()) {
        Set<String> revokeValues = revoke.getScopeFieldValues(scopeKey);
        if (scopeKey.getScopeType() != ScopeType.AUTHZ_REQ || revokeValues == null || revokeValues.isEmpty()) {
            newScope.put(scopeKey, scope.getScopeMap().get(scopeKey));
        } else {
            LinkedHashSet<String> newValues = new LinkedHashSet<String>();
            for (String scopeValue : scope.getScopeFieldValues(scopeKey)) {
                if (!revokeValues.contains(scopeValue)) {
                    newValues.add(scopeValue);
                }
            }
            newScope.put(scopeKey, newValues);
        }
    }

    return new Scope(newScope);
}

From source file:nl.systemsgenetics.genenetworkbackend.hpo.TestDiseaseGenePerformance.java

public static HashSet<String> loadHpoExclude(File hposToExclude) throws IOException {

    LinkedHashSet<String> hpos = new LinkedHashSet<>();

    BufferedReader reader = new BufferedReader(new FileReader(hposToExclude));

    String line;/*from  www  . j ava 2s  .  com*/
    while ((line = reader.readLine()) != null) {
        hpos.add(line);
    }

    return hpos;

}

From source file:org.vedantatree.expressionoasis.ExpressionEngine.java

License:asdf

/**
 * Retrieves a set of variable names contained within the specified expression string
 * //from   w  ww . ja v  a 2 s. co  m
 * @param expression the expression to extract the variable names for
 * @return a set of variable names contained within the specified expression string
 * @throws ExpressionEngineException
 */
public static Set<String> getVariableNames(String expression) throws ExpressionEngineException {
    // it may matter to a user of this code what order the variable names are in, hence LinkedHashSet
    LinkedHashSet<String> variableNames = new LinkedHashSet<String>();

    Expression exp = compileExpression(expression, new ExpressionContext(), false);
    ExpressionTypeFinder finder = new ExpressionTypeFinder(exp, IdentifierExpression.class);
    Set<Expression> foundVariables = finder.getExpressions();

    for (Expression variable : foundVariables) {
        String variableName = ((IdentifierExpression) variable).getIdentifierName();
        variableNames.add((variableName));
    }

    return variableNames;
}

From source file:org.openhab.binding.network.service.NetworkUtils.java

/**
 * Takes the interfaceIPs and fetches every IP which can be assigned on their network
 *
 * @param networkIPs The IPs which are assigned to the Network Interfaces
 * @return Every single IP which can be assigned on the Networks the computer is connected to
 *//*from www .j ava 2s.  co m*/
public static LinkedHashSet<String> getNetworkIPs(TreeSet<String> interfaceIPs) {
    LinkedHashSet<String> networkIPs = new LinkedHashSet<String>();

    for (Iterator<String> it = interfaceIPs.iterator(); it.hasNext();) {
        try {
            // gets every ip which can be assigned on the given network
            SubnetUtils utils = new SubnetUtils(it.next());
            String[] addresses = utils.getInfo().getAllAddresses();
            for (int i = 0; i < addresses.length; i++) {
                networkIPs.add(addresses[i]);
            }

        } catch (Exception ex) {
        }
    }

    return networkIPs;
}

From source file:org.apache.solr.SolrTestCaseHS.java

@SafeVarargs
public static <T> Set<T> set(T... a) {
    LinkedHashSet<T> s = new LinkedHashSet<>();
    for (T t : a) {
        s.add(t);
    }//from  w  w w .j  a v  a2  s.c o m
    return s;
}

From source file:fredboat.command.music.control.SelectCommand.java

static void select(CommandContext context) {
    Member invoker = context.invoker;
    GuildPlayer player = PlayerRegistry.getOrCreate(context.guild);
    VideoSelection selection = VideoSelection.get(invoker);
    if (selection == null) {
        context.reply(context.i18n("selectSelectionNotGiven"));
        return;/*from w  w  w  . ja v  a  2 s .c  om*/
    }

    try {
        //Step 1: Parse the issued command for numbers

        // LinkedHashSet to handle order of choices + duplicates
        LinkedHashSet<Integer> requestChoices = new LinkedHashSet<>();

        // Combine all args and the command trigger. if the trigger is not a number it will be sanitized away
        String commandOptions = (context.trigger + " " + context.rawArgs).trim();
        String sanitizedQuery = sanitizeQueryForMultiSelect(commandOptions).trim();

        if (StringUtils.isNumeric(commandOptions)) {
            requestChoices.add(Integer.valueOf(commandOptions));
        } else if (TextUtils.isSplitSelect(sanitizedQuery)) {
            // Remove all non comma or number characters
            String[] querySplit = sanitizedQuery.split(",|\\s");

            for (String value : querySplit) {
                if (StringUtils.isNumeric(value)) {
                    requestChoices.add(Integer.valueOf(value));
                }
            }
        }

        //Step 2: Use only valid numbers (usually 1-5)

        ArrayList<Integer> validChoices = new ArrayList<>();
        // Only include valid values which are 1 to <size> of the offered selection
        for (Integer value : requestChoices) {
            if (1 <= value && value <= selection.choices.size()) {
                validChoices.add(value);
            }
        }

        //Step 3: Make a selection based on the order of the valid numbers

        // any valid choices at all?
        if (validChoices.isEmpty()) {
            throw new NumberFormatException();
        } else {
            AudioTrack[] selectedTracks = new AudioTrack[validChoices.size()];
            StringBuilder outputMsgBuilder = new StringBuilder();

            for (int i = 0; i < validChoices.size(); i++) {
                selectedTracks[i] = selection.choices.get(validChoices.get(i) - 1);

                String msg = context.i18nFormat("selectSuccess", validChoices.get(i),
                        selectedTracks[i].getInfo().title,
                        TextUtils.formatTime(selectedTracks[0].getInfo().length));
                if (i < validChoices.size()) {
                    outputMsgBuilder.append("\n");
                }
                outputMsgBuilder.append(msg);

                player.queue(new AudioTrackContext(selectedTracks[i], invoker));
            }

            VideoSelection.remove(invoker);
            TextChannel tc = FredBoat.getTextChannelById(selection.channelId);
            if (tc != null) {
                CentralMessaging.editMessage(tc, selection.outMsgId,
                        CentralMessaging.from(outputMsgBuilder.toString()));
            }

            player.setPause(false);
            context.deleteMessage();
        }
    } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) {
        context.reply(context.i18nFormat("selectInterval", selection.choices.size()));
    }
}

From source file:org.broad.igv.gitools.Gitools.java

public static void exportTDM(List<String> lociStrings, File file) throws IOException {

    // Convert the loci strings to a list of loci, if the loci represents multiple features (e.g. isoforms) use the largest
    int averageFeatureSize = 0;
    List<NamedFeature> loci = new ArrayList<NamedFeature>(lociStrings.size());
    for (String l : lociStrings) {
        NamedFeature feature = FeatureDB.getFeature(l);
        if (feature == null) {
            feature = Locus.fromString(l);
        }/*from   ww w.  jav a 2 s.  c  om*/
        if (feature != null) {
            loci.add(feature);
            averageFeatureSize += (feature.getEnd() - feature.getStart());
        }
    }
    if (loci.size() > 0)
        averageFeatureSize /= loci.size();

    // Determine data types -- all data tracks + mutation, and samples
    LinkedHashSet<TrackType> loadedTypes = new LinkedHashSet<TrackType>();

    List<Track> tracks = IGV.getInstance().getAllTracks();
    for (Track t : tracks) {
        if ((t instanceof DataTrack || t.getTrackType() == TrackType.MUTATION) && t.isVisible()) {
            loadedTypes.add(t.getTrackType());
            //samples.add(t.getSample());
        }
    }

    // set an appropriate zoom level for this feature set.  Very approximate
    int zoom = 0;
    Genome genome = GenomeManager.getInstance().getCurrentGenome();
    if (genome != null) {
        double averageChrLength = genome.getTotalLength() / genome.getChromosomes().size();
        zoom = (int) (Math.log(averageChrLength / averageFeatureSize) / Globals.log2) + 1;
    }

    // Loop though tracks and loci and gather data by sample & gene
    Map<String, SampleData> sampleDataMap = new LinkedHashMap<String, SampleData>();
    for (Track t : tracks) {
        if (!t.isVisible())
            continue;

        String sampleName = t.getSample();
        List<Track> overlays = IGV.getInstance().getOverlayTracks(t);

        for (NamedFeature locus : loci) {

            double regionScore;
            if (t instanceof DataTrack) {
                DataTrack dataTrack = (DataTrack) t;
                regionScore = dataTrack.getAverageScore(locus.getChr(), locus.getStart(), locus.getEnd(), zoom);
                addToSampleData(sampleDataMap, sampleName, locus.getName(), t.getTrackType(), regionScore);
            }

            if (overlays != null) {
                for (Track overlay : overlays) {
                    if (overlay.getTrackType() == TrackType.MUTATION) {
                        regionScore = overlay.getRegionScore(locus.getChr(), locus.getStart(), locus.getEnd(),
                                zoom, RegionScoreType.MUTATION_COUNT, locus.getName());
                        //Only add if we found a mutation. Should we put it in anyway?
                        if (regionScore > 0) {
                            addToSampleData(sampleDataMap, sampleName, locus.getName(), overlay.getTrackType(),
                                    regionScore);
                        }
                    }
                }
            }
        }

    }

    writeTDM(loadedTypes, sampleDataMap, file);
}

From source file:de.qaware.chronix.solr.type.metric.SolrDocumentBuilder.java

/**
 * Merges to sets of time series attributes.
 * The result is set for each key holding the values.
 * If the other value is a collection, than all values
 * of the collection are added instead of the collection object.
 *
 * @param merged     the merged attributes
 * @param attributes the attributes of the other time series
 *///from www  . j av a2s  .  c  o m
private static void merge(Map<String, Object> merged, Map<String, Object> attributes) {

    for (HashMap.Entry<String, Object> newEntry : attributes.entrySet()) {

        String key = newEntry.getKey();

        //we ignore the version in the result
        if (key.equals("_version_")) {
            continue;
        }

        if (!merged.containsKey(key)) {
            merged.put(key, new LinkedHashSet());
        }

        LinkedHashSet values = (LinkedHashSet) merged.get(key);
        Object value = newEntry.getValue();

        //Check if the value is a collection.
        //If it is a collection we add all values instead of adding a collection object
        if (value instanceof Collection && !values.contains(value)) {
            values.addAll((Collection) value);
        } else if (!values.contains(value)) {
            //Otherwise we have a single value or an array.
            values.add(value);
        }
        //otherwise we ignore the value
    }
}