org.apache.brooklyn.util.collections.MutableSet.builder()方法的使用及代码示例

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

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

MutableSet.builder介绍

暂无

代码示例

代码示例来源: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-software-base

Set<String> result = MutableSet.<String> builder().
    addAll(getJmxJavaConfigOptions()).
    addAll(getCustomJavaConfigOptions()).

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

@SuppressWarnings("unchecked")
protected <T extends Entity> T createEntityProxy(Iterable<Class<?>> interfaces, T entity) {
  // We don't especially want the proxy to have to implement EntityLocal, 
  // but required by how AbstractEntity.parent is used (e.g. parent.getAllConfig).
  // However within EntityProxyImpl we place add'l guards to prevent read-only access to such methods
  Set<Class<?>> allInterfaces = MutableSet.<Class<?>>builder()
      .add(EntityProxy.class, Entity.class, EntityLocal.class, EntityInternal.class)
      .addAll(interfaces)
      .build();
  // TODO OSGi strangeness! The classloader obtained from the type should be enough.
  // If an OSGi class loader, it should delegate to find things like Entity.class etc.
  // However, we get errors such as:
  //    NoClassDefFoundError: org.apache.brooklyn.api.sensor.AttributeSensor not found by ....brooklyn-test-osgi-entities
  // Building our own aggregating class loader gets around this.
  // But we really should not have to do this! What are the consequences?
  //
  // The reason for the error is that the proxy tries to load all classes
  // referenced from the entity and its interfaces with the single passed loader
  // while a normal class loading would nest the class loaders (loading interfaces'
  // references with their own class loaders which in our case are different).
  AggregateClassLoader aggregateClassLoader = classLoaderCache.getClassLoaderForProxy(entity.getClass(), allInterfaces);
  return (T) java.lang.reflect.Proxy.newProxyInstance(
      aggregateClassLoader,
      allInterfaces.toArray(new Class[allInterfaces.size()]),
      new EntityProxyImpl(entity));
}

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

public void testBuilderRetainAll() throws Exception {
  Set<Object> vals = MutableSet.builder()
      .add(1,2,3)
      .retainAll(ImmutableList.of(1,2))
      .build();
  Assert.assertEquals(vals, ImmutableSet.of(1,2));
}

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

public void testBuilderAddIterator() throws Exception {
  Set<Object> vals = MutableSet.builder().addAll(ImmutableSet.of(1,2).iterator()).build();
  Assert.assertEquals(vals, ImmutableSet.of(1,2));
}

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

Set<String> newlyDiscoveredLocs = MutableSet.<String>builder()
    .addAll(referencedLocs)
    .removeAll(alreadyReferencedLocations)

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

public void testBuilderAddArray() throws Exception {
  Set<Object> vals = MutableSet.builder().addAll(new Object[] {1,2,3}).build();
  Assert.assertEquals(vals, ImmutableSet.of(1,2,3));
}

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

public void testBuilderAddVarargs() throws Exception {
  Set<Object> vals = MutableSet.builder().add(1,2,3).build();
  Assert.assertEquals(vals, ImmutableSet.of(1,2,3));
}

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

public void testBuilderAddIterable() throws Exception {
  Set<Object> vals = MutableSet.builder().addAll(ImmutableSet.of(1,2)).addAll(ImmutableSet.of(2,3)).build();
  Assert.assertEquals(vals, ImmutableSet.of(1,2,3));
}

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

public void testBuilderAddIfNotNull() throws Exception {
  Set<Object> vals = MutableSet.builder().addIfNotNull(1).addIfNotNull(null).build();
  Assert.assertEquals(vals, ImmutableSet.of(1));
}

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

public void testBuilderRemoveAll() throws Exception {
  Set<Object> vals = MutableSet.builder()
      .add(1,2,3)
      .removeAll(ImmutableSet.of(2,3))
      .add(4)
      .build();
  Assert.assertEquals(vals, ImmutableSet.of(1,4));
}

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

public void testBuilderRemoval() throws Exception {
  Set<Object> vals = MutableSet.builder()
      .add(1,2,3)
      .remove(2)
      .add(4)
      .build();
  Assert.assertEquals(vals, ImmutableSet.of(1,3,4));
}

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

@Test
public void testRemoveConfigKey() throws Exception {
  entity.getMutableEntityType().removeConfigKey(ConfigEntityForTesting.INSTALL_UNIQUE_LABEL);
  assertEquals(entity.getEntityType().getConfigKeys(), 
      MutableSet.builder().addAll(DEFAULT_CONFIG_KEYS).remove(ConfigEntityForTesting.INSTALL_UNIQUE_LABEL).build().asUnmodifiable());
  
  assertEventuallyListenerEventsEqual(ImmutableList.of(
    BasicSensorEvent.ofUnchecked(AbstractEntity.CONFIG_KEY_REMOVED, entity, ConfigEntityForTesting.INSTALL_UNIQUE_LABEL)));
}

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

@Test
public void testRemoveSensor() throws Exception {
  entity.getMutableEntityType().removeSensor(SENSOR_ADDED);
  assertEquals(entity.getEntityType().getSensors(), 
      MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).build().asUnmodifiable());
  
  assertEventuallyListenerEventsEqual(ImmutableList.of(
    BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED)));
}

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

@Test
public void testUpdateCalledWithAddressesOfNewChildren() {
  // First child
  cluster.resize(1);
  Entity child = Iterables.getOnlyElement(cluster.getMembers());
  
  List<Collection<String>> u = Lists.newArrayList(controller.getUpdates());
  assertTrue(u.isEmpty(), "expected empty list but got "+u);
  
  child.sensors().set(WebServerEntity.HTTP_PORT, 1234);
  child.sensors().set(Startable.SERVICE_UP, true);
  assertEventuallyAddressesMatchCluster();
  // Second child
  cluster.resize(2);
  Asserts.succeedsEventually(new Runnable() {
    @Override
    public void run() {
      assertEquals(cluster.getMembers().size(), 2);
    }});
  Entity child2 = Iterables.getOnlyElement(MutableSet.<Entity>builder().addAll(cluster.getMembers()).remove(child).build());
  
  child2.sensors().set(WebServerEntity.HTTP_PORT, 1234);
  child2.sensors().set(Startable.SERVICE_UP, true);
  assertEventuallyAddressesMatchCluster();
  
  // And remove all children; expect all addresses to go away
  cluster.resize(0);
  assertEventuallyAddressesMatchCluster();
}

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

@Test
public void testRemoveSensors() throws Exception {
  entity.getMutableEntityType().removeSensor(SENSOR_ADDED.getName());
  entity.getMutableEntityType().removeSensor(POLICY_ADDED.getName());
  assertEquals(entity.getEntityType().getSensors(), 
      MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).remove(POLICY_ADDED).build().asUnmodifiable());
  final RecordingSensorEventListener<?> listener = this.listener;
  Asserts.succeedsEventually(new Runnable() {
    @Override
    public void run() {
      assertEquals(Iterables.size(listener.getEvents()), 2);
    }
  });
  assertEventuallyListenerEventsEqual(ImmutableList.of(
    BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED),
    BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, POLICY_ADDED)));
}

相关文章