@Test public void testSearchAll() { Map<String, Object> all = mapping.searchAll(3, "*s*", Object.class); assertTrue(all.size() == 32); Map<String, Integer> allInt = mapping.searchAll(3, "*s*", Integer.class); assertTrue(allInt.size() == 21); }
public <T> Map<String, T> searchAll(S source, String pattern, Class<T> tclass) { LinkedHashMap<String, T> list = new LinkedHashMap<>(); WildCards wc = new WildCards(pattern); synchronized (this) { for (Entry<String, TFunction<S, ?>> x : map.entrySet()) { if (wc.match(x.getKey())) { TFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { list.put(x.getKey(), (T) fn.extractor.apply(source)); } } } for (Entry<String, TListFunction<S, ?>> x : lmap.entrySet()) { TListFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { for (int i = fn.start; i <= fn.end; ++i) { String key = listKey(x.getKey(), i); if (wc.match(key)) { list.put(key, (T) fn.extractor.apply(source, i)); } } } } } return list; }
InformationMapping { public <T> Map<String, T> searchAll(S source, String pattern, Class<T> tclass) { LinkedHashMap<String, T> list = new LinkedHashMap<>(); WildCards wc = new WildCards(pattern); synchronized (this) { for (Entry<String, TFunction<S, ?>> x : map.entrySet()) { if (wc.match(x.getKey())) { TFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { list.put(x.getKey(), (T) fn.extractor.apply(source)); } } } for (Entry<String, TListFunction<S, ?>> x : lmap.entrySet()) { TListFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { for (int i = fn.start; i <= fn.end; ++i) { String key = listKey(x.getKey(), i); if (wc.match(key)) { list.put(key, (T) fn.extractor.apply(source, i)); } } } } } return list; } }
InformationMapping { public <T> Map<String, T> searchAll(S source, String pattern, Class<T> tclass) { LinkedHashMap<String, T> list = new LinkedHashMap<>(); WildCards wc = new WildCards(pattern); synchronized (this) { for (Entry<String, TFunction<S, ?>> x : map.entrySet()) { if (wc.match(x.getKey())) { TFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { list.put(x.getKey(), (T) fn.extractor.apply(source)); } } } for (Entry<String, TListFunction<S, ?>> x : lmap.entrySet()) { TListFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { for (int i = fn.start; i <= fn.end; ++i) { String key = listKey(x.getKey(), i); if (wc.match(key)) { list.put(key, (T) fn.extractor.apply(source, i)); } } } } } return list; } InformationMapping(Class<S> sourceClass); }
InformationMapping { public <T> Map<String, T> searchAll(S source, String pattern, Class<T> tclass) { LinkedHashMap<String, T> list = new LinkedHashMap<>(); WildCards wc = new WildCards(pattern); synchronized (this) { for (Entry<String, TFunction<S, ?>> x : map.entrySet()) { if (wc.match(x.getKey())) { TFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { list.put(x.getKey(), (T) fn.extractor.apply(source)); } } } for (Entry<String, TListFunction<S, ?>> x : lmap.entrySet()) { TListFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { for (int i = fn.start; i <= fn.end; ++i) { String key = listKey(x.getKey(), i); if (wc.match(key)) { list.put(key, (T) fn.extractor.apply(source, i)); } } } } } return list; } InformationMapping(Class<S> sourceClass); static String listKey(String prefix, int item); static String wcKey(String prefix, char wc); static int listItem(String prefix, String key); static boolean isIParamItem(String prefix, String key); static void updateAll(ClassLoader loader); static boolean update(Class sourceClass, ClassLoader loader); void update(); void update(ClassLoader loader); void set(String name, Class<T> tclass, Function<S, T> extractor); void set(String name, Function<S, TsData> extractor); void setList(String prefix, int start, int end, Class<T> tclass, BiFunction<S, Integer, T> extractor); void setList(String prefix, int start, int end, BiFunction<S, Integer, TsData> extractor); void set(String prefix, int defparam, Class<T> tclass, BiFunction<S, Integer, T> extractor); void set(String prefix, int defparam, BiFunction<S, Integer, TsData> extractor); void fillDictionary(String prefix, Map<String, Class> dic, boolean compact); String[] keys(); boolean contains(String id); T getData(S source, String id, Class<T> tclass); Map<String, T> searchAll(S source, String pattern, Class<T> tclass); }
InformationMapping { public <T> Map<String, T> searchAll(S source, String pattern, Class<T> tclass) { LinkedHashMap<String, T> list = new LinkedHashMap<>(); WildCards wc = new WildCards(pattern); synchronized (this) { for (Entry<String, TFunction<S, ?>> x : map.entrySet()) { if (wc.match(x.getKey())) { TFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { list.put(x.getKey(), (T) fn.extractor.apply(source)); } } } for (Entry<String, TListFunction<S, ?>> x : lmap.entrySet()) { TListFunction<S, ?> fn = x.getValue(); if (tclass.isAssignableFrom(fn.targetClass)) { for (int i = fn.start; i <= fn.end; ++i) { String key = listKey(x.getKey(), i); if (wc.match(key)) { list.put(key, (T) fn.extractor.apply(source, i)); } } } } } return list; } InformationMapping(Class<S> sourceClass); static String listKey(String prefix, int item); static String wcKey(String prefix, char wc); static int listItem(String prefix, String key); static boolean isIParamItem(String prefix, String key); static void updateAll(ClassLoader loader); static boolean update(Class sourceClass, ClassLoader loader); void update(); void update(ClassLoader loader); void set(String name, Class<T> tclass, Function<S, T> extractor); void set(String name, Function<S, TsData> extractor); void setList(String prefix, int start, int end, Class<T> tclass, BiFunction<S, Integer, T> extractor); void setList(String prefix, int start, int end, BiFunction<S, Integer, TsData> extractor); void set(String prefix, int defparam, Class<T> tclass, BiFunction<S, Integer, T> extractor); void set(String prefix, int defparam, BiFunction<S, Integer, TsData> extractor); void fillDictionary(String prefix, Map<String, Class> dic, boolean compact); String[] keys(); boolean contains(String id); T getData(S source, String id, Class<T> tclass); Map<String, T> searchAll(S source, String pattern, Class<T> tclass); static final String LSTART; }