Java Code Examples for java.util.HashSet#clone()

The following examples show how to use java.util.HashSet#clone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetFactHandlesCommandTest.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
private void verifyThatCollectionContainsTheseFactHandle(HashSet<String> factSet, Object collection) { 
    factSet = (HashSet<String>) factSet.clone();
    if( collection instanceof Collection<?> ) { 
        Collection<FactHandle> factHandles = (Collection<FactHandle>) collection;
        assertTrue(! factHandles.isEmpty());
        assertTrue(factHandles.size() == factSet.size(), factSet.size() + "inserted but only " + factHandles.size() + " facts retrieved");
        Object [] internalFactHandles = factHandles.toArray();
        for( int i = 0; i < internalFactHandles.length; ++i ) { 
            Object factObject = ((InternalFactHandle) internalFactHandles[i]).getObject();
            assertTrue(factSet.contains(factObject));
            factSet.remove(factObject);
        }
        assertTrue( factSet.isEmpty(), "Additional facts found that weren't inserted.");
    }
    else { 
        fail("result of command was NOT a collection of FactHandles"); 
    }
}
 
Example 2
Source File: AFTSDefaultTextQueryIT.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void changeCrossLocaleEnabledFields() throws NoSuchFieldException, IllegalAccessException {
    Field crossLocalePropertiesField = AlfrescoSolrDataModel
            .getInstance()
            .getClass()
            .getDeclaredField("crossLocaleSearchProperties");

    crossLocalePropertiesField.setAccessible(true);

    Field crossLocaleTypesField = AlfrescoSolrDataModel
            .getInstance()
            .getClass()
            .getDeclaredField("crossLocaleSearchDataTypes");

    crossLocaleTypesField.setAccessible(true);

    HashSet<QName> crossLocaleProperties = (HashSet<QName>) crossLocalePropertiesField.get(AlfrescoSolrDataModel.getInstance());
    HashSet<QName> crossLocaleTypes = (HashSet<QName>) crossLocaleTypesField.get(AlfrescoSolrDataModel.getInstance());

    oldCrossLocaleTypes = (HashSet<QName>) crossLocaleTypes.clone();
    oldCrossLocaleProperties = (HashSet<QName>) crossLocaleProperties.clone();

    crossLocaleTypes.clear();
    crossLocaleProperties.clear();
    crossLocaleProperties.add(PROP_TITLE);
}
 
Example 3
Source File: TestRetryCacheWithHA.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void listCachePools(
    HashSet<String> poolNames, int active) throws Exception {
  HashSet<String> tmpNames = (HashSet<String>)poolNames.clone();
  RemoteIterator<CachePoolEntry> pools = dfs.listCachePools();
  int poolCount = poolNames.size();
  for (int i=0; i<poolCount; i++) {
    CachePoolEntry pool = pools.next();
    String pollName = pool.getInfo().getPoolName();
    assertTrue("The pool name should be expected", tmpNames.remove(pollName));
    if (i % 2 == 0) {
      int standby = active;
      active = (standby == 0) ? 1 : 0;
      cluster.transitionToStandby(standby);
      cluster.transitionToActive(active);
      cluster.waitActive(active);
    }
  }
  assertTrue("All pools must be found", tmpNames.isEmpty());
}
 
Example 4
Source File: TestRetryCacheWithHA.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void listCacheDirectives(
    HashSet<String> poolNames, int active) throws Exception {
  HashSet<String> tmpNames = (HashSet<String>)poolNames.clone();
  RemoteIterator<CacheDirectiveEntry> directives = dfs.listCacheDirectives(null);
  int poolCount = poolNames.size();
  for (int i=0; i<poolCount; i++) {
    CacheDirectiveEntry directive = directives.next();
    String pollName = directive.getInfo().getPool();
    assertTrue("The pool name should be expected", tmpNames.remove(pollName));
    if (i % 2 == 0) {
      int standby = active;
      active = (standby == 0) ? 1 : 0;
      cluster.transitionToStandby(standby);
      cluster.transitionToActive(active);
      cluster.waitActive(active);
    }
  }
  assertTrue("All pools must be found", tmpNames.isEmpty());
}
 
Example 5
Source File: TestRetryCacheWithHA.java    From big-c with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void listCachePools(
    HashSet<String> poolNames, int active) throws Exception {
  HashSet<String> tmpNames = (HashSet<String>)poolNames.clone();
  RemoteIterator<CachePoolEntry> pools = dfs.listCachePools();
  int poolCount = poolNames.size();
  for (int i=0; i<poolCount; i++) {
    CachePoolEntry pool = pools.next();
    String pollName = pool.getInfo().getPoolName();
    assertTrue("The pool name should be expected", tmpNames.remove(pollName));
    if (i % 2 == 0) {
      int standby = active;
      active = (standby == 0) ? 1 : 0;
      cluster.transitionToStandby(standby);
      cluster.transitionToActive(active);
      cluster.waitActive(active);
    }
  }
  assertTrue("All pools must be found", tmpNames.isEmpty());
}
 
