@Override public Collection<BrooklynObject> get() { return MutableSet.of(); } });
public EqualToAny(Iterable<? extends T> vals) { this.vals = MutableSet.copyOf(vals); // so allows nulls } @Override
@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; }
public static <V> MutableSet<V> of(V v1, V v2) { MutableSet<V> result = new MutableSet<V>(); result.add(v1); result.add(v2); return result; }
/** 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); } }
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);
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")); }
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; }
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; }
@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; }
@Override public Set<String> apply(final String input) { return MutableSet.copyOf(JavaStringEscapes.unwrapJsonishListIfPossible(input)).asUnmodifiable(); } });
@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; }
@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); }
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);
@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); }
private Set<?> mergeSetsImpl(Set<?> val1, Set<?> val2, int depthRemaining, Visited visited) { return MutableSet.builder() .addAll(val1) .addAll(val2) .build(); }
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()); } } }