@Override public Map<EName, List<DublinCoreValue>> getValues() { return mlist(data.values().iterator()) .foldl(new HashMap<EName, List<DublinCoreValue>>(), new Function2<HashMap<EName, List<DublinCoreValue>>, List<CatalogEntry>, HashMap<EName, List<DublinCoreValue>>>() { @Override public HashMap<EName, List<DublinCoreValue>> apply(HashMap<EName, List<DublinCoreValue>> map, List<CatalogEntry> entries) { if (entries.size() > 0) { final EName property = entries.get(0).getEName(); map.put(property, mlist(entries).map(toDublinCoreValue).value()); } return map; } }); }
/** Merge a list of objects into one (last one wins). */ public static Obj append(Obj... os) { final List<Prop> props = mlist(os).foldl(new ArrayList<Prop>(), new Function2<ArrayList<Prop>, Obj, ArrayList<Prop>>() { @Override public ArrayList<Prop> apply(ArrayList<Prop> props, Obj obj) { props.addAll(obj.getProps()); return props; } }); return new Obj(props); }
/** Append a list of arrays into one. */ public static Arr append(Arr... as) { final List<Val> vals = mlist(as).foldl(new ArrayList<Val>(), new Function2<ArrayList<Val>, Arr, ArrayList<Val>>() { @Override public ArrayList<Val> apply(ArrayList<Val> vals, Arr arr) { vals.addAll(arr.getVals()); return vals; } }); return new Arr(vals); } }
/** * Constructor function for ACLs. * * @see #entry(String, String, boolean) * @see #entries(String, org.opencastproject.util.data.Tuple[]) */ public static AccessControlList acl(Either<AccessControlEntry, List<AccessControlEntry>>... entries) { // sequence entries final List<AccessControlEntry> seq = mlist(entries) .foldl(new ArrayList<AccessControlEntry>(), new Function2<List<AccessControlEntry>, Either<AccessControlEntry, List<AccessControlEntry>>, List<AccessControlEntry>>() { @Override public List<AccessControlEntry> apply(List<AccessControlEntry> sum, Either<AccessControlEntry, List<AccessControlEntry>> current) { if (current.isLeft()) sum.add(current.left().value()); else sum.addAll(current.right().value()); return sum; } }); return new AccessControlList(seq); }
/** Sequence a list of options. [Option a] -> Option [a] */ public static <A> Option<List<A>> sequenceOpt(List<Option<A>> as) { final List<A> seq = mlist(as).foldl(new ArrayList<A>(), new Function2<List<A>, Option<A>, List<A>>() { @Override public List<A> apply(List<A> sum, Option<A> o) { for (A a : o) { sum.add(a); return sum; } return sum; } }); return some(seq); }
private static JSONObject toJsonSimple(Obj obj) { return mlist(obj.getProps()).foldl(new JSONObject(), new Function2<JSONObject, Prop, JSONObject>() { @Override public JSONObject apply(JSONObject jo, Prop prop) { jo.put(prop.getName(), toJsonSimple(prop.getVal())); return jo; } }); }
private static JSONArray toJsonSimple(Arr arr) { return mlist(arr.getVals()).foldl(new JSONArray(), new Function2<JSONArray, Val, JSONArray>() { @Override public JSONArray apply(JSONArray ja, Val val) { ja.add(toJsonSimple(val)); return ja; } }); }
/** Concat a tree of incidents into a list. */ public static List<Incident> concat(IncidentTree tree) { return mlist(tree.getDescendants()).foldl( new LinkedList<>(tree.getIncidents()), new Function2<List<Incident>, IncidentTree, List<Incident>>() { @Override public List<Incident> apply(List<Incident> sum, IncidentTree tree) { sum.addAll(concat(tree)); return sum; } }); } }
public Incident toIncident() { return new IncidentImpl(id, jobId, serviceType, processingHost, timestamp, severity, code, mlist(nullToNil(details)).map(JaxbIncidentDetail.toDetailFn).value(), mlist( nullToNil(descriptionParameters)).foldl(new HashMap<>(), new Function2<Map<String, String>, Param, Map<String, String>>() { @Override public Map<String, String> apply(Map<String, String> sum, Param param) { sum.put(param.getName(), param.getValue()); return sum; } })); }