下面列出了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");
}
}
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);
}
@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());
}
@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());
}
@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());
}
@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());
}
/**
* 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;
}
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();
}
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);
}
}
public void test_empty_clone() throws Exception {
HashSet<Integer> emptyHs = new HashSet<Integer>();
HashSet<Integer> cloned = (HashSet) emptyHs.clone();
cloned.add(new Integer(8));
}
public static <T> Set<T> copyBySetClone(HashSet<T> original) {
Set<T> copy = (Set<T>) original.clone();
return copy;
}