Example 6
Source File: TestRetryCacheWithHA.java    From big-c with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void listCacheDirectives(
    HashSet<String> poolNames, int active) throws Exception {
  HashSet<String> tmpNames = (HashSet<String>)poolNames.clone();
  RemoteIterator<CacheDirectiveEntry> directives = dfs.listCacheDirectives(null);
  int poolCount = poolNames.size();
  for (int i=0; i<poolCount; i++) {
    CacheDirectiveEntry directive = directives.next();
    String pollName = directive.getInfo().getPool();
    assertTrue("The pool name should be expected", tmpNames.remove(pollName));
    if (i % 2 == 0) {
      int standby = active;
      active = (standby == 0) ? 1 : 0;
      cluster.transitionToStandby(standby);
      cluster.transitionToActive(active);
      cluster.waitActive(active);
    }
  }
  assertTrue("All pools must be found", tmpNames.isEmpty());
}
 
Example 7
Source File: TaskDependecies.java    From BigDataScript with Apache License 2.0 6 votes vote down vote up
/**
 * Is there a circular dependency for this task?
 */
@SuppressWarnings("unchecked")
boolean isCircular(Task task, HashSet<Task> tasks) {
	if (!tasks.add(task)) return true;

	// Get all input files, find corresponding tasks and recurse
	if (task.getInputs() != null) {
		for (String in : task.getInputs()) {
			List<Task> depTasks = getTasksByOutput(in);

			if (depTasks != null) {
				for (Task t : depTasks) {
					HashSet<Task> newTasks = (HashSet<Task>) tasks.clone();
					if (isCircular(t, newTasks)) return true;
				}
			}
		}
	}
	return false;
}
 
Example 8
Source File: DynamicCopyFieldsIT.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void modifyAlfrescoSolrDataModel() throws NoSuchFieldException, IllegalAccessException {
    Field crossLocalePropertiesField = AlfrescoSolrDataModel
            .getInstance()
            .getClass()
            .getDeclaredField("crossLocaleSearchProperties");

    crossLocalePropertiesField.setAccessible(true);

    Field crossLocaleTypesField = AlfrescoSolrDataModel
            .getInstance()
            .getClass()
            .getDeclaredField("crossLocaleSearchDataTypes");

    crossLocaleTypesField.setAccessible(true);

    Field identifierPropertiesField = AlfrescoSolrDataModel
            .getInstance()
            .getClass()
            .getDeclaredField("identifierProperties");

    identifierPropertiesField.setAccessible(true);

    HashSet<QName> crossLocaleProperties = (HashSet<QName>) crossLocalePropertiesField.get(AlfrescoSolrDataModel.getInstance());
    HashSet<QName> crossLocaleTypes = (HashSet<QName>) crossLocaleTypesField.get(AlfrescoSolrDataModel.getInstance());
    HashSet<QName> identifierProperties = (HashSet<QName>) identifierPropertiesField.get(AlfrescoSolrDataModel.getInstance());

    oldCrossLocaleProperties = (HashSet<QName>) crossLocaleProperties.clone();
    oldCrossLocaleTypes = (HashSet<QName>) crossLocaleTypes.clone();
    oldIdentifierProperties = (HashSet<QName>) identifierProperties.clone();

    crossLocaleTypes.clear();
    crossLocaleTypes.add(QName.createQName("http://www.alfresco.org/model/dictionary/1.0", "text"));
    crossLocaleTypes.add(QName.createQName("http://www.alfresco.org/model/dictionary/1.0", "content"));
    crossLocaleProperties.add(getCustomQName(MLTEXT_LOVPARTIAL));
    identifierProperties.add(getCustomQName(MLTEXT_FREE));
}
 
Example 9
Source File: CustomFiltersActionGroup.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean hasChanges(HashSet<String> patterns, String[] oldPatterns) {
	@SuppressWarnings("unchecked")
	HashSet<String> copy= (HashSet<String>) patterns.clone();
	for (int i= 0; i < oldPatterns.length; i++) {
		boolean found= copy.remove(oldPatterns[i]);
		if (!found)
			return true;
	}
	return !copy.isEmpty();
}
 
Example 10
Source File: FileRegistry.java    From secor with Apache License 2.0 5 votes vote down vote up
public void deleteTopicPartitionGroup(TopicPartitionGroup topicPartitioGroup) throws IOException {
    HashSet<LogFilePath> paths = mFiles.get(topicPartitioGroup);
    if (paths == null) {
        return;
    }
    HashSet<LogFilePath> clonedPaths = (HashSet<LogFilePath>) paths.clone();
    for (LogFilePath path : clonedPaths) {
        deletePath(path);
    }
}
 
Example 11
Source File: HashSetTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void test_empty_clone() throws Exception {
    HashSet<Integer> emptyHs = new HashSet<Integer>();
    HashSet<Integer> cloned = (HashSet) emptyHs.clone();
    cloned.add(new Integer(8));
}
 
Example 12
Source File: CopySets.java    From tutorials with MIT License 4 votes vote down vote up
public static <T> Set<T> copyBySetClone(HashSet<T> original) {
    Set<T> copy = (Set<T>) original.clone();
    return copy;
}