org.apache.brooklyn.util.collections.MutableSet类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中org.apache.brooklyn.util.collections.MutableSet类的一些代码示例,展示了MutableSet类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MutableSet类的具体详情如下:
包路径:org.apache.brooklyn.util.collections.MutableSet
类名称:MutableSet

MutableSet介绍

暂无

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
  public Collection<BrooklynObject> get() {
    return MutableSet.of();
  }
});

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public EqualToAny(Iterable<? extends T> vals) {
  this.vals = MutableSet.copyOf(vals); // so allows nulls
}
@Override

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
protected Set<Object> merge(boolean unmodifiable, Iterable<?>... sets) {
  MutableSet<Object> result = MutableSet.of();
  for (Iterable<?> set: sets) result.addAll(set);
  if (unmodifiable) return result.asUnmodifiable();
  return result;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public Builder<V> removeAll(Iterable<? extends V> iterable) {
  if (iterable instanceof Collection) {
    result.removeAll((Collection<? extends V>) iterable);
  } else {
    for (V v : iterable) {
      result.remove(v);
    }
  }
  return this;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public Builder<V> addAll(Iterable<? extends V> iterable) {
  if (iterable instanceof Collection) {
    result.addAll((Collection<? extends V>) iterable);
  } else {
    for (V v : iterable) {
      result.add(v);
    }
  }
  return this;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public static <V> MutableSet<V> of(V v1, V v2) {
  MutableSet<V> result = new MutableSet<V>();
  result.add(v1);
  result.add(v2);
  return result;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

/** checks that all accepted enum values are represented by the given set of explicit values */
public static void checkAllEnumeratedIgnoreCase(String contextMessage, Enum<?>[] enumValues, String ...explicitValues) {
  MutableSet<String> explicitValuesSet = MutableSet.copyOf(Iterables.transform(Arrays.asList(explicitValues), StringFunctions.toLowerCase()));
  
  Set<Enum<?>> missingEnums = MutableSet.of();
  for (Enum<?> e: enumValues) {
    if (explicitValuesSet.remove(e.name().toLowerCase())) continue;
    if (explicitValuesSet.remove(e.toString().toLowerCase())) continue;
    
    if (explicitValuesSet.remove(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, e.name()).toLowerCase())) continue;
    if (explicitValuesSet.remove(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, e.toString()).toLowerCase())) continue;
    
    if (explicitValuesSet.remove(CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, e.toString()).toLowerCase())) continue;
    if (explicitValuesSet.remove(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, e.name()).toLowerCase())) continue;
    
    missingEnums.add(e);
  }
  
  if (!missingEnums.isEmpty() || !explicitValuesSet.isEmpty()) {
    throw new IllegalStateException("Not all options for "+contextMessage+" are enumerated; "
      + "leftover enums = "+missingEnums+"; "
      + "leftover values = "+explicitValuesSet);
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-launcher

bn.start(MutableSet.<Location>of());
log.info("Deployment result: "+t.getUnchecked());
MutableSet<Application> apps = MutableSet.copyOf( l.getManagementContext().getApplications() );
Assert.assertEquals(apps.size(), 2);
apps.remove(app);
apps = MutableSet.copyOf( l.getManagementContext().getApplications() );
apps.removeAll( MutableSet.of(app, newApp) );
Application newApp2 = Iterables.getOnlyElement(apps);
Entities.dumpInfo(newApp2);

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public void testContainingNullAndUnmodifiable() {
  MutableSet<Object> x = MutableSet.<Object>of("x", null);
  Assert.assertTrue(x.contains(null));
  
  Set<Object> x1 = x.asUnmodifiable();
  Set<Object> x2 = x.asUnmodifiableCopy();
  Set<Object> x3 = x.asImmutableCopy();
  
  x.remove(null);
  Assert.assertFalse(x.contains(null));
  Assert.assertFalse(x1.contains(null));
  Assert.assertTrue(x2.contains(null));
  Assert.assertTrue(x3.contains(null));
  
  try { x1.remove("x"); Assert.fail(); } catch (Exception e) { /* expected */ }
  try { x2.remove("x"); Assert.fail(); } catch (Exception e) { /* expected */ }
  try { x3.remove("x"); Assert.fail(); } catch (Exception e) { /* expected */ }
  
  Assert.assertTrue(x1.contains("x"));
  Assert.assertTrue(x2.contains("x"));
  Assert.assertTrue(x3.contains("x"));
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-rest-resources

private LinkedHashMap<String, TaskSummary> getAllDescendantTasks(final Task<?> parentTask, int limit, int maxDepth) {
  final LinkedHashMap<String, TaskSummary> result = Maps.newLinkedHashMap();
  if (!(parentTask instanceof HasTaskChildren)) {
    return result;
  }
  Set<Task<?>> nextLayer = MutableSet.copyOf( ((HasTaskChildren) parentTask).getChildren() );
  outer: while (limit!=0 && !nextLayer.isEmpty() && maxDepth-- != 0) {
    Set<Task<?>> thisLayer = nextLayer;
    nextLayer = MutableSet.of();
    for (final Task<?> childTask : thisLayer) {
      TaskSummary wasThere = result.put(childTask.getId(), TaskTransformer.fromTask(ui.getBaseUriBuilder()).apply(childTask));
      if (wasThere==null) {
        if (--limit == 0) {
          break outer;
        }
        if (childTask instanceof HasTaskChildren) {
          Iterables.addAll(nextLayer, ((HasTaskChildren)childTask).getChildren());
        }
      }
    }
  }
  return result;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public static RegisteredTypeLoadingContext alreadyEncountered(Set<String> encounteredTypeSymbolicNames, String anotherEncounteredType) {
  BasicRegisteredTypeLoadingContext result = new BasicRegisteredTypeLoadingContext();
  MutableSet<String> encounteredTypes = MutableSet.copyOf(encounteredTypeSymbolicNames);
  encounteredTypes.addIfNotNull(anotherEncounteredType);
  result.encounteredTypes = encounteredTypes.asUnmodifiable();
  return result;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@SuppressWarnings("deprecation")
protected Set<ConfigKey<?>> findKeys(Predicate<? super ConfigKey<?>> filter, KeyFindingMode mode) {
  MutableSet<ConfigKey<?>> result = MutableSet.of();
  if (mode==KeyFindingMode.DECLARED_OR_PRESENT) {
    result.addAll( Iterables.filter(getKeysAtContainer(getContainer()), filter) );
  }
  for (ConfigKey<?> k: Iterables.filter(ownConfig.keySet(), filter)) {
    if (result.contains(k)) continue;
    if (mode!=KeyFindingMode.PRESENT_NOT_RESOLVED) {
      ConfigKey<?> k2 = getKeyAtContainer(getContainer(), k);
      if (k2!=null) k = k2;
    }
    result.add(k);
  }
  // due to set semantics local should be added first, it prevents equal items from parent from being added on top
  if (getParent()!=null) {
    // now take from runtime parents, but filtered
    Set<ConfigKey<?>> inherited;
    switch (mode) {
    case DECLARED_OR_PRESENT:  inherited = getParentInternal().config().getInternalConfigMap().findKeysDeclared(filter); break;
    case PRESENT_AND_RESOLVED: inherited = getParentInternal().config().getInternalConfigMap().findKeysPresent(filter); break;
    case PRESENT_NOT_RESOLVED: inherited = getParentInternal().config().getInternalConfigMap().findKeys(filter); break;
    default:
      throw new IllegalStateException("Unsupported key finding mode: "+mode);
    }
    // TODO due to recursive nature we call this N times for the Nth level ancestor 
    result.addAll( filterOutRuntimeNotReinherited(inherited) );
  }
  return result;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

@Override
  public Set<String> apply(final String input) {
    return MutableSet.copyOf(JavaStringEscapes.unwrapJsonishListIfPossible(input)).asUnmodifiable();
  }
});

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
public Iterable<URL> getResources(String name) {
  MutableSet<URL> result = MutableSet.<URL>of();
  for (BrooklynClassLoadingContext target : primaries) {
    result.addAll(target.getResources(name));
  }
  for (BrooklynClassLoadingContext target : secondaries) {
    result.addAll(target.getResources(name));
  }
  return result;
}

代码示例来源:origin: io.brooklyn.clocker/brooklyn-clocker-docker

@Override
public void disconnect(DockerContainer container, VirtualNetwork network) {
  synchronized (network) {
    MutableSet<Entity> connected = MutableSet.copyOf(network.sensors().get(VirtualNetwork.CONNECTED_CONTAINERS));
    connected.remove(container);
    network.sensors().set(VirtualNetwork.CONNECTED_CONTAINERS, connected.asImmutableCopy());
  }
  network.relations().remove(VirtualNetwork.CONNECTED, container);
  container.relations().remove(VirtualNetwork.CONNECTED, network);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

String locationProxyXpath = prefix+"//locationProxy";
Set<String> locsToInspect = MutableSet.copyOf(alreadyReferencedLocations);
  Set<String> newlyDiscoveredLocs = MutableSet.<String>builder()
      .addAll(referencedLocs)
      .removeAll(alreadyReferencedLocations)

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

Collection<CatalogBundle> librariesAddedHereBundles = CatalogItemDtoAbstract.parseLibraries(librariesAddedHereNames);
MutableSet<Object> librariesCombinedNames = MutableSet.of();
if (!isNoBundleOrSimpleWrappingBundle(mgmt, containingBundle)) {
  librariesCombinedNames.add(containingBundle.getVersionedName().toOsgiString());
librariesCombinedNames.putAll(librariesAddedHereNames);
librariesCombinedNames.putAll(getFirstAs(parentMetadata, Collection.class, "brooklyn.libraries", "libraries").orNull());
if (!librariesCombinedNames.isEmpty()) {
  catalogMetadata.put("brooklyn.libraries", librariesCombinedNames);

代码示例来源:origin: io.brooklyn.clocker/brooklyn-clocker-docker

@Override
public void connect(DockerContainer container, VirtualNetwork network) {
  synchronized (network) {
    MutableSet<Entity> connected = MutableSet.copyOf(network.sensors().get(VirtualNetwork.CONNECTED_CONTAINERS));
    connected.add(container);
    network.sensors().set(VirtualNetwork.CONNECTED_CONTAINERS, connected.asImmutableCopy());
  }
  network.relations().add(VirtualNetwork.ATTACHED, container);
  container.relations().add(VirtualNetwork.CONNECTED, network);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

private Set<?> mergeSetsImpl(Set<?> val1, Set<?> val2, int depthRemaining, Visited visited) {
  return MutableSet.builder()
      .addAll(val1)
      .addAll(val2)
      .build();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

protected void expireUnmanagedEntityTasks() {
  Iterator<Entry<Entity, Task<?>>> ei;
  synchronized (unmanagedEntitiesNeedingGc) {
    ei = MutableSet.copyOf(unmanagedEntitiesNeedingGc.entrySet()).iterator();
  }
  while (ei.hasNext()) {
    Entry<Entity, Task<?>> ee = ei.next();
    if (Entities.isManaged(ee.getKey())) continue;
    if (ee.getValue()!=null && !ee.getValue().isDone()) continue;
    deleteTasksForEntity(ee.getKey());
    synchronized (unmanagedEntitiesNeedingGc) {
      unmanagedEntitiesNeedingGc.remove(ee.getKey());
    }
  }
}

相关文章