Java Code Examples for java.util.Set.add()

The following are Jave code examples for showing how to use add() of the java.util.Set class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: monarch   File: MessageDependencyMonitor.java   View Source Code Vote up 6 votes
public Set<Dependency<Thread, Serializable>> getBlockedThreads(Thread[] allThreads) {

    InternalDistributedSystem system = InternalDistributedSystem.getAnyInstance();
    if (system == null) {
      return Collections.emptySet();
    }
    InternalDistributedMember myId = system.getDistributedMember();

    Set<Dependency<Thread, Serializable>> blockedThreads =
        new HashSet<Dependency<Thread, Serializable>>();
    for (Thread thread : allThreads) {
      ReplyProcessor21 processor = waitingProcessors.get(thread);
      if (processor != null && processor.getProcessorId() > 0) {
        blockedThreads.add(new Dependency<Thread, Serializable>(thread,
            new MessageKey(myId, processor.getProcessorId())));
      }
    }
    return blockedThreads;
  }
 
Example 2
Project: incubator-netbeans   File: BridgingInputOutputProvider.java   View Source Code Vote up 6 votes
/**
 * Translate set of {@link ShowOperation}s to set of
 * {@link IOSelect.AdditionalOperation}s.
 */
private Set<IOSelect.AdditionalOperation> showOperationsToIoSelect(
        Set<ShowOperation> operations) {
    Set<IOSelect.AdditionalOperation> res
            = EnumSet.noneOf(IOSelect.AdditionalOperation.class);
    for (ShowOperation so : operations) {
        switch (so) {
            case OPEN:
                res.add(IOSelect.AdditionalOperation.OPEN);
                break;
            case MAKE_VISIBLE:
                res.add(IOSelect.AdditionalOperation.REQUEST_VISIBLE);
                break;
            case ACTIVATE:
                res.add(IOSelect.AdditionalOperation.REQUEST_ACTIVE);
                break;
        }
    }
    return res;
}
 
Example 3
Project: incubator-netbeans   File: CheckTreeNode.java   View Source Code Vote up 6 votes
protected Collection setPartiallyChecked() {
    Set changedNodes = new HashSet();
    changedNodes.add(this);

    // Check if change is needed
    if (checkState == STATE_PARTIALLY_CHECKED) {
        return changedNodes;
    }

    // Update checkState of this node
    checkState = STATE_PARTIALLY_CHECKED;

    // Update checkState of parent
    TreeNode parent = getParent();

    if ((parent != null) && parent instanceof CheckTreeNode) {
        changedNodes.addAll(((CheckTreeNode) parent).setPartiallyChecked());
    }

    // Return Collection of leaf nodes changed by this operation
    return changedNodes;
}
 
Example 4
Project: ECFileCache   File: ECodec.java   View Source Code Vote up 6 votes
private int checkErasuresAndGetMin(int[] erasures) throws ECFileCacheException {
  if (ArrayUtils.isEmpty(erasures)) {
    throw new ECFileCacheException("empty erasures array");
  }

  if (erasures.length > CODING_BLOCK_NUM) {
    String verbose = String.format("can not decode data with [%d] blocks erased.", erasures.length);
    LOGGER.warn(verbose);
    throw new ECFileCacheException(verbose);
  }

  int min = Integer.MAX_VALUE;
  Set<Integer> set = new HashSet<Integer>();
  for (final int erasure : erasures) {
    if (erasure < -1 || erasure >= EC_BLOCK_NUM || set.contains(erasure)) {
      throw new ECFileCacheException("invalid erasures array");
    }
    set.add(erasure);

    if (erasure < min) {
      min = erasure;
    }
  }

  return min;
}
 
Example 5
Project: Equella   File: SuspensionWrapper.java   View Source Code Vote up 6 votes
@Override
public boolean save(SuspendedUserWrapperSettings xml)
{
	Set<String> right = new HashSet<String>();
	for( UserBean user : fsb.getRight() )
	{
		right.add(user.getUniqueID());
	}

	boolean saved = false;
	try
	{
		xml.setSuspendedUsers(right);
		saved = true;
	}
	catch( Exception e )
	{
		displayError(CurrentLocale.get("com.tle.admin.usermanagement.suspensionwrapper.errorsaving"), e); //$NON-NLS-1$
	}

	return saved;
}
 
