Java Code Examples for org.osgl.util.S#Pair

The following examples show how to use org.osgl.util.S#Pair . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 6 votes vote down vote up
private List<S.Pair> propertyListOf(Class<?> c, Set<Class<?>> circularReferenceDetector, Map<String, Class> typeImplLookup) {
    if (null == typeImplLookup) {
        typeImplLookup = Generics.buildTypeParamImplLookup(c);
    } else {
        typeImplLookup.putAll(Generics.buildTypeParamImplLookup(c));
    }
    if (circularReferenceDetector.contains(c)) {
        return C.list();
    }
    circularReferenceDetector.add(c);
    try {
        return buildPropertyList(c, circularReferenceDetector, typeImplLookup);
    } finally {
        circularReferenceDetector.remove(c);
    }
}
 
Example 2
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 6 votes vote down vote up
private List<S.Pair> buildPropertyList(Class c, Set<Class<?>> circularReferenceDetector, Map<String, Class> typeImplLookup) {
    Method[] ma = c.getMethods();
    String context = "";
    List<S.Pair> retLst = new ArrayList<>();
    for (Method m: ma) {
        buildPropertyPath(context, m, c, retLst, circularReferenceDetector, typeImplLookup);
    }
    List<Field> fa = $.fieldsOf(c);
    for (Field f: fa) {
        int mod = f.getModifiers();
        if (Modifier.isTransient(mod) || !Modifier.isPublic(mod)) {
            continue;
        }
        buildPropertyPath(context, f, retLst, circularReferenceDetector, typeImplLookup);
    }
    Collections.sort(retLst, pairComp);
    return retLst;
}
 
Example 3
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 6 votes vote down vote up
private void buildPropertyPath(String context, Method m, Class<?> c, List<S.Pair> repo, Set<Class<?>> circularReferenceDetector, Map<String, Class> typeImplLookup) {
    if (Modifier.isStatic(m.getModifiers())) {
        return;
    }
    if (m.getParameterTypes().length > 0) {
        return;
    }
    String name = m.getName();
    if ("getClass".equals(name)) {
        return;
    }
    String propName = "";
    if (name.startsWith("get")) {
        propName = getPropName(name);
    } else if (name.startsWith("is")) {
        propName = isPropName(name);
    }
    if (S.isEmpty(propName)) {
        return;
    }
    Class returnType = Generics.getReturnType(m, c);
    Label label = m.getAnnotation(Label.class);
    String labelString = null == label ? null : label.value();
    buildPropertyPath(returnType, m.getGenericReturnType(), labelString, context, propName, repo, circularReferenceDetector, typeImplLookup);
}
 
Example 4
Source File: FastJsonPropertyPreFilterTest.java    From actframework with Apache License 2.0 6 votes vote down vote up
@Before
public void prepare() throws Exception {
    super.setup();
    filter = new FastJsonPropertyPreFilter();
    Zee zee = new Zee("zee", false);
    Zee zee2 = new Zee("zee2", true);
    Bar bar = new Bar("bar", 5, zee);
    Bar bar1 = new Bar("bar1", 4, zee2);
    Bar bar2 = new Bar("bar2", 3, null);
    foo = new Foo("foo", bar);
    foo2 = new Foo("foo2", bar, bar1, bar2);
    JsonUtilConfig.configure(mockApp);
    repo = new DataPropertyRepository(mockApp);
    fooProps = repo.propertyListOf(Foo.class);
    List<String> ls = new ArrayList<>();
    for (S.Pair pair : fooProps) {
        ls.add(pair._1);
    }
    filter.setFullPaths(ls);
}
 
Example 5
Source File: OutputFieldsCache.java    From actframework with Apache License 2.0 5 votes vote down vote up
public List<S.Pair> getOutputFields(PropertySpec.MetaInfo spec, Class<?> componentClass, Object firstElement, ActContext context) {
    K k = new K(spec.excludedFields(context), spec.outputFieldsAndLabel(context), componentClass);
    List<S.Pair> outputs = cache.get(k);
    if (null == outputs) {
        outputs = calculateOutputs(k, firstElement);
        cache.put(k, outputs);
    }
    return outputs;
}
 
