/** convenience for converting an object x to something which consists only of json primitives, doing * {@link #toString()} on anything which is not recognised. see {@link JsonPrimitiveDeepTranslator} */ public static Object convertToJsonPrimitive(Object x) { if (x==null) return null; if (x instanceof Map) return newInstancePrimitive().put((Map<?,?>)x).getRootMap(); return newInstancePrimitive().put("data", x).getRootMap().get("data"); }
private static String toJson(Map<?,?> x) { // was: // return new Gson().toJson(x); // but GSON does funny things with DSL, whereas toString is the right thing to do return Jsonya.newInstance().add(x).toString(); }
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
private static Object immutable(Object in) { if (in instanceof Map) return MutableMap.copyOf((Map<?,?>)in).asUnmodifiable(); if (in instanceof Iterable) return MutableList.copyOf((Iterable<?>)in).asUnmodifiable(); return in; }
@Override protected Map getCustomJavaSystemProperties() { return MutableMap.<String, String>builder() .put("jboss.platform.mbeanserver", null) .put("javax.management.builder.initial", "org.jboss.system.server.jmx.MBeanServerBuilderImpl") .put("java.util.logging.manager", "org.jboss.logmanager.LogManager") .put("org.jboss.logging.Logger.pluginClass", "org.jboss.logging.logmanager.LoggerPluginImpl") .build(); } }
private Iterable<?> mergeIterablesImpl(Iterable<?> val1, Iterable<?> val2, int depthRemaining, Visited visited) { if (depthRemaining < 1) { return val1; } if (val1 instanceof Set) { return mergeSetsImpl((Set<?>)val1, MutableSet.copyOf(val2), depthRemaining, visited); } else { return mergeListsImpl(MutableList.copyOf(val1), val2, depthRemaining, visited); } }
/** as {@link #newInstance()} but using the given translator to massage objects inserted into the Jsonya structure */ public static Navigator<MutableMap<Object,Object>> newInstanceTranslating(Function<Object,Object> translator) { return newInstance().useTranslator(translator); }
/** * Returns a predicate for a collection which is true if * all elements in the collection given to the predicate * which satisfies the predicate given here. * <p> * This will return true for the empty set. * To require additionally that there is at least one * use {@link #quorum(QuorumCheck, Predicate)} with * {@link QuorumChecks#allAndAtLeastOne()}. */ public static <T,TT extends Iterable<T>> Predicate<TT> all(Predicate<T> attributeSatisfies) { return quorum(QuorumChecks.all(), attributeSatisfies); }
/** Returns a predicate for a collection which is true if * there is at least one element in the collection given to the predicate * which satisfies the predicate given here. */ public static <T,TT extends Iterable<T>> Predicate<TT> any(Predicate<T> attributeSatisfies) { // implementation could be more efficient -- ie succeed fast return quorum(QuorumChecks.atLeastOne(), attributeSatisfies); }
@Override public QuorumCheck apply(final Integer input) { return QuorumChecks.of(input); } });
/** as {@link #newInstanceTranslating(Function)} using a function which only supports JSON primitives: * maps and collections are traversed, strings and primitives are inserted, and everything else has toString applied. * see {@link JsonPrimitiveDeepTranslator} */ public static Navigator<MutableMap<Object,Object>> newInstancePrimitive() { return newInstanceTranslating(new JsonPrimitiveDeepTranslator()); }
public static LinearRangeQuorumCheck of(String name, Iterable<? extends Iterable<Integer>> points) { return new LinearRangeQuorumCheck(name, Point.listOfIntegerCoords(points)); } public static LinearRangeQuorumCheck of(Iterable<? extends Iterable<Integer>> points) {
@Override protected Object createCollection(Class type) { return new MutableSet<Object>(); } }