Example 6
Project: lams   File: UniversalLoginModule.java   View Source Code Vote up 6 votes
/**
    * Find or create a Group with the given name. Subclasses should use this method to locate the 'Roles' group or
    * create additional types of groups.
    *
    * @return A named Group from the principals set.
    */
   private Group createGroup(String name, Set<Principal> principals) {
Group roles = null;
for (Principal principal : principals) {
    if (principal instanceof Group) {
	Group grp = (Group) principal;
	if (grp.getName().equals(name)) {
	    roles = grp;
	    break;
	}
    }
}

// If we did not find a group create one
if (roles == null) {
    roles = new SimpleGroup(name);
    principals.add(roles);
}
return roles;
   }
 
Example 7
Project: monarch   File: StructMemberAccessJUnitTest.java   View Source Code Vote up 6 votes
public void _BUGtestSubClassQuery() throws Exception {
  Set add1 = new HashSet();
  Set add2 = new HashSet();
  add1.add(new Address("Hp3 9yf", "Apsley"));
  add1.add(new Address("Hp4 9yf", "Apsleyss"));
  add2.add(new Address("Hp3 8DZ", "Hemel"));
  add2.add(new Address("Hp4 8DZ", "Hemel"));
  Region region = CacheUtils.createRegion("employees", Employee.class);
  region.put("1", new Manager("aaa", 27, 270, "QA", 1800, add1, 2701));
  region.put("2", new Manager("bbb", 28, 280, "QA", 1900, add2, 2801));
  String queries[] = {"SELECT DISTINCT e.manager_id FROM /employees e"};
  for (int i = 0; i < queries.length; i++) {
    Query q = CacheUtils.getQueryService().newQuery(queries[i]);
    Object r = q.execute();
    String className =
        (((SelectResults) r).getCollectionType()).getElementType().getSimpleClassName();
    if (!className.equals("Employee")) {
      fail(
          "StructMemberAccessTest::testSubClassQuery:failed .Expected class name Employee. Actualy obtained="
              + className);
    }
  }
}
 
Example 8
Project: Open-DM   File: ManagedJobsSchema.java   View Source Code Vote up 6 votes
private Set<String> getJobsUsingProfile(Connection conn, String profileName)
        throws SQLException {
    Set<String> jobNames = new HashSet<String>();

    if (profileName == null) {
        return jobNames;
    }

    Statement stmt = conn.createStatement();
    ResultSet rs = DBUtils.executeQuery(stmt, GET_ALL_JOBS_AND_PROFILES_SQL);
    while (rs.next()) {
        String sourceProfileName = rs
                .getString(ManagedJobTableColumn.SOURCE_PROFILE_NAME.toString());
        if (sourceProfileName != null && sourceProfileName.equals(profileName)) {
            jobNames.add(rs.getString(ManagedJobTableColumn.JOB_NAME.toString()));
            continue;
        }
        String targetProfileName = rs
                .getString(CopyJobTableColumn.TARGET_PROFILE_NAME.toString());
        if (targetProfileName != null && targetProfileName.equals(profileName)) {
            jobNames.add(rs.getString(ManagedJobTableColumn.JOB_NAME.toString()));
        }
    }
    return jobNames;
}
 
Example 9
Project: elasticsearch_my   File: RestTermVectorsAction.java   View Source Code Vote up 6 votes
public static void addFieldStringsFromParameter(TermVectorsRequest termVectorsRequest, String fields) {
    Set<String> selectedFields = termVectorsRequest.selectedFields();
    if (fields != null) {
        String[] paramFieldStrings = Strings.commaDelimitedListToStringArray(fields);
        for (String field : paramFieldStrings) {
            if (selectedFields == null) {
                selectedFields = new HashSet<>();
            }
            if (!selectedFields.contains(field)) {
                field = field.replaceAll("\\s", "");
                selectedFields.add(field);
            }
        }
    }
    if (selectedFields != null) {
        termVectorsRequest.selectedFields(selectedFields.toArray(new String[selectedFields.size()]));
    }
}
 
Example 10
Project: SECP   File: AppCreateDTOTest.java   View Source Code Vote up 5 votes
@Test
public void testPermissions() {
    AppCreateDTO appCreateDTO = new AppCreateDTO();

    Set<String> permissions = new HashSet<>();
    permissions.add("TOP_SECRET");

    appCreateDTO.setPermissions(permissions);
    assertEquals("permissions are not equal",permissions, appCreateDTO.getPermissions());
}
 
