Java Examples for java.util.Set

The following java examples will help you to understand the usage of java.util.Set. These source code samples are taken from different open source projects.

Example 1
Project: liferay-ide-master  File: ProjectNamesPossibleValuesService.java View source code
@Override
protected void compute(Set<String> values) {
    for (IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
        if (project != null && project.isAccessible()) {
            values.add(project.getName());
        }
    }
}
Example 2
Project: turmeric-eclipse-master  File: TestCollectionUtil.java View source code
/**
	 * Test method for [email protected] [email protected]til#intersection(java.util.Set, java.util.Set)}.
	 */
@Test
public void testIntersection() {
    Set<String> collection = new HashSet<String>();
    collection.add("3dfx");
    collection.add("Nvidia");
    collection.add("ATI");
    Set<String> collection2 = new HashSet<String>();
    collection2.add("3dfx");
    collection2.add("ATI");
    collection2.add("Trident");
    Set<String> expected = new HashSet<String>();
    expected.add("3dfx");
    expected.add("ATI");
    Set<String> data = CollectionUtil.intersection(collection, collection2);
    TestSetUtil.assertSetEquals(expected, data);
}
Example 3
Project: google-web-toolkit-svnmirror-master  File: TreeSetTest.java View source code
/**
   * Test method for 'java.util.Set.add(Object)'.
   * 
   * @see java.util.Set#add(Object)
   */
