public static List<NamedStringTag> findAll(String kind, Iterable<Object> tags) { List<NamedStringTag> result = MutableList.of(); for (Object object: tags) { if (object instanceof NamedStringTag && kind.equals(((NamedStringTag)object).kind)) result.add( (NamedStringTag) object ); } return result; }
private static Iterable<PlanToSpecTransformer> filterDeprecated(Iterable<PlanToSpecTransformer> transformers) { List<PlanToSpecTransformer> result = MutableList.of(); for (PlanToSpecTransformer t: transformers) { if (!isDeprecated(t.getClass())) { result.add(t); } } return result; }
private List<String> getStringList(String innerPath) { List<String> result = MutableList.of(); final NodeList nodeList = (NodeList) XmlUtil.xpathHandlingIllegalChars(contents, prefix + innerPath + "//string", XPathConstants.NODESET); for(int c = 0 ; c < nodeList.getLength() ; c++) { result.add(nodeList.item(c).getFirstChild().getNodeValue()); } return result; } }
public static List<String> wrapJavaStrings(Iterable<String> values) { if (values==null) return null; List<String> result = MutableList.of(); for (String v: values) result.add(wrapJavaString(v)); return result; }
void addEntry(CatalogItemDtoAbstract<?, ?> entry) { if (entries == null) entries = MutableList.of(); CatalogItemDtoAbstract<?, ?> oldEntry = getEntriesMap().get(entry.getId()); entries.add(entry); if (oldEntry!=null) removeEntry(oldEntry); }
private List<String> identities(Collection<?> objs) { List<String> result = MutableList.of(); for (Object obj: objs) result.add(Integer.toHexString(System.identityHashCode(obj))); return result; }
public void testEqualsDifferentTypes() { List<Object> a = MutableList.<Object>of("a", 1, "b", false); List<Object> b = Arrays.<Object>asList("a", 1, "b", false); Assert.assertEquals(a, b); Assert.assertEquals(b, a); }
@Override public List<String> listContentsWithSubPath(final String parentSubPath) { if (!prepared) throw new IllegalStateException("prepare method not yet invoked: "+this); synchronized (filesByName) { List<String> result = MutableList.of(); for (String file: filesByName.keySet()) if (file.startsWith(parentSubPath)) result.add(file); return result; } }
@Test public void testMin() throws Exception { Function<Collection<? extends Number>, Integer> func = MathAggregatorFunctions.computingMin(null, null, Integer.class); assertEquals(func.apply(MutableList.<Number>of(1, 3, 5)), (Integer)1); assertEquals(func.apply(MutableList.<Number>of(3, null, 1)), (Integer)1); }
private void populateInitialFromUri(BasicBrooklynCatalog catalog, String catalogUrl) { log.debug("Loading initial catalog from {}", catalogUrl); try { String contents = new ResourceUtils(this).getResourceAsString(catalogUrl); catalog.reset(MutableList.<CatalogItem<?,?>>of()); Object result = catalog.addItems(contents); log.debug("Loaded initial catalog from {}: {}", catalogUrl, result); } catch (Exception e) { Exceptions.propagateIfFatal(e); log.warn("Error importing catalog from " + catalogUrl + ": " + e, e); } }
@Test public void testMutableList() throws Exception { List<?> obj = MutableList.of("123"); assertSerializeAndDeserialize(obj); }
public static List<Point> listOfIntegerCoords(Iterable<? extends Iterable<Integer>> points) { MutableList<Point> result = MutableList.of(); for (Iterable<Integer> point: points) result.add(ofIntegerCoords(point)); return result.asUnmodifiable(); } @Override
@Test public void testCastValueWithTypeToken() throws Exception { List<Function<Collection<? extends Number>, Double>> funcs = new ArrayList<>(); funcs.add(MathAggregatorFunctions.computingSum(999, null, doubleTypeToken)); funcs.add(MathAggregatorFunctions.computingAverage(999, null, doubleTypeToken)); funcs.add(MathAggregatorFunctions.computingMin(999, null, doubleTypeToken)); funcs.add(MathAggregatorFunctions.computingMax(999, null, doubleTypeToken)); for (Function<Collection<? extends Number>, Double> func : funcs) { assertEquals(func.apply(MutableList.<Number>of(null)), (Double)999d); } }
/** returns fields which should be used for equality, including by default {@link #toStringOtherFields()} and {@link #toStringPollSource()}; * subclasses can add to the returned value */ protected MutableList<Object> equalsFields() { MutableList<Object> result = MutableList.of().appendIfNotNull(getSensor()).appendIfNotNull(toStringPollSource()); for (Object field: toStringOtherFields()) result.appendIfNotNull(field); return result; }
@Test public void testAddListAtRootAddsReference() { MutableList<Object> list = MutableList.<Object>of("a", "b"); Navigator<MutableMap<Object, Object>> j = Jsonya.newInstance().add(list); Assert.assertEquals( j.toString(), "[ \"a\", \"b\" ]"); list.append("c"); Assert.assertEquals( j.toString(), "[ \"a\", \"b\", \"c\" ]"); }
@Test public void testAddStringToListAtRoot() { Navigator<MutableMap<Object, Object>> j = Jsonya.newInstance().list().add("a", "b").root(); Assert.assertEquals( j.toString(), "[ \"a\", \"b\" ]" ); Assert.assertEquals( j.get(), MutableList.of("a", "b") ); }
@SuppressWarnings("unchecked") @Override public void setEntity(EntityLocal entity) { super.setEntity(entity); subscriptions().subscribe(entity, SERVICE_PROCESS_IS_RUNNING, this); subscriptions().subscribe(entity, Attributes.SERVICE_UP, this); highlightTriggers(MutableList.of(SERVICE_PROCESS_IS_RUNNING, Attributes.SERVICE_UP), entity); onUpdated(); }
@Test public void testAddListToExistingRootAddsCopy() { MutableList<Object> list = MutableList.<Object>of("a", "b"); Navigator<MutableMap<Object, Object>> j = Jsonya.newInstance().list().add(list); Assert.assertEquals( j.toString(), "[ \"a\", \"b\" ]"); list.append("c"); Assert.assertEquals( j.toString(), "[ \"a\", \"b\" ]"); }
@Test public void testAddListToExistingAddsCopy() { MutableList<Object> list = MutableList.<Object>of("a", "b"); Navigator<MutableMap<Object, Object>> j = Jsonya.newInstance().at("root").list().add(list).root(); Assert.assertEquals( j.toString(), "{ \"root\": [ \"a\", \"b\" ] }"); list.append("c"); Assert.assertEquals( j.toString(), "{ \"root\": [ \"a\", \"b\" ] }"); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public void testListEmpty() throws Exception { // ensure it is null before we pass something in, and passing an empty collection makes it be empty log.info("List-Empty-1: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), null); entity.config().set((ListConfigKey)TestEntity.CONF_LIST_THING, MutableList.of()); log.info("List-Empty-2: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig())); Assert.assertEquals(entity.getConfig(TestEntity.CONF_LIST_THING), ImmutableList.of()); }