public static <T, T1> Map<T, T1> where(Map<T, T1> map, JFuncTT<Map.Entry<T, T1>, Boolean> func) { try { Map<T, T1> result = new HashMap<>(); for (Map.Entry<T, T1> el : map.entrySet()) if (func.invoke(el)) result.put(el.getKey(), el.getValue()); return result; } catch (Exception ignore) { return new HashMap<>(); } }
public static <T, T1, T2> Map<T, T2> select(Map<T, T1> map, JFuncTT<T1, T2> func) { try { Map<T, T2> result = new HashMap<>(); for (Map.Entry<T, T1> el : map.entrySet()) result.put(el.getKey(), func.invoke(el.getValue())); return result; } catch (Exception ignore) { return new HashMap<>(); } }
public static <T, T1> T1 first(Map<T, T1> map, JFuncTT<T, Boolean> func) { try { for (Map.Entry<T, T1> el : map.entrySet()) if (func.invoke(el.getKey())) return el.getValue(); } catch (Exception ignore) { } return null; }
public static <T, T1, T2> Collection<T2> selectMap( Map<T, T1> map, JFuncTT<Map.Entry<T, T1>, T2> func) { try { List<T2> result = new ArrayList<>(); for (Map.Entry<T, T1> el : map.entrySet()) result.add(func.invoke(el)); return result; } catch (Exception ignore) { return new ArrayList<>(); } }
public static <T, T1> void foreach(Map<T, T1> map, JActionT<Map.Entry<T, T1>> action) { try { for (Map.Entry<T, T1> entry : map.entrySet()) action.invoke(entry); } catch (Exception ignore) { } }
public static <T, T1> T1 first(Map<T, T1> map) { for (Map.Entry<T, T1> el : map.entrySet()) return el.getValue(); return null; }