public void testAdd_entries3() {
    // verify that the method is not supported.
    if (isAddSupported) {
        // populate the set
        Set<E> set = createSet();
        set.add(getKeys()[0]);
        set.add(getKeys()[1]);
        set.add(getKeys()[2]);
        // test contents
        assertFalse(set.isEmpty());
        assertEquals(3, set.size());
        Collection<E> keys = set;
        // test contains all keys
        assertTrue(keys.contains(getKeys()[0]));
        assertTrue(keys.contains(getKeys()[1]));
        assertTrue(keys.contains(getKeys()[2]));
    }
}
Example 4
Project: expenditures-master  File: AuthorizeDislocationService.java View source code
@Atomic
public static Collection<PersonMissionAuthorization> authorizeDislocation(final Set<PersonMissionAuthorization> personMissionAuthorizations) {
    final Collection<PersonMissionAuthorization> notActive = new HashSet<>();
    for (final PersonMissionAuthorization personMissionAuthorization : personMissionAuthorizations) {
        final Mission mission = personMissionAuthorization.getAssociatedMission();
        final MissionProcess missionProcess = mission.getMissionProcess();
        final AuthoriseParticipantActivity activity = (AuthoriseParticipantActivity) missionProcess.getActivity(AuthoriseParticipantActivity.class);
        if (activity.isActive(missionProcess)) {
            final AuthoriseParticipantActivityInformation activityInformation = (AuthoriseParticipantActivityInformation) activity.getActivityInformation(missionProcess);
            activityInformation.setPersonMissionAuthorization(personMissionAuthorization);
            activity.execute(activityInformation);
        } else {
            notActive.add(personMissionAuthorization);
        }
    }
    return notActive;
}
Example 5
Project: molgenis-master  File: FileExtensionUtils.java View source code
public static String findExtensionFromPossibilities(String fileName, Set<String> fileExtensions) {
    String name = fileName.toLowerCase();
    List<String> possibleExtensions = new ArrayList<String>();
    for (String extention : fileExtensions) {
        if (name.endsWith('.' + extention)) {
            possibleExtensions.add(extention);
        }
    }
    String longestExtension = null;
    for (String possibleExtension : possibleExtensions) {
        if (null == longestExtension) {
            longestExtension = possibleExtension;
            continue;
        } else {
            if (longestExtension.length() < possibleExtension.length())
                longestExtension = possibleExtension;
        }
    }
    return longestExtension;
}
Example 6
Project: sonar-java-master  File: URLHashCodeAndEqualsCheck.java View source code
public void foo(URL url) throws Exception {
    // Noncompliant [[sc=5;ec=22]] {{Use the URI class instead.}}
    Map<URL, Integer> sites = new HashMap<>();
    // Noncompliant {{Use the URI class instead.}}
    Set<URL> otherSites = new HashSet<>();
    // Compliant
    URL homepage = new URL("http://sonarsource.com");
    // Noncompliant [[sc=5;ec=25]] {{Use the URI class instead.}}
    homepage.equals(url);
    // Noncompliant {{Use the URI class instead.}}
    homepage.hashCode();
    // Compliant
    homepage.getPath();
    // Compliant
    Map<URI, URL> uriToUrl = new HashMap<>();
    // Compliant
    Map uriToUrl2 = new Hashmap();
    // Compliant
    Map<> uriToUrl3 = new Hashmap<>();
}
Example 7
Project: tapestry-model-master  File: CollectionDescriptorTest.java View source code
@Test
public void testClone() {
    CollectionDescriptor bazzesDescriptor = new CollectionDescriptor(Foo.class, "bazzes", Set.class);
    bazzesDescriptor.setElementType(Baz.class);
    bazzesDescriptor.setOneToMany(true);
    bazzesDescriptor.setChildRelationship(true);
    bazzesDescriptor.setInverseProperty("inverse");
    CollectionDescriptor clonedDescriptor = (CollectionDescriptor) bazzesDescriptor.clone();
    assertTrue(clonedDescriptor.isChildRelationship());
    assertEquals("inverse", clonedDescriptor.getInverseProperty());
    assertTrue(clonedDescriptor.isOneToMany());
}
Example 8
Project: bennu-master  File: SchedulerTaskAnnotationProcessor.java View source code
@Override
public void onStartup(Set<Class<?>> classes, ServletContext ctx) throws ServletException {
    if (classes != null) {
        for (Class<?> type : classes) {
            final Task annon = type.getAnnotation(Task.class);
            if (annon != null) {
                SchedulerSystem.addTask(type.getName(), annon);
            }
        }
    }
}
Example 9
Project: sitebricks-master  File: ValidationConverter.java View source code
@Override
public List<String> to(Set<? extends ConstraintViolation<?>> source) {
    List<String> errors = Lists.newArrayList();
    if (source != null) {
        for (ConstraintViolation<?> cv : source) {
            errors.add(cv.getMessage());
        }
    }
    return errors;
}
Example 10
Project: sisu-guice-master  File: MoreTypesTest.java View source code
public void testParameterizedTypeToString() {
    TypeLiteral<Inner<String>> innerString = new TypeLiteral<Inner<String>>() {
    };
    assertEquals("com.google.inject.internal.MoreTypesTest$Inner<java.lang.String>", MoreTypes.typeToString(innerString.getType()));
    TypeLiteral<Set<Inner<Integer>>> mapInnerInteger = new TypeLiteral<Set<Inner<Integer>>>() {
    };
    assertEquals("java.util.Set<com.google.inject.internal.MoreTypesTest$Inner<java.lang.Integer>>", MoreTypes.typeToString(mapInnerInteger.getType()));
    TypeLiteral<Map<Inner<Long>, Set<Inner<Long>>>> mapInnerLongToSetInnerLong = new TypeLiteral<Map<Inner<Long>, Set<Inner<Long>>>>() {
    };
    assertEquals("java.util.Map<com.google.inject.internal.MoreTypesTest$Inner<java.lang.Long>, " + "java.util.Set<com.google.inject.internal.MoreTypesTest$Inner<java.lang.Long>>>", MoreTypes.typeToString(mapInnerLongToSetInnerLong.getType()));
}
Example 11
Project: org.openntf.domino-master  File: ASTAssignment.java View source code
/*
	 * (non-Javadoc)
	 * @see org.openntf.formula.ast.SimpleNode#analyzeThis(java.util.Set, java.util.Set, java.util.Set, java.util.Set)
	 */
