Set add - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Set add method.

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
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
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
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
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
This code example shows how to use the following methods:add
  public void setInitialised() { 
    this.initialised = true;
  } 
 
  public void add(T elem) {
    ids.add(elem);
  } 
 
  public void remove(T elem) {
    ids.remove(elem);
  } 
 
  public void merge(ChoosableSet<T> toMerge) {
    ids.addAll(toMerge.ids);
  } 
 
  public boolean isEmpty() { 
    return ids.isEmpty();
  } 
 
8
CodeRank
This code example shows how to use the following methods:add
    @Test 
    public void smembers() { 
        jedis.sadd("foo", "a"); 
        jedis.sadd("foo", "b"); 
 
        Set<String> expected = new HashSet<String>();
        expected.add("a");
        expected.add("b");
 
        Set<String> members = jedis.smembers("foo");
 
        assertEquals(expected, members);
 
        // Binary 
        jedis.sadd(bfoo, ba);
        jedis.sadd(bfoo, bb);
 
        Set<byte[]> bexpected = new HashSet<byte[]>();
        bexpected.add(bb);
        bexpected.add(ba);
8
CodeRank
This code example shows how to use the following methods:add
        jedis.zadd("foo", 1d, "a"); 
        jedis.zadd("foo", 2d, "b"); 
 
        long status = jedis.zrem("foo", "a");
 
        Set<String> expected = new LinkedHashSet<String>();
        expected.add("b");
 
        assertEquals(1, status);
        assertEquals(expected, jedis.zrange("foo", 0, 100));
 
        status = jedis.zrem("foo", "bar");
 
        assertEquals(0, status);
 
        // Binary 
        jedis.zadd(bfoo, 1d, ba);
        jedis.zadd(bfoo, 2d, bb);
 
        long bstatus = jedis.zrem(bfoo, ba);
8
CodeRank
This code example shows how to use the following methods:add
     */ 
    @Test 
    public void testCreateSection() { 
        Configuration config = getConfig();
 
        Set<String> set = new HashSet<String>();
        set.add("this");
        set.add("this.test.sub");
        set.add("this.test");
        set.add("this.test.other");
 
        config.createSection("this.test.sub");
        config.createSection("this.test.other");
 
        assertEquals(set, config.getKeys(true));
    } 
 
    /** 
     * Test of getDefaults method, of class Configuration. 
     */ 
8
CodeRank
This code example shows how to use the following methods:add
     
    private static final Set<String> stringSet;
     
    static { 
    	stringSet = new HashSet<String>();
    	stringSet.add( "string1" );
    	stringSet.add( "string2" );
    	stringSet.add( "string3" );
    } 
     
    @Before 
    public void setUp() { 
        content = new HashMap<String, Map<String, Object>>();
 
        sharedPreferences = new TestSharedPreferences(content, FILENAME, 3);
        editor = sharedPreferences.edit();
        editor.putBoolean("boolean", true);
        editor.putFloat("float", 1.1f);
        editor.putInt("int", 2);
        editor.putLong("long", 3l);
8
CodeRank

Related Set add Questions & Answers:

add Method Overview
Adds the specified element to this set if it is not already present (optional operation).
See Code Examples for other Java 8 Set Methods: