Example usage for java.util Set contains

List of usage examples for java.util Set contains

Introduction

In this page you can find the example usage for java.util Set contains.

Prototype

boolean contains(Object o);

Source Link

Document

Returns true if this set contains the specified element.

Usage

From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java

public static List<String> filter(List<String> training, int threshold) {
    Set<Integer> filtered = training.stream().flatMap(line -> Stream.of(line.split(" ")).skip(1))
            .map(pair -> new Integer(pair.substring(0, pair.indexOf(":"))))
            .collect(groupingBy(i -> i, counting())).entrySet().stream()
            .filter(entry -> entry.getValue() >= threshold).map(Entry::getKey).collect(toSet());
    return training.stream().map(line -> line.split(" "))
            .map(fields -> fields[0] + " "
                    + String.join(" ", Stream.of(fields).skip(1).filter(
                            pair -> filtered.contains(new Integer(pair.substring(0, pair.indexOf(":")))))
                            .collect(toList())))
            .map(String::trim).collect(toList());
}

From source file:com.act.biointerpretation.l2expansion.L2FilteringDriver.java

private static L2PredictionCorpus runDbLookups(CommandLine cl, L2PredictionCorpus predictionCorpus,
        Options opts) throws IOException {

    if (cl.hasOption(OPTION_DB_LOOKUP)) {

        if (cl.hasOption(OPTION_LOOKUP_TYPES)) {

            LOGGER.info("Instantiating mongoDB.");
            MongoDB mongoDB = new MongoDB("localhost", 27017, cl.getOptionValue(OPTION_DB_LOOKUP));

            String[] lookupOptions = cl.getOptionValues(OPTION_LOOKUP_TYPES);
            Set<String> lookupSet = new HashSet<>();
            for (String option : lookupOptions) {
                if (!option.equals(LOOKUP_CHEMICALS) && !option.equals(LOOKUP_REACTIONS)) {
                    LOGGER.error("Invalid lookup option supplied: %s", option);
                    HELP_FORMATTER.printHelp(L2FilteringDriver.class.getCanonicalName(), HELP_MESSAGE, opts,
                            null, true);
                    System.exit(1);
                }/*from w ww .  j  ava2s.c  o m*/
                lookupSet.add(option);
            }

            if (lookupSet.contains(LOOKUP_CHEMICALS)) {
                LOGGER.info("Looking up chemicals in DB.");
                predictionCorpus = predictionCorpus.applyTransformation(new ChemicalsTransformer(mongoDB));
            }
            if (lookupSet.contains(LOOKUP_REACTIONS)) {
                LOGGER.info("Looking up reactions in DB.");
                predictionCorpus = predictionCorpus.applyTransformation(new ReactionsTransformer(mongoDB));
            }

        } else {
            LOGGER.warn("Mongo DB instantiated but lookup option not selected.");
        }
    }
    return predictionCorpus;
}

From source file:de.dfki.km.perspecting.obie.corpus.LabeledTextCorpus.java

public static Collection<String> scanWordContent(double probUseType, Set<String> matchPos,
        String[] wordFeatureVector, boolean useRegex) {

    Collection<String> returnValues = new HashSet<String>();

    if (wordFeatureVector.length == 4) {
        if (wordFeatureVector[LABEL].equals(OUTSIDE_ANY_LABEL)) {
            if (wordFeatureVector[POS].length() > 1
                    && matchPos.contains(wordFeatureVector[POS].substring(0, 2))) {
                returnValues.addAll(scanWordSyntax(wordFeatureVector, useRegex, false));
            } else {
                if (wordFeatureVector[LABEL].length() > 1) {
                    returnValues.addAll(scanWordSyntax(wordFeatureVector, useRegex, false));
                }//  w ww .  j ava  2s.c o m
            }
        } else {
            double d = new Random().nextDouble();
            if (d <= probUseType) {
                returnValues.add(wordFeatureVector[LABEL]);
            } else {
                if (wordFeatureVector[LABEL].length() > 1) {
                    returnValues.addAll(scanWordSyntax(wordFeatureVector, useRegex, false));
                }
            }
        }
    }
    return returnValues;
}

From source file:com.newatlanta.appengine.nio.file.GaePath.java

private static Set<OpenOption> checkOutputStreamOpenOptions(OpenOption... options) {
    Set<OpenOption> optionSet = getOpenOptionSet(options);
    if (optionSet.contains(READ)) {
        throw new IllegalArgumentException(READ.name());
    }/*from w  w w  .  j  av a 2  s.c  o m*/
    if (optionSet.contains(SYNC)) {
        throw new UnsupportedOperationException(SYNC.name());
    }
    if (optionSet.contains(DSYNC)) {
        throw new UnsupportedOperationException(DSYNC.name());
    }
    if (optionSet.contains(DELETE_ON_CLOSE)) {
        throw new UnsupportedOperationException(DELETE_ON_CLOSE.name());
    }
    if (optionSet.contains(SPARSE)) {
        throw new UnsupportedOperationException(SPARSE.name());
    }
    if (optionSet.contains(TRUNCATE_EXISTING)) {
        throw new UnsupportedOperationException(TRUNCATE_EXISTING.name());
    }
    return optionSet;
}

From source file:com.shieldsbetter.sbomg.ViewModelGenerator.java

private static ListElementTypeData outfitModelWithListElementType(ModelClass dest, String contextName,
        Set<String> options, Object elDesc) {
    ListElementTypeData result;//from   www . j  ava 2  s .  c  o m

    if (elDesc instanceof String) {
        result = new ListElementTypeData(options.contains("final"), options.contains("leaf"), (String) elDesc,
                false);
    } else if (elDesc instanceof Map) {
        String rawElementName = contextName + "Record";
        ModelClass r = new ModelClass(rawElementName, true);
        outfitModel(r, "", elDesc);

        boolean leaf = options.contains("leaf") || r.getListenerEventCount() == 0;

        dest.addType(r.buildTypeSpec());

        result = new ListElementTypeData(options.contains("final"), leaf, rawElementName, true);
    } else {
        throw new RuntimeException();
    }

    return result;
}

From source file:io.github.jeddict.jcode.util.POMManager.java

public static void addNBActionMappingProfile(String actionName, Project project, List<String> goals,
        List<String> profiles, Map<String, String> properties) {
    try {//  ww  w. j a v  a  2 s .  co m
        M2ConfigProvider configProvider = project.getLookup().lookup(M2ConfigProvider.class);
        NetbeansActionMapping actionMapping = ModelHandle2.getMapping(actionName, project,
                configProvider.getActiveConfiguration());
        if (actionMapping == null) {
            actionMapping = ModelHandle2.getDefaultMapping(actionName, project);
        }
        Set<String> existingGoals = new HashSet<>(actionMapping.getGoals());
        for (String goal : goals) {
            if (!existingGoals.contains(goal)) {
                actionMapping.addGoal(goal);
            }
        }
        Set<String> existingProfiles = new HashSet<>(actionMapping.getActivatedProfiles());
        for (String profile : profiles) {
            if (!existingProfiles.contains(profile)) {
                actionMapping.addActivatedProfile(profile);
            }
        }
        Map<String, String> existingProperties = actionMapping.getProperties();
        for (String key : properties.keySet()) {
            if (!existingProperties.containsKey(key)) {
                actionMapping.addProperty(key, properties.get(key));
            }
        }

        ModelHandle2.putMapping(actionMapping, project, configProvider.getActiveConfiguration());
    } catch (Exception e) {
        Exceptions.attachMessage(e, "Cannot persist action configuration.");
        Exceptions.printStackTrace(e);
    }
}

From source file:de.micromata.genome.jpa.metainf.MetaInfoUtils.java

public static String dumpMetaTableReferenceByTree(List<EntityMetadata> deps, boolean fullTree) {
    Set<EntityMetadata> printed = new HashSet<>();
    StringBuilder sb = new StringBuilder();
    for (EntityMetadata em : deps) {
        sb.append(em);//from  ww w  . ja  v  a2 s.  c om
        sb.append("\n");
        for (EntityMetadata re : em.getReferencedBy()) {

            if (fullTree == false) {
                if (printed.contains(re) == true) {
                    continue;
                }
                printed.add(re);
            }
            String ident = "  ";
            HashSet<EntityMetadata> used = new HashSet<>();

            dumpReferencePath(sb, re, fullTree ? used : printed, ident);
        }
    }
    return sb.toString();
}

From source file:net.solarnetwork.util.ClassUtils.java

/**
 * Get a Map of non-null bean properties for an object.
 * //from w  ww  . j  av  a  2 s  . co  m
 * @param o the object to inspect
 * @param ignore a set of property names to ignore (optional)
 * @return Map (never null)
 */
public static Map<String, Object> getBeanProperties(Object o, Set<String> ignore) {
    if (ignore == null) {
        ignore = DEFAULT_BEAN_PROP_NAME_IGNORE;
    }
    Map<String, Object> result = new LinkedHashMap<String, Object>();
    BeanWrapper bean = PropertyAccessorFactory.forBeanPropertyAccess(o);
    PropertyDescriptor[] props = bean.getPropertyDescriptors();
    for (PropertyDescriptor prop : props) {
        if (prop.getReadMethod() == null) {
            continue;
        }
        String propName = prop.getName();
        if (ignore != null && ignore.contains(propName)) {
            continue;
        }
        Object propValue = bean.getPropertyValue(propName);
        if (propValue == null) {
            continue;
        }
        result.put(propName, propValue);
    }
    return result;
}

From source file:gov.nasa.ensemble.resources.ResourceUtil.java

public static void removeBuilders(final IProject project, final String... builderIds) throws CoreException {
    final IProjectDescription description = project.getDescription();
    final Set<String> builderIdSet = new HashSet<String>(Arrays.asList(builderIds));
    final List<ICommand> newCommands = list(description.getBuildSpec()).filter(new Predicate<ICommand>() {
        @Override//  w  w w.  jav a2s.  c o m
        public boolean apply(ICommand command) {
            return builderIdSet.contains(command.getBuilderName());
        }
    });
    description.setBuildSpec(newCommands.toArray().array(ICommand[].class));
    // setting the description causes MAE-5218
    // project.setDescription(description, null);
}

From source file:freebase.api.FreebaseAPI.java

public static Set<Integer> filterBy(String inputfile, Set<Integer> keys, Integer column, String outputfile,
        Integer output_column) {//w  w  w .j av  a  2s. c  o m
    final List<String> input_list = Utils.readFileLineByLine(inputfile, true);
    StringBuilder output_str = new StringBuilder();
    Set<Integer> output_set = new HashSet();
    for (String line : input_list) {
        String[] split = line.split("\\t");
        Integer key = Integer.parseInt(split[column]);
        if (keys.contains(key)) {
            output_str.append(line).append(NEWLINE);
            if (output_column != null) {
                output_set.add(Integer.parseInt(split[output_column]));
            }
        }
    }
    Utils.writeDataIntoFile(output_str.toString(), outputfile);
    if (output_column != null) {
        return output_set;
    } else {
        return null;
    }
}