Java Code Examples for org.osgl.util.C#newList()

The following examples show how to use org.osgl.util.C#newList() . 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: FibonacciSeriesLoader.java    From java-di with Apache License 2.0 6 votes vote down vote up
@Override
public List<Integer> load(Map<String, Object> options, BeanSpec container, Genie genie) {
    int max = toInt(options.get("max"));
    int n1 = 1, n2 = 1, f;
    List<Integer> list = C.newList();
    list.add(n1);
    list.add(n2);
    for (;;) {
        f = n1 + n2;
        n1 = n2;
        n2 = f;
        if (f < max) {
            list.add(f);
        } else {
            break;
        }
    }
    return list;
}
 
Example 2
Source File: TypedClasses.java    From java-di with Apache License 2.0 6 votes vote down vote up
@Provides
public static TypedElementLoader typedElementLoader() {
    return new TypedElementLoader() {
        @Override
        protected List<Class> load(Class type, boolean loadNonPublic, boolean loadAbstract, boolean loadRoot) {
            if (type == Base.class) {
                List<Class> list = (List) C.newList(Derived.class);
                if (loadNonPublic) {
                    list.add(NonPublicDerived.class);
                }
                if (loadAbstract) {
                    list.add(AbstractDerived.class);
                }
                if (loadRoot) {
                    list.add(Base.class);
                }
                return list;
            }
            return C.list();
        }
    };
}
 
Example 3
Source File: Book.java    From act-doc with Apache License 2.0 6 votes vote down vote up
public void process() {
    List<String> lines = new ArrayList<>();
    for (String chapter : processor.chapters()) {
        File src = new File(base, chapter);
        List<String> fileLines = IO.readLines(src);
        C.List<String> processedFileLines = C.newList();
        for (String line : fileLines) {
            if ("[返回目录](index.md)".equals(line.trim())) {
                continue;
            }
            line = processor.processTag(line);
            processedFileLines.add(line);
        }
        if (!lines.isEmpty()) {
            processedFileLines.add("\\newpage");
        }
        lines.addAll(processedFileLines);
    }
    File target = new File(processor.workspace(), "act_doc-" + lang + ".md");
    IO.write(S.join(lines).by("\n").get()).to(target);
}
 
Example 4
Source File: EventBus.java    From actframework with Apache License 2.0 6 votes vote down vote up
private static Set<List<Class>> permutationOf(List<List<Class>> candidates, int workingColumnId) {
    if (workingColumnId == 0) {
        Set<List<Class>> permutations = new HashSet<>();
        for (Class c : candidates.get(0)) {
            permutations.add(C.newList(c));
        }
        return permutations;
    } else {
        Set<List<Class>> prefixPermutations = permutationOf(candidates, workingColumnId - 1);
        List<Class> currentCandidates = candidates.get(workingColumnId);
        Set<List<Class>> retSet = new HashSet<>();
        for (List<Class> argList : prefixPermutations) {
            for (Class type : currentCandidates) {
                List<Class> merged = C.newList(argList);
                merged.add(type);
                retSet.add(merged);
            }
        }
        return retSet;
    }
}
 
Example 5
Source File: EndpointTester.java    From actframework with Apache License 2.0 6 votes vote down vote up
protected Map<String, Object> prepareJsonData(List<$.T2<String, Object>> params) {
    Map<String, Object> map = C.newMap();
    if (null != params) {
        for ($.T2<String, Object> pair : params) {
            String key = pair._1;
            Object val = pair._2;
            if (map.containsKey(key)) {
                List list;
                Object x = map.get(key);
                if (x instanceof List) {
                    list = $.cast(x);
                } else {
                    list = C.newList(x);
                    map.put(key, list);
                }
                list.add(val);
            } else {
                map.put(key, val);
            }
        }
    }
    return map;
}
 
Example 6
Source File: Zen.java    From actframework with Apache License 2.0 6 votes vote down vote up
private static List<String> loadWords() {
    URL url = Act.getResource("act_zen.txt");
    List<String> words = C.newList(defaultWords());
    if (null != url) {
        try {
            List<String> myWords = IO.readLines(url.openStream());
            if (!myWords.isEmpty()) {
                words = myWords;
            }
        } catch (Exception e) {
            // ignore it
        }
    }
    List<String> retVal = new ArrayList<>(words.size());
    for (String s : words) {
        if (s.contains("\n")) {
            s = s.replaceAll("\n", "\n          ");
        } else if (s.contains("\\n")) {
            s = s.replaceAll("\\\\n", "\n          ");
        }
        retVal.add(s);
    }
    return retVal;
}
 
Example 7
Source File: ElementLoaderProvider.java    From java-di with Apache License 2.0 5 votes vote down vote up
private static C.List<FilterInfo> filters(Genie genie, BeanSpec spec) {
    C.List<FilterInfo> list = C.newList();
    Set<Annotation> annotations = spec.filters();
    for (Annotation anno : annotations) {
        Class<? extends Annotation> annoClass = anno.annotationType();
        Filter filterTag = (Filter.class == annoClass) ? (Filter) anno : annoClass.getAnnotation(Filter.class);
        ElementFilter loader = genie.get(filterTag.value());
        list.add(new FilterInfo(loader, filterTag.reverse(), anno, spec));
    }
    return list;
}
 
