Java 8 Set - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Set class.

This code example shows how to use the following methods:add
	bhash.put(bbar, bcar);
	bhash.put(bcar, bbar);
	jedis.hmset(bfoo, bhash);
 
	Set<byte[]> bkeys = jedis.hkeys(bfoo);
	Set<byte[]> bexpected = new LinkedHashSet<byte[]>();
	bexpected.add(bbar);
	bexpected.add(bcar);
	assertEquals(bexpected, bkeys);
    } 
 
    @Test 
    public void hvals() { 
	Map<String, String> hash = new LinkedHashMap<String, String>();
	hash.put("bar", "car");
	hash.put("car", "bar");
	jedis.hmset("foo", hash);
 
	List<String> vals = jedis.hvals("foo");
	assertEquals(2, vals.size());
9
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add
    static final String UNEXPECTED_FAILURES_TABLE = "unexpectedFailures";
    static final String EXPECTED_PASSES_TABLE = "expextedPasses";
    static final String UNEXPECTED_PASSES_TABLE = "unexpextedPasses";
    private static final Set<String> TABLES_NAMES = new HashSet<String>();
    { 
        TABLES_NAMES.add(EXPECTED_FAILURES_TABLE);
        TABLES_NAMES.add(EXPECTED_PASSES_TABLE);
        TABLES_NAMES.add(UNEXPECTED_FAILURES_TABLE);
        TABLES_NAMES.add(UNEXPECTED_PASSES_TABLE);
    } 
 
    private static final void createTables(SQLiteDatabase db) {
        String cmd;
        for (String tableName : TABLES_NAMES) {
            cmd = "create table " + tableName + " ("
                    + KEY_ID + " integer primary key autoincrement, "
                    + KEY_PATH + " text not null, "
                    + KEY_BYTES + " blob not null);";
            db.execSQL(cmd);
        } 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isEmpty, removeAll
            String name2, SortedSet<String> set2) {
        Set<String> onlyInSet1 = new TreeSet<String>(set1);
 
        onlyInSet1.removeAll(set2);
 
        Set<String> onlyInSet2 = new TreeSet<String>(set2);
        onlyInSet2.removeAll(set1);
 
        if (!onlyInSet1.isEmpty() || !onlyInSet2.isEmpty()) {
            fail(String.format("in %s only: %s\nin %s only: %s", name1, onlyInSet1, name2, onlyInSet2));
        } 
 
        assertEquals(set2, set1);
    } 
 
    protected SortedSet<String> findAllPropertyNames(Class<?> clazz) throws Exception {
        SortedSet<String> names = new TreeSet<String>();
        for (PropertyDescriptor propDesc : getBeanInfo(clazz).getPropertyDescriptors()) {
            if (propDesc == null
                    || propDesc.getWriteMethod() == null) {
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add
 
    Object snapshotValue = snapshot.get(key);
    if (snapshotValue == null) {
      final OIdentifiable storedValue = indexEngine.get(key);
 
      final Set<OIdentifiable> values = new LinkedHashSet<OIdentifiable>();
 
      if (storedValue != null)
        values.add(storedValue.getIdentity());
 
      values.add(value.getIdentity());
 
      snapshot.put(key, values);
    } else if (snapshotValue instanceof Set) {
      final Set<OIdentifiable> values = (Set<OIdentifiable>) snapshotValue;
 
      values.add(value.getIdentity());
    } else { 
      final Set<OIdentifiable> values = new LinkedHashSet<OIdentifiable>();
 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add
  public static final Pattern SCALAR_PATTERN = Pattern.compile("^\\d*$");
  public static final Pattern FRACTIONAL_SCALAR_PATTERN = Pattern.compile("^\\d\\.\\d*$");
  public static Set<String> TIMES = new HashSet<String>();
 
  static { 
    Scalar.TIMES.add("am");
    Scalar.TIMES.add("pm");
    Scalar.TIMES.add("morning");
    Scalar.TIMES.add("afternoon");
    Scalar.TIMES.add("evening");
    Scalar.TIMES.add("night");
  } 
 
  public Scalar(Number type) {
    super(type);
  } 
 
  public static List<Token> scan(List<Token> tokens, Options options) {
    for (int i = 0; i < tokens.size(); i++) {
      Token token = tokens.get(i);
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isEmpty, iterator
  public Iterator<T> iterator() {
    return ids.iterator();
  } 
 
  public synchronized T choose() { 
    if (!ids.isEmpty()) {
      if (iter == null || !iter.hasNext()) {
        iter = ids.iterator();
      } 
      try { 
        return iter.next();
      } catch (NoSuchElementException e) {
        return null; 
      } 
    } else { 
      return null; 
    } 
  } 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:isEmpty, size
    @Override 
    protected void recognizeArguments(CommandContext ctx) throws CommandFormatException {
 
        final ParsedCommandLine args = ctx.getParsedCommandLine();
        final Set<String> propertyNames = args.getPropertyNames();
        if(!propertyNames.isEmpty()) {
            final Collection<String> names;
            if(helpArg.isPresent(args)) {
                if(propertyNames.size() == 1) {
                    return; 
                } 
                names = new ArrayList<String>(propertyNames);
                names.remove(helpArg.getFullName());
                names.remove(helpArg.getShortName());
            } else { 
                names = propertyNames;
            } 
            throw new CommandFormatException("Unrecognized argument names: " + names);
        } 
    } 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add
                metaData.setRoleName(getElementText(reader, propertyReplacer));
            else if (localName.equals(Element.PRINCIPAL_NAME.getLocalName())) {
                Set<String> principalNames = metaData.getPrincipals();
                if (principalNames == null) {
                    principalNames = new HashSet<String>();
                    metaData.setPrincipals(principalNames);
                } 
                principalNames.add(getElementText(reader, propertyReplacer));
            } 
            else 
                throw unexpectedElement(reader);
        } else { 
            super.processElement(metaData, reader, propertyReplacer);
        } 
    } 
 
} 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:contains, size
        assertFalse(handler.isRequestComplete());
 
        assertEquals("read-resource", handler.getOperationName());
 
        Set<String> argNames = handler.getPropertyNames();
        assertEquals(2, argNames.size());
        assertTrue(argNames.contains("recursive"));
        assertEquals("true", handler.getPropertyValue("recursive"));
        assertTrue(argNames.contains("other"));
    } 
 
    @Test 
    public void testNameValueSeparatorNameAndValueSeparator() throws Exception { 
        DefaultCallbackHandler handler = new DefaultCallbackHandler();
 
        parseOperation(":read-resource(recursive=true,other=", handler);
 
        assertFalse(handler.hasAddress());
        assertTrue(handler.hasOperationName());
        assertTrue(handler.hasProperties());
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:add, contains, remove
      return super.getResult(); 
    } 
  } 
 
  private static void addItemToResult(Object o, Set<Object> accepted, Set<Object> rejected) {
    if (!accepted.contains(o) && !rejected.contains(o)) {
      accepted.add(o);
    } else { 
      accepted.remove(o);
      rejected.add(o);
    } 
  } 
 
  private static void addItemsToResult(Collection<Object> co, Set<Object> accepted, Set<Object> rejected) {
    for (Object o : co) {
      addItemToResult(o, accepted, rejected);
    } 
  } 
 
  public String getSyntax() {
8
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Java 8 Set Questions & Answers:

See Code Examples for Java 8 Set Methods: