Java Code Examples for org.rapidoid.u.U#list()
The following examples show how to use
org.rapidoid.u.U#list() .
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: Layout.java From rapidoid with Apache License 2.0 | 6 votes |
@Override protected Object render() { List<Tag> rows = U.list(); Tag row = GUI.row().class_("row row-separated"); int n = 0; int colSize = 12 / cols; for (Object item : contents) { n++; if (n == cols + 1) { n = 1; rows.add(row); row = GUI.row().class_("row row-separated"); } row = row.append(GUI.col_(colSize, item)); } if (!row.isEmpty()) { rows.add(row); } return U.arrayOf(Tag.class, rows); }
Example 2
Source File: Cls.java From rapidoid with Apache License 2.0 | 6 votes |
public static List<Method> getMethodsAnnotated(Class<?> clazz, Class<? extends Annotation> annotation) { List<Method> annotatedMethods = U.list(); try { for (Class<?> c = clazz; c.getSuperclass() != null; c = c.getSuperclass()) { Method[] methods = c.getDeclaredMethods(); for (Method method : methods) { if (method.isAnnotationPresent(annotation)) { annotatedMethods.add(method); } } } } catch (Exception e) { throw U.rte("Cannot instantiate class!", e); } return annotatedMethods; }
Example 3
Source File: JSON.java From rapidoid with Apache License 2.0 | 6 votes |
public static synchronized void reset() { for (ObjectMapper mapper : U.list(MAPPER, PRETTY_MAPPER)) { SerializerProvider serializerProvider = mapper.getSerializerProvider(); if (serializerProvider instanceof DefaultSerializerProvider) { DefaultSerializerProvider provider = (DefaultSerializerProvider) serializerProvider; provider.flushCachedSerializers(); } else { Log.warn("Couldn't clear the cache of Jackson serializers!", "class", Cls.of(serializerProvider)); } DeserializationContext deserializationContext = mapper.getDeserializationContext(); Object cache = Cls.getFieldValue(deserializationContext, "_cache"); if (cache instanceof DeserializerCache) { DeserializerCache deserializerCache = (DeserializerCache) cache; deserializerCache.flushCachedDeserializers(); } else { Log.warn("Couldn't clear the cache of Jackson deserializers!", "class", Cls.of(cache)); } } }
Example 4
Source File: Groups.java From rapidoid with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T extends Manageable> List<GroupOf<T>> find(String kind) { List<GroupOf<T>> groups = U.list(); for (GroupOf<?> group : all()) { if (group.kind().equals(kind)) { groups.add((GroupOf<T>) group); } } return groups; }
Example 5
Source File: JPAInjectionTest.java From rapidoid with Apache License 2.0 | 5 votes |
@Page(raw = true) @Transaction public Object del2(long id, Req req) { checkInjected(); U.must(em.getTransaction().getRollbackOnly() == HttpUtils.isGetReq(req)); JPA.delete(Book.class, id); return U.list("DEL #" + id, JPA.getAllEntities().size() + " remaining"); }
Example 6
Source File: AbstractRapidoidMojo.java From rapidoid with Apache License 2.0 | 5 votes |
private String pickMainClass(List<String> mainClasses, MavenProject project) { // the.group.id.Main String byGroupId = project.getGroupId() + ".Main"; if (mainClasses.contains(byGroupId)) return byGroupId; List<String> namedMain = U.list(); List<String> withGroupIdPkg = U.list(); for (String name : mainClasses) { if (name.equals("Main")) return "Main"; if (name.endsWith(".Main")) { namedMain.add(name); } if (name.startsWith(project.getGroupId() + ".")) { withGroupIdPkg.add(name); } } // the.group.id.foo.bar.Main getLog().info("Candidates by group ID: " + withGroupIdPkg); if (withGroupIdPkg.size() == 1) return U.single(withGroupIdPkg); // foo.bar.Main getLog().info("Candidates named Main: " + namedMain); if (namedMain.size() == 1) return U.single(namedMain); namedMain.retainAll(withGroupIdPkg); getLog().info("Candidates by group ID - named Main: " + namedMain); if (namedMain.size() == 1) return U.single(namedMain); // the.group.id.foo.bar.Main (the shortest name) withGroupIdPkg.sort((s1, s2) -> s1.length() - s2.length()); getLog().info("Candidates by group ID - picking one with the shortest name: " + withGroupIdPkg); return U.first(withGroupIdPkg); }
Example 7
Source File: ReverseProxyMapDSL.java From rapidoid with Apache License 2.0 | 5 votes |
private ReverseProxy createReverseProxy() { List<ProxyUpstream> proxyUpstreams = U.list(); U.notNull(upstreams, "proxy upstreams"); for (String upstream : upstreams) { proxyUpstreams.add(new ProxyUpstream(upstream)); } LoadBalancer balancer = loadBalancer != null ? loadBalancer : new RoundRobinLoadBalancer(); ProxyMapping mapping = new ProxyMapping(uriPrefix, balancer, proxyUpstreams); return new ReverseProxy(mapping); }
Example 8
Source File: BeansHandler.java From rapidoid with Apache License 2.0 | 5 votes |
@Override public Object call() { List<Object> routes = U.list(); routes.add(h3("Application context of managed beans:")); routes.add(grid(IoC.defaultContext().info())); return multi(routes); }
Example 9
Source File: RoutesHandler.java From rapidoid with Apache License 2.0 | 5 votes |
@Override public Object call() { List<Object> routes = U.list(); Set<Route> appRoutes = On.setup().routes().allExceptInternal(); Set<Route> internalRoutes = On.setup().routes().allInternal(); internalRoutes.addAll(Admin.setup().routes().allInternal()); routes.add(div(h3("Application routes:"), routesOf(appRoutes, true))); routes.add(div(h3("Internal routes:"), routesOf(internalRoutes, true))); return multi(routes); }
Example 10
Source File: AppDeployMojo.java From rapidoid with Apache License 2.0 | 5 votes |
private List<String> getServers() { String[] srvrs = servers.split("\\s*,\\s*"); for (int i = 0; i < srvrs.length; i++) { String server = Str.trimr(srvrs[i], "/"); if (!server.startsWith("http")) server = "http://" + server; srvrs[i] = server; } return U.list(srvrs); }
Example 11
Source File: AnyObj.java From rapidoid with Apache License 2.0 | 5 votes |
@SafeVarargs public static <T, V extends T> List<T> withoutNulls(V... values) { List<T> list = U.list(); for (T val : values) { if (val != null) { list.add(val); } } return list; }
Example 12
Source File: Groups.java From rapidoid with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T extends Manageable> List<GroupOf<T>> find(Class<? extends T> itemType) { List<GroupOf<T>> groups = U.list(); for (GroupOf<?> group : all()) { if (group.itemType().equals(itemType)) { groups.add((GroupOf<T>) group); } } return groups; }
Example 13
Source File: ConfigOptions.java From rapidoid with Apache License 2.0 | 5 votes |
private static List<ConfigOption> commandOptions() { List<ConfigOption> opts = U.list(); opts.add(cmd("dev", "CLI shortcut for convenient local development setup")); opts.add(cmd("installer", "Print installation script for Rapidoid")); opts.add(cmd("password", "Generate salted password hash")); opts.add(cmd("help", "Show help")); return opts; }
Example 14
Source File: ConfigImpl.java From rapidoid with Apache License 2.0 | 5 votes |
protected synchronized void initialize() { mustBeRoot(); List<String> loaded = U.list(); base.initial.putAll(Env.argsAsMap()); overrideByEnv(); if (useBuiltInDefaults()) { ConfigLoaderUtil.loadBuiltInConfig(this, loaded); } boolean useConfigFiles = U.notEmpty(getFilenameBase()); if (useConfigFiles) { ConfigLoaderUtil.loadConfig(this, loaded); } overrideByEnv(); substitutePlaceholders(); Conf.applyConfig(this); if (!loaded.isEmpty()) { Log.info("Loaded configuration", "namespace", getFilenameBase(), "!files", loaded); } else { if (useConfigFiles) { Log.warn("Didn't find any configuration files", "path", getPath()); } } }
Example 15
Source File: Radios.java From rapidoid with Apache License 2.0 | 5 votes |
@Override protected Object render() { U.notNull(options, "options"); List<Object> radios = U.list(); for (Object opt : options) { boolean checked = initial != null && U.eq(initial, opt); radios.add(GUI.radio().name(_name()).value(opt).checked(checked).label(str(opt))); } return radios; }
Example 16
Source File: IO.java From rapidoid with Apache License 2.0 | 5 votes |
public static List<String> readLines(BufferedReader reader) { List<String> lines = U.list(); try { String line; while ((line = reader.readLine()) != null) { lines.add(line); } } catch (IOException e) { throw U.rte(e); } return lines; }
Example 17
Source File: AbstractValue.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public List<String> list() { String s = str().getOrNull(); return s != null ? U.list(s.split(",")) : U.list(); }
Example 18
Source File: ClasspathScanner.java From rapidoid with Apache License 2.0 | 4 votes |
private static List<String> retrieveClasses(Set<String> classpath, String packageName, Class<? extends Annotation>[] annotated, Predicate<InputStream> bytecodeFilter, Pattern regex, ClassLoader classLoader, AtomicInteger searched) { List<String> classes = U.list(); String pkgName = U.safe(packageName); String pkgPath = pkgName.replace('.', File.separatorChar); Log.trace("Starting classpath scan", "package", packageName, "annotated", annotated, "regex", regex, "loader", classLoader); Log.trace("Classpath details", "classpath", classpath); Set<String> jars = U.set(); for (String cpe : classpath) { File cpEntry = new File(cpe); if (cpEntry.exists()) { if (cpEntry.isDirectory()) { if (shouldScanDir(cpEntry.getAbsolutePath())) { Log.trace("Scanning directory", "root", cpEntry.getAbsolutePath()); File startingDir; if (pkgPath.isEmpty()) { startingDir = cpEntry; } else { startingDir = new File(cpEntry.getAbsolutePath(), pkgPath); } if (startingDir.exists()) { getClassesFromDir(classes, cpEntry, startingDir, pkgName, regex, annotated, bytecodeFilter, searched); } } else { Log.trace("Skipping directory", "root", cpEntry.getAbsolutePath()); } } else if (cpEntry.isFile() && cpEntry.getAbsolutePath().toLowerCase().endsWith(".jar")) { jars.add(cpEntry.getAbsolutePath()); } else { Log.warn("Invalid classpath entry: " + cpe); } } else { if (!cpe.contains("*") && !cpe.contains("?") && U.neq(cpe, ClasspathUtil.appJar())) { Log.warn("Classpath entry doesn't exist: " + cpe); } } } for (String jarName : jars) { if (shouldScanJAR(jarName)) { Log.trace("Scanning JAR", "name", jarName); getClassesFromJAR(jarName, classes, packageName, regex, annotated, bytecodeFilter, classLoader, searched); } else { Log.trace("Skipping JAR", "name", jarName); } } return classes; }
Example 19
Source File: ManageableCache.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public List<String> getManageableProperties() { return U.list("id", "size", "capacity", "requests", "hitRate", "hits", "misses", "bypassed", "errors", "ttl"); }
Example 20
Source File: EchoProtocolTest.java From rapidoid with Apache License 2.0 | 3 votes |
private void connectAndExercise() { NetUtil.connect("localhost", 8080, (F3<Void, InputStream, BufferedReader, DataOutputStream>) (inputStream, in, out) -> { out.writeBytes("hello\n"); eq(in.readLine(), "HELLO"); out.writeBytes("Foo\n"); eq(in.readLine(), "FOO"); out.writeBytes("bye\n"); eq(in.readLine(), "BYE"); return null; }); for (int i = 1; i <= ROUNDS; i++) { Msc.logSection("ROUND " + i); for (final String testCase : testCases) { final List<String> expected = U.list(testCase.toUpperCase().split("\r?\n")); Msc.startMeasure(); NetUtil.connect("localhost", 8080, (F3<Void, InputStream, BufferedReader, DataOutputStream>) (inputStream, in, out) -> { out.writeBytes(testCase); List<String> lines = IO.readLines(in); eq(lines, expected); return null; }); Msc.endMeasure(expected.size(), "messages"); } } }