Example 11
Project: jmt   File: BDMapImpl.java   View Source Code Vote up 5 votes
private Set<Object> getSetFromArray(Object[] array) {
	Set<Object> s = new TreeSet<Object>();
	for (Object element : array) {
		s.add(element);
	}
	return s;
}
 
Example 12
Project: alar-trie   File: Trie.java   View Source Code Vote up 5 votes
private Set<String> findSubwordsFrom(Letter root, Set<String> subwords, String prevChars) {
	for(Letter letter : root.getNextChars()) {
		String tmpSubword = prevChars;
		if(letter != null) {
			tmpSubword += letter.getValue();
			if(letter.isLast()) {
				subwords.add(tmpSubword);
			}
			findSubwordsFrom(letter, subwords, tmpSubword);
		}
	}
	return subwords;
}
 
Example 13
Project: dremio-oss   File: BatchSchema.java   View Source Code Vote up 5 votes
public void materializeVectors(List<SchemaPath> columns, OutputMutator mutator) {
  Preconditions.checkNotNull(columns, "A scan's column selection cannot be null.");
  Set<String> selectedColumns = new HashSet<>();
  for (SchemaPath sp : columns) {
    selectedColumns.add(sp.getRootSegment().getNameSegment().getPath());
  }
  for (Field field : this) {
    if (columns != null && !selectedColumns.contains("*") && !selectedColumns.contains(field.getName())) {
      continue;
    }
    mutator.addField(field, CompleteType.fromField(field).getValueVectorClass());
  }
}
 
Example 14
Project: aws-sdk-java-v2   File: DoubleSetUnmarshaller.java   View Source Code Vote up 5 votes
@Override
public Object unmarshall(AttributeValue value) {
    Set<Double> result = new HashSet<Double>();
    for (String s : value.ns()) {
        result.add(Double.valueOf(s));
    }
    return result;
}
 
Example 15
Project: util4j   File: ScriptClassProvider.java   View Source Code Vote up 5 votes
/**
 * 找出脚本类
 * @param clazzs
 * @return
 * @throws InstantiationException
 * @throws IllegalAccessException
 */
@SuppressWarnings("unchecked")
private Set<Class<? extends T>> findScriptClass(Set<Class<?>> clazzs)
		throws InstantiationException, IllegalAccessException {
	Set<Class<? extends T>> scriptClazzs = new HashSet<Class<? extends T>>();
	for (Class<?> clazz : clazzs) {
		if (IScript.class.isAssignableFrom(clazz)) {
			Class<T> scriptClazz = (Class<T>) clazz;
			scriptClazzs.add(scriptClazz);
		}
	}
	return scriptClazzs;
}
 
Example 16
Project: ForeverLibrary   File: CookieJarImpl.java   View Source Code Vote up 5 votes
public void addCookies(List<Cookie> cookies) {
    for (Cookie cookie : cookies) {
        String domain = cookie.domain();
        Set<Cookie> domainCookies = userCookies.get(domain);
        if (domainCookies == null) {
            domainCookies = new HashSet<>();
            userCookies.put(domain, domainCookies);
        }
        domainCookies.add(cookie);
    }
}
 
Example 17
Project: rskj   File: RepositoryImpl.java   View Source Code Vote up 5 votes
@Override
public synchronized Set<ByteArrayWrapper> getAccountsKeys() {
    Set<ByteArrayWrapper> result = new HashSet<>();

    for (ByteArrayWrapper key : detailsDataStore.keys()) {
        if (this.isExist(key.getData())) {
            result.add(key);
        }
    }

    return result;
}
 
Example 18
Project: sats-core   File: LSVMGrid.java   View Source Code Vote up 5 votes
private Set<LSVMLicense> expand(Set<LSVMLicense> proximity, LSVMLicense license) {

        Set<LSVMLicense> newLicenses = new HashSet<>();
        // Add top neighbor if not in first row
        if (license.getRowPosition() > 0) {
            // Only add if not added yet
            if (!proximity.contains(getLicense(license.getRowPosition() - 1, license.getColumnPosition()))) {
                newLicenses.add(getLicense(license.getRowPosition() - 1, license.getColumnPosition()));
            }
        }

        // Add right neighbor if not in last column
        if (license.getColumnPosition() < getNumberOfColumns() - 1) {
            // Only add if not added yet
            if (!proximity.contains(getLicense(license.getRowPosition(), license.getColumnPosition() + 1))) {
                newLicenses.add(getLicense(license.getRowPosition(), license.getColumnPosition() + 1));
            }
        }

        // Add lower neighbor if not in last row
        if (license.getRowPosition() < getNumberOfRows() - 1) {
            // Only add if not added yet
            if (!proximity.contains(getLicense(license.getRowPosition() + 1, license.getColumnPosition()))) {
                newLicenses.add(getLicense(license.getRowPosition() + 1, license.getColumnPosition()));
            }
        }

        // Add left neighbor if not in first column
        if (license.getColumnPosition() > 0) {
            // Only add if not added yet
            if (!proximity.contains(getLicense(license.getRowPosition(), license.getColumnPosition() - 1))) {
                newLicenses.add(getLicense(license.getRowPosition(), license.getColumnPosition() - 1));
            }
        }

        return newLicenses;
    }
 
Example 19
Project: Reer   File: UnresolvableConfigurationResult.java   View Source Code Vote up 4 votes
@Override
public Set<? extends RenderableDependency> getChildren() {
    final DependencySet dependencies = configuration.getDependencies();
    if (dependencies.isEmpty()) {
        return Collections.emptySet();
    }
    Set<RenderableDependency> children = Sets.newLinkedHashSet();
    for (final Dependency dependency : dependencies) {
        children.add(new RenderableDependency() {
            @Override
            public Object getId() {
                return dependency;
            }

            @Override
            public String getName() {
                String label;
                if (dependency instanceof ProjectDependency) {
                    label = "project " + dependency.getName();
                } else {
                    label = Joiner.on(":").join(Iterables.filter(Arrays.asList(dependency.getGroup(), dependency.getName(), dependency.getVersion()), Predicates.<String>notNull()));
                }
                return label;
            }

            @Override
            public String getDescription() {
                return null;
            }

            @Override
            public ResolutionState getResolutionState() {
                return ResolutionState.UNRESOLVED;
            }

            @Override
            public Set<? extends RenderableDependency> getChildren() {
                return Collections.emptySet();
            }
        });
    }
    return children;
}
 
Example 20
Project: GitHub   File: ShowcaseApplication.java   View Source Code Vote up 4 votes
@Override
public void onCreate() {
  super.onCreate();
  FLog.setMinimumLoggingLevel(FLog.VERBOSE);
  Set<RequestListener> listeners = new HashSet<>();
  listeners.add(new RequestLoggingListener());

  OkHttpClient okHttpClient = new OkHttpClient.Builder()
      .addNetworkInterceptor(new StethoInterceptor())
      .build();

  ImagePipelineConfig imagePipelineConfig =
      OkHttpImagePipelineConfigFactory.newBuilder(this, okHttpClient)
          .setRequestListeners(listeners)
          .setProgressiveJpegConfig(new SimpleProgressiveJpegConfig())
          .setImageDecoderConfig(CustomImageFormatConfigurator.createImageDecoderConfig(this))
          .experiment()
          .setMediaVariationsIndexEnabled(
              new Supplier<Boolean>() {
                @Override
                public Boolean get() {
                  return true;
                }
              })
          .experiment()
          .setBitmapPrepareToDraw(true, 0, Integer.MAX_VALUE, true)
          .experiment()
          .setSmartResizingEnabled(Suppliers.BOOLEAN_TRUE)
          .build();

  ImagePipelineConfig.getDefaultImageRequestConfig().setProgressiveRenderingEnabled(true);

  DraweeConfig.Builder draweeConfigBuilder = DraweeConfig.newBuilder();
  CustomImageFormatConfigurator.addCustomDrawableFactories(this, draweeConfigBuilder);

  draweeConfigBuilder.setDebugOverlayEnabledSupplier(
      DebugOverlaySupplierSingleton.getInstance(getApplicationContext()));

  Fresco.initialize(this, imagePipelineConfig, draweeConfigBuilder.build());

  final Context context = this;
  Stetho.initialize(
      Stetho.newInitializerBuilder(context)
          .enableDumpapp(
              new DumperPluginsProvider() {
                @Override
                public Iterable<DumperPlugin> get() {
                  return new Stetho.DefaultDumperPluginsBuilder(context)
                      .provide(new FrescoStethoPlugin())
                      .finish();
                }
              })
          .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(context))
          .build());
}