tovisit.addAll(Arrays.asList(nextclazz.getInterfaces())); result.addAll(Iterables.filter(Arrays.asList(nextclazz.getDeclaredFields()), filter!=null ? filter : Predicates.<Field>alwaysTrue()));
tovisit.addAll(Arrays.asList(nextclazz.getInterfaces())); result.addAll(Iterables.filter(Arrays.asList(nextclazz.getDeclaredMethods()), new Predicate<Method>() { @Override public boolean apply(Method input) { return Modifier.isPublic(input.getModifiers());
public void testBuilderAddIterator() throws Exception { List<Object> vals = MutableList.builder().addAll(ImmutableList.of(1,2).iterator()).build(); Assert.assertEquals(vals, ImmutableList.of(1,2)); }
@Test public void testExistingChildrenStartedRoundRobiningAcrossLocations() throws Exception { List<Location> locs = ImmutableList.of(loc1, loc2); DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class) .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class))); List<TestEntity> existingChildren = Lists.newArrayList(); for (int i = 0; i < 4; i++) { existingChildren.add(fabric.addChild(EntitySpec.create(TestEntity.class))); } app.start(locs); // Expect only these existing children Asserts.assertEqualsIgnoringOrder(fabric.getChildren(), existingChildren); Asserts.assertEqualsIgnoringOrder(fabric.getMembers(), existingChildren); // Expect one location per existing child (round-robin) // Expect one location per existing child List<Location> remainingLocs = MutableList.<Location>builder().addAll(locs).addAll(locs).build(); for (Entity existingChild : existingChildren) { Collection<Location> childLocs = existingChild.getLocations(); assertEquals(childLocs.size(), 1, "childLocs="+childLocs); assertTrue(remainingLocs.remove(Iterables.get(childLocs, 0)), "childLocs="+childLocs+"; remainingLocs="+remainingLocs+"; allLocs="+locs); } }
@Override public void removeLocations(Collection<? extends Location> removedLocations) { synchronized (locations) { List<Location> oldLocations = locations.get(); Set<Location> trulyRemovedLocations = Sets.intersection(ImmutableSet.copyOf(removedLocations), ImmutableSet.copyOf(oldLocations)); locations.set(MutableList.<Location>builder().addAll(oldLocations).removeAll(removedLocations).buildImmutable()); for (Location loc : trulyRemovedLocations) { sensors().emit(AbstractEntity.LOCATION_REMOVED, loc); } } // TODO Not calling `Entities.unmanage(removedLocation)` because this location might be shared with other entities. // Relying on abstractLocation.removeChildLocation unmanaging it, but not ideal as top-level locations will stick // around forever, even if not referenced. // Same goes for AbstractEntity#clearLocations(). getManagementSupport().getEntityChangeListener().onLocationsChanged(); }
@Test public void testExistingChildrenToppedUpWhenNewMembersIfMoreLocations() throws Exception { List<Location> locs = ImmutableList.of(loc1, loc2, loc3); DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class) .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(TestEntity.class))); TestEntity existingChild = fabric.addChild(EntitySpec.create(TestEntity.class)); app.start(locs); // Expect three children: the existing one, and one per other location assertEquals(fabric.getChildren().size(), 3, "children="+fabric.getChildren()); assertTrue(fabric.getChildren().contains(existingChild), "children="+fabric.getChildren()+"; existingChild="+existingChild); Asserts.assertEqualsIgnoringOrder(fabric.getMembers(), fabric.getChildren()); List<Location> remainingLocs = MutableList.<Location>builder().addAll(locs).build(); for (Entity child : fabric.getChildren()) { Collection<Location> childLocs = child.getLocations(); assertEquals(childLocs.size(), 1, "childLocs="+childLocs); assertTrue(remainingLocs.remove(Iterables.get(childLocs, 0)), "childLocs="+childLocs+"; remainingLocs="+remainingLocs+"; allLocs="+locs); } }
@Override protected List<String> getCustomJavaConfigOptions() { return MutableList.<String>builder() .addAll(super.getCustomJavaConfigOptions()) .add("-Xms200m") .add("-Xmx800m") .add("-XX:MaxPermSize=400m") .build(); }
@Override protected List<String> getCustomJavaConfigOptions() { return MutableList.<String>builder() .addAll(super.getCustomJavaConfigOptions()) .add("-server") .build(); }; };
public void testBuilderAddArray() throws Exception { List<Object> vals = MutableList.builder().addAll(new Object[] {1,2,3}).build(); Assert.assertEquals(vals, ImmutableList.of(1,2,3)); }
public static <E> MutableList<E> copyOf(Iterator<? extends E> elements) { if (!elements.hasNext()) { return of(); } return new MutableList.Builder<E>().addAll(elements).build(); }
protected BasicDownloadTargets(Builder builder) { primaries = ImmutableList.copyOf(builder.primaries); fallbacks = MutableList.<String>builder().addAll(builder.fallbacks).removeAll(builder.primaries).build().asUnmodifiable(); canContinueResolving = builder.canContinueResolving; }
@Override protected List<String> getCustomJavaConfigOptions() { return MutableList.<String>builder() .addAll(super.getCustomJavaConfigOptions()) .add("-Xms200m") .add("-Xmx800m") .add("-XX:MaxPermSize=400m") .build(); }
@Override protected List<String> getCustomJavaConfigOptions() { return MutableList.<String>builder().addAll(super.getCustomJavaConfigOptions()).add("-Dabc=def").build(); } }
@Override protected List<String> getCustomJavaConfigOptions() { return MutableList.<String>builder() .addAll(super.getCustomJavaConfigOptions()) .add("-Xms200m") .add("-Xmx800m") .add("-XX:MaxPermSize=400m") .build(); }
@Override protected List<String> getCustomJavaConfigOptions() { return MutableList.<String>builder() .addAll(super.getCustomJavaConfigOptions()) .add("-Xms200m") .add("-Xmx800m") .add("-XX:MaxPermSize=400m") .build(); }
public Builder<V> addLists(Iterable<? extends V> ...items) { for (Iterable<? extends V> item: items) { addAll(item); } return this; } }