@Override
protected void analyzeThis(final Set<String> readFields, final Set<String> modifiedFields, final Set<String> variables, final Set<String> functions) {
    switch(type) {
        case FIELD:
            modifiedFields.add(varName.toLowerCase());
            break;
        case VAR:
        case DEFAULT:
            variables.add(varName.toLowerCase());
            break;
        case ENV:
            break;
    }
}
Example 12
Project: LambdaDojo-master  File: S404StreamInsteadOfFor.java View source code
private void splitSentences() {
    List<String> sentences = Arrays.asList("Peter Piper picked", "a peck of pickled peppers.", "A peck of pickled peppers", "Peter Piper picked. ", "If Peter Piper picked", "a peck of pickled peppers,", "Where's the peck of pickled peppers", "Peter Piper picked? ");
    Set<String> words = new HashSet<>();
    for (String sentence : sentences) {
        String[] splitedSentence = sentence.split("[\\.,\\? ]");
        for (String word : splitedSentence) {
            words.add(word.toLowerCase());
        }
    }
    System.out.println(words);
}
Example 13
Project: dataverse-master  File: GroupUtil.java View source code
/**
     * @param authenticatedUser An non-null AuthenticatedUser.
     * @param groups The groups associated with an AuthenticatedUser.
     * @return A list of identifiers for the user including groups, single
     * quoted, and separated by commas. Null if a null AuthenticatedUser is
     * passed.
     */