Example 6
Source File: OutputFieldsCache.java    From actframework with Apache License 2.0 5 votes vote down vote up
private boolean hasPattern2(Collection<S.Pair> ls, List<StringOrPattern> lsp) {
    boolean b = false;
    for (S.Pair pair: ls) {
        StringOrPattern sp = new StringOrPattern(pair._1);
        b = b || sp.isPattern();
        lsp.add(sp);
    }
    return b;
}
 
Example 7
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the complete property list of a class
 * @param c the class
 * @return the property list of the class
 */
public synchronized List<S.Pair> propertyListOf(Class<?> c) {
    String cn = c.getName();
    List<S.Pair> ls = repo.get(cn);
    if (ls != null) {
        return ls;
    }
    Set<Class<?>> circularReferenceDetector = new HashSet<>();
    ls = propertyListOf(c, circularReferenceDetector, null);
    repo.put(c.getName(), ls);
    return ls;
}
 
Example 8
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 5 votes vote down vote up
public static List<String> getFields(List<S.Pair> fieldsAndLabels) {
    List<String> l = new ArrayList<>(fieldsAndLabels.size());
    for (S.Pair pair : fieldsAndLabels) {
        l.add(pair._1);
    }
    return l;
}
 
Example 9
Source File: FastJsonPropertyPreFilter.java    From actframework with Apache License 2.0 5 votes vote down vote up
private List<String> fromPairs(List<S.Pair> pairs) {
    List<String> list = new ArrayList<>();
    for (S.Pair pair : pairs) {
        list.add(pair._1);
    }
    return list;
}
 
Example 10
Source File: DataPropertyRepositoryTest.java    From actframework with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    List<S.Pair> ls = repo.propertyListOf(Person.class);
    yes(containsField(ls, "firstName"));
    yes(containsLabel(ls, "First name"));
    yes(containsField(ls, "lastName"));
    no(containsLabel(ls, "Last name"));
    yes(containsField(ls, "age"));
    yes(containsField(ls, "address.streetNo"));
    yes(containsField(ls, "address.streetName"));
    yes(containsField(ls, "address.city"));
}
 
Example 11
Source File: DataPropertyRepositoryTest.java    From actframework with Apache License 2.0 5 votes vote down vote up
private boolean containsLabel(List<S.Pair> pairs, String field) {
    for (S.Pair pair : pairs) {
        if (S.eq(pair._2, field)) {
            return true;
        }
    }
    return false;
}
 
Example 12
Source File: DataPropertyRepositoryTest.java    From actframework with Apache License 2.0 5 votes vote down vote up
private boolean containsField(List<S.Pair> pairs, String field) {
    for (S.Pair pair : pairs) {
        if (S.eq(pair._1, field)) {
            return true;
        }
    }
    return false;
}
 
Example 13
Source File: OutputFieldsCache.java    From actframework with Apache License 2.0 4 votes vote down vote up
K(Set<String> ss, List<S.Pair> ls, Class<?> componentType) {
    excluded = ss;
    outputs = ls;
    this.componentType = componentType;
}
 
Example 14
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 4 votes vote down vote up
public List<S.Pair> outputFields(PropertySpec.MetaInfo spec, Class<?> componentClass, Object firstElement, ActContext context) {
    return outputFieldsCache.getOutputFields(spec, componentClass, firstElement, context);
}
 
Example 15
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public int compare(S.Pair o1, S.Pair o2) {
    return o1._1.compareTo(o2._1);
}
 
Example 16
Source File: DataPropertyRepository.java    From actframework with Apache License 2.0 4 votes vote down vote up
private void buildPropertyPath(String context, Field field, List<S.Pair> repo, Set<Class<?>> circularReferenceDetector, Map<String, Class> typeImplLookup) {
    Label label = field.getAnnotation(Label.class);
    String labelString = null == label ? null : label.value();
    buildPropertyPath(field.getType(), field.getGenericType(), labelString, context, field.getName(), repo, circularReferenceDetector, typeImplLookup);
}