java.util.HashSet#clone ( )源码实例Demo

下面列出了java.util.HashSet#clone ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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"); 
    }
}
 
源代码2 项目: SearchServices   文件: AFTSDefaultTextQueryIT.java
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);
}
 
源代码3 项目: hadoop   文件: TestRetryCacheWithHA.java
@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());
}
 
源代码4 项目: hadoop   文件: TestRetryCacheWithHA.java
@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());
}
 
源代码5 项目: big-c   文件: TestRetryCacheWithHA.java
@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());
}
 
源代码6 项目: big-c   文件: TestRetryCacheWithHA.java
@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());
}
 
源代码7 项目: BigDataScript   文件: TaskDependecies.java
/**
 * 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;
}
 
源代码8 项目: SearchServices   文件: DynamicCopyFieldsIT.java
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));
}
 
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();
}
 
源代码10 项目: secor   文件: FileRegistry.java
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);
    }
}
 
源代码11 项目: j2objc   文件: HashSetTest.java
public void test_empty_clone() throws Exception {
    HashSet<Integer> emptyHs = new HashSet<Integer>();
    HashSet<Integer> cloned = (HashSet) emptyHs.clone();
    cloned.add(new Integer(8));
}
 
源代码12 项目: tutorials   文件: CopySets.java
public static <T> Set<T> copyBySetClone(HashSet<T> original) {
    Set<T> copy = (Set<T>) original.clone();
    return copy;
}