public static String getAllIdentifiersForUser(AuthenticatedUser authenticatedUser, Set<Group> groups) {
    if (authenticatedUser == null) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("'").append(authenticatedUser.getIdentifier()).append("'");
    if (groups != null) {
        groups.stream().forEach(( group) -> {
            sb.append(", ").append("'").append(group.getIdentifier()).append("'");
        });
    }
    return sb.toString();
}
Example 14
Project: cloudtm-data-platform-master  File: CheckGaps.java View source code
public static void main(String[] args) {
    SortedSet<Integer> set = new TreeSet<Integer>();
    for (int i = 0; i < args.length; i++) {
        set.add(Integer.parseInt(args[i]));
    }
    int low = set.first(), high = set.last();
    System.out.println("input has " + set.size() + " numbers, low=" + low + ", high=" + high);
    Set<Integer> correct_set = new HashSet<Integer>();
    for (int i = low; i < high; i++) {
        correct_set.add(i);
    }
    correct_set.removeAll(set);
    System.out.println("missing seqnos: " + correct_set);
}
Example 15
Project: alien4cloud-master  File: ToscaPropertyConstraintDuplicateValidator.java View source code
@Override
public boolean isValid(List<PropertyConstraint> value, ConstraintValidatorContext context) {
    if (value == null) {
        return true;
    }
    Set<String> definedConstraints = Sets.newHashSet();
    boolean isValid = true;
    for (int i = 0; i < value.size(); i++) {
        PropertyConstraint constraint = value.get(i);
        if (!definedConstraints.add(constraint.getClass().getName())) {
            context.buildConstraintViolationWithTemplate("CONSTRAINTS.VALIDATION.DUPLICATED_CONSTRAINT").addBeanNode().inIterable().atIndex(i).addConstraintViolation();
            isValid = false;
        }
    }
    return isValid;
}
Example 16
Project: geotools-old-master  File: EAttributeValueIsID.java View source code
public static final Condition eq(final Set<Identifier> eIDs) {
    return new Condition() {

        @Override
        public boolean isSatisfied(Object value) {
            if (value instanceof Feature) {
                for (Identifier it : eIDs) {
                    if (it.matches(value))
                        return true;
                }
            } else if (value instanceof String) {
                for (Identifier it : eIDs) {
                    if (it.getID().equals(value))
                        return true;
                }
            }
            return false;
        }
    };
}
Example 17
Project: extFM-Tooling-master  File: MtextExpectedEnumerationTerminal.java View source code
public java.util.Set<String> getTokenNames() {
    // EnumerationTerminals are associated with multiple tokens, one for each literal
    // that was mapped to a string
    java.util.Set<String> tokenNames = new java.util.LinkedHashSet<String>();
    java.util.Map<String, String> mapping = enumerationTerminal.getLiteralMapping();
    for (String literalName : mapping.keySet()) {
        String text = mapping.get(literalName);
        if (text != null && !"".equals(text)) {
            tokenNames.add("'" + text + "'");
        }
    }
    return tokenNames;
}
Example 18
Project: ARTPart-master  File: Main.java View source code
public static void main(String[] args) throws Exception {
    // These charsets must be provided; anything else is optional.
    List<String> standardCharsets = Arrays.asList("US-ASCII", "ISO-8859-1", "UTF-8", "UTF-16BE", "UTF-16LE", "UTF-16");
    SortedMap<String, Charset> all = Charset.availableCharsets();
    Set<String> needed = new HashSet<String>(standardCharsets);
    for (Map.Entry<String, Charset> e : all.entrySet()) {
        String canonicalName = e.getKey();
        needed.remove(canonicalName);
    }
    System.out.println("Missing: " + needed);
}
Example 19
Project: parkandrideAPI-master  File: NotBlankElementSetValidator.java View source code
@Override
public boolean isValid(Set<? extends CharSequence> set, ConstraintValidatorContext context) {
    if (set != null) {
        for (CharSequence val : set) {
            if (val == null || val.toString().trim().length() == 0) {
                return false;
            }
        }
    }
    return true;
}
Example 20
Project: many-ql-master  File: MissingIdentifiersError.java View source code
private static String missingIdentifierString(List<Identifier> processed, Set<Identifier> all) {
    StringBuilder missing = new StringBuilder("-- Missing Identifiers --\n");
    all.stream().filter( identifier -> !processed.contains(identifier)).forEach( identifier -> missing.append("  > " + identifier + "\n"));
    return missing.toString();
}
Example 21
Project: mjprof-master  File: JPSUtil.java View source code
public static int lookupProcessId(String lookForMainClass) throws MonitorException, URISyntaxException {
    HostIdentifier hostId = new HostIdentifier("local://localhost");
    MonitoredHost monitoredHost = MonitoredHost.getMonitoredHost(hostId);
    // get the set active JVMs on the specified host.
    Set jvms = monitoredHost.activeVms();
    for (Object jvm : jvms) {
        int lvmid = (Integer) jvm;
        MonitoredVm vm = null;
        String vmidString = "//" + lvmid + "?mode=r";
        VmIdentifier id = new VmIdentifier(vmidString);
        vm = monitoredHost.getMonitoredVm(id, 0);
        String mainClass = MonitoredVmUtil.mainClass(vm, false);
        if (mainClass.equals(lookForMainClass))
            return lvmid;
    }
    return -1;
}
Example 22
Project: cms-ce-master  File: TermsStatsFacetResultSetXmlCreator.java View source code
public Element create(TermsStatsFacetResultSet termsStatsFacetResultSet) {
    final Element rangeFacetRootElement = createFacetRootElement("terms-stats", termsStatsFacetResultSet);
    final Set<TermsStatsFacetResultEntry> resultEntries = termsStatsFacetResultSet.getResults();
    for (TermsStatsFacetResultEntry result : resultEntries) {
        Element resultEl = new Element("term");
        addAttributeIfNotNull(resultEl, "sum", result.getTotal());
        addAttributeIfNotNull(resultEl, "total-count", result.getTotalCount());
        addAttributeIfNotNull(resultEl, "hits", result.getCount());
        addAttributeIfNotNull(resultEl, "min", result.getMin());
        addAttributeIfNotNull(resultEl, "mean", result.getMean());
        addAttributeIfNotNull(resultEl, "max", result.getMax());
        resultEl.addContent(result.getTerm());
        rangeFacetRootElement.addContent(resultEl);
    }
    return rangeFacetRootElement;
}
Example 23
Project: quickml-master  File: AttributeCombiningEnricherTest.java View source code
@Test
public void simpleTest() {
    Set<List<String>> attributesToCombine = Sets.newHashSet();
    attributesToCombine.add(Lists.newArrayList("k1", "k2"));
    AttributeCombiningEnricher attributeCombiningEnricher = new AttributeCombiningEnricher(attributesToCombine);
    AttributesMap attributes = AttributesMap.newHashMap();
    attributes.put("k1", "a");
    attributes.put("k2", "b");
    final AttributesMap enhancedAttributes = attributeCombiningEnricher.apply(attributes);
    Assert.assertEquals(enhancedAttributes.size(), 3);
    Assert.assertEquals(enhancedAttributes.get("k1-k2"), "ab");
}
Example 24
Project: ManagedRuntimeInitiative-master  File: JavaCompiler.java View source code
/** Main method: compile a list of files, return all compiled classes
     *  @param filenames     The names of all files to be compiled.
     */
public List<ClassSymbol> compile(List<String> filenames, Map<String, String> origOptions, ClassLoader aptCL, AnnotationProcessorFactory providedFactory, java.util.Set<Class<? extends AnnotationProcessorFactory>> productiveFactories, java.util.Set<java.io.File> aggregateGenFiles) throws Throwable {
    // it has been used before.
    assert !hasBeenUsed : "attempt to reuse JavaCompiler";
    hasBeenUsed = true;
    this.aggregateGenFiles = aggregateGenFiles;
    long msec = System.currentTimeMillis();
    ListBuffer<ClassSymbol> classes = new ListBuffer<ClassSymbol>();
    try {
        //parse all files
        ListBuffer<JCCompilationUnit> trees = new ListBuffer<JCCompilationUnit>();
        for (List<String> l = filenames; l.nonEmpty(); l = l.tail) {
            if (classesAsDecls) {
                if (!l.head.endsWith(".java")) {
                    // process as class file
                    ClassSymbol cs = reader.enterClass(names.fromString(l.head));
                    try {
                        cs.complete();
                    } catch (Symbol.CompletionFailure cf) {
                        bark.aptError("CantFindClass", l);
                        continue;
                    }
                    // add to list of classes
                    classes.append(cs);
                    continue;
                }
            }
            trees.append(parse(l.head));
        }
        //enter symbols for all files
        List<JCCompilationUnit> roots = trees.toList();
        if (errorCount() == 0) {
            boolean prev = bark.setDiagnosticsIgnored(true);
            try {
                enter.main(roots);
            } finally {
                bark.setDiagnosticsIgnored(prev);
            }
        }
        if (errorCount() == 0) {
            apt.main(roots, classes, origOptions, aptCL, providedFactory, productiveFactories);
            genSourceFileNames.addAll(apt.getSourceFileNames());
            genClassFileNames.addAll(apt.getClassFileNames());
        }
    } catch (Abort ex) {
    }
    if (verbose)
        printVerbose("total", Long.toString(System.currentTimeMillis() - msec));
    chk.reportDeferredDiagnostics();
    printCount("error", errorCount());
    printCount("warn", warningCount());
    return classes.toList();
}
Example 25
Project: EclipseTrader-master  File: BaseWireFeedGenerator.java View source code
/**
     * Purging unused declarations is less optimal, performance-wise, than never adding them in the first place.  So, we
     * should still ask the ROME guys to fix their code (not adding dozens of unnecessary module declarations). Having
     * said that: purging them here, before XML generation, is more efficient than parsing and re-molding the XML after
     * ROME generates it.
     * <p/>
     * Note that the calling app could still add declarations/modules to the Feed tree after this.  Which is fine.  But
     * those modules are then responsible for crawling to the root of the tree, at generate() time, to make sure their
     * namespace declarations are present.
     */
protected static void purgeUnusedNamespaceDeclarations(Element root) {
    java.util.Set usedPrefixes = new java.util.HashSet();
    collectUsedPrefixes(root, usedPrefixes);
    List list = root.getAdditionalNamespaces();
    List additionalNamespaces = new java.util.ArrayList();
    // the duplication will prevent a ConcurrentModificationException below
    additionalNamespaces.addAll(list);
    for (int i = 0; i < additionalNamespaces.size(); i++) {
        Namespace ns = (Namespace) additionalNamespaces.get(i);
        String prefix = ns.getPrefix();
        if (prefix != null && prefix.length() > 0 && !usedPrefixes.contains(prefix)) {
            root.removeNamespaceDeclaration(ns);
        }
    }
}