Example 8
Source File: RandomListLoader.java    From java-di with Apache License 2.0 5 votes vote down vote up
@Override
public List<Integer> get() {
    List<Integer> list = C.newList();
    for (int i = 0; i < 10; ++i) {
        list.add(N.randInt(100));
    }
    return list;
}
 
Example 9
Source File: TestIssue1.java    From java-tool with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    List<Foo> foos = C.newList();
    foos.add(new Bar());
    foos.add(new Zee());

    C.List<Foo> l = C.list(foos);
    yes(l.size() == 2);
    yes(l.is(C.Feature.READONLY));
}
 
Example 10
Source File: AppNameInferer.java    From actframework with Apache License 2.0 5 votes vote down vote up
private static List<String> tokenOf(Class<?> entryClass) {
    C.List<String> tokens = C.newList();
    tokens.addAll(classNameTokensReversed(entryClass));
    Class<?> enclosingClass = entryClass.getEnclosingClass();
    while (null != enclosingClass) {
        tokens.addAll(classNameTokensReversed(enclosingClass));
        enclosingClass = entryClass.getEnclosingClass();
    }
    String pkgName = JavaNames.packageNameOf(entryClass);
    tokens.append(S.fastSplit(pkgName, ".").reverse());
    return tokens.reverse();
}
 
Example 11
Source File: CSRFTest.java    From actframework with Apache License 2.0 5 votes vote down vote up
public List<Cookie> retrieveCsrfToken($.Var<String> csrf) throws IOException {
    url("/csrf");
    List<Cookie> cookies = cookies();
    List<Cookie> returnCookies = C.newList();
    for (Cookie cookie : cookies) {
        if ("xsrf-token".equalsIgnoreCase(cookie.name())) {
            csrf.set(cookie.value());
        } else {
            returnCookies.add(cookie);
        }
    }
    return returnCookies;
}
 
Example 12
Source File: GeneralAnnoInfo.java    From actframework with Apache License 2.0 5 votes vote down vote up
public void putListAttribute(String name, Object val) {
    List<Object> vals = listAttributes.get(name);
    if (null == vals) {
        vals = C.newList(val);
        listAttributes.put(name, vals);
    } else {
        vals.add(val);
    }
}
 
Example 13
Source File: CliDispatcher.java    From actframework with Apache License 2.0 5 votes vote down vote up
private List<String> commands0(boolean sys, boolean app, boolean withShortcut) {
    C.List<String> list = C.newList();
    Act.Mode mode = Act.mode();
    boolean all = !sys && !app;
    for (Keyword keyword : registry.keySet()) {
        String s = rawNameRepo.get(keyword);
        boolean isSysCmd = s.startsWith("act.");
        if (isSysCmd && !sys && !all) {
            continue;
        }
        if (!isSysCmd && !app && !all) {
            continue;
        }
        CliHandler h = registry.get(keyword);
        if (h.appliedIn(mode)) {
            if (withShortcut) {
                List<String> shortcuts = shortCuts(h);
                if (null != shortcuts && !shortcuts.isEmpty()) {
                    s = s + " | " + shortcuts.get(0);
                }
            }
            list.add(s);
        }
    }
    return list.sorted(new $.Comparator<String>() {
        @Override
        public int compare(String o1, String o2) {
            boolean b1 = (o1.startsWith("act."));
            boolean b2 = (o2.startsWith("act."));
            if (b1 & !b2) {
                return -1;
            }
            if (!b1 & b2) {
                return 1;
            }
            return o1.compareTo(o2);
        }
    });
}
 
Example 14
Source File: WrappedIterableTest.java    From actframework with Apache License 2.0 5 votes vote down vote up
static public void main(String[] args) throws Exception {
    System.out.println(System.getenv("TERM"));

    List<Integer> sizedColl = C.newList();
    for (int i = 0; i < 10000; ++i) {
        sizedColl.add(i);
    }

    for (Integer x : ProgressBar.wrap(sizedColl, "Traverse")) {
        Thread.sleep(2);
    }
}
 
Example 15
Source File: PropertyTest.java    From java-tool with Apache License 2.0 4 votes vote down vote up
public void addBar(Bar bar) {
    if (barList == null) {
        barList = C.newList();
    }
    barList.add(bar);
}
 
Example 16
Source File: SimpleTreeNode.java    From actframework with Apache License 2.0 4 votes vote down vote up
public SimpleTreeNode(String id, String label, List<TreeNode> children) {
    this.id = id;
    this.label = label;
    this.children = null == children ? C.<TreeNode>newList() : C.newList(children);
}
 
Example 17
Source File: SimpleTreeNode.java    From actframework with Apache License 2.0 4 votes vote down vote up
public SimpleTreeNode(String id, String label) {
    this(id, label, C.<TreeNode>newList());
}
 
Example 18
Source File: DaoBase.java    From actframework with Apache License 2.0 4 votes vote down vote up
@Override
public List<MODEL_TYPE> findAllAsList() {
    return C.newList(findAll());
}
 
Example 19
Source File: CatchMethodMetaInfo.java    From actframework with Apache License 2.0 4 votes vote down vote up
public CatchMethodMetaInfo exceptionClasses(List<String> list) {
    targetExceptionClassNames = C.newList(list);
    return this;
}
 
Example 20
Source File: OsglListProvider.java    From java-di with Apache License 2.0 4 votes vote down vote up
@Override
public C.List<?> get() {
    return C.newList();
}