Java Code Examples for org.rapidoid.u.U#set()
The following examples show how to use
org.rapidoid.u.U#set() .
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: ClassMetadata.java From rapidoid with Apache License 2.0 | 6 votes |
public static Set<Field> getInjectableFields(Class<?> clazz) { Set<Field> fields = U.set(); for (Class<? extends Annotation> annotation : INJECTION_ANNOTATIONS) { fields.addAll(Cls.getFieldsAnnotated(clazz, annotation)); } if (MscOpts.hasJPA()) { Class<Annotation> javaxPersistenceContext = Cls.get("javax.persistence.PersistenceContext"); List<Field> emFields = Cls.getFieldsAnnotated(clazz, javaxPersistenceContext); for (Field emField : emFields) { U.must(emField.getType().getName().equals("javax.persistence.EntityManager"), "Expected EntityManager type!"); } fields.addAll(emFields); } return fields; }
Example 2
Source File: App.java From rapidoid with Apache License 2.0 | 5 votes |
private static void notifyListenersAfterRestart() { Set<AppRestartListener> listeners = U.set(On.changes().getRestartListeners()); for (AppRestartListener listener : listeners) { try { listener.afterAppRestart(); } catch (Exception e) { Log.error("Error occurred in the app restart listener!", e); } } }
Example 3
Source File: ClassMetadata.java From rapidoid with Apache License 2.0 | 5 votes |
public static Set<Class<?>> getTypesToManage(Class<?> clazz) { Set<Class<?>> types = U.set(); Manage depAnn = Metadata.getAnnotationRecursive(clazz, Manage.class); if (depAnn != null) { Collections.addAll(types, depAnn.value()); } return types; }
Example 4
Source File: ClassMetadata.java From rapidoid with Apache License 2.0 | 5 votes |
private Set<String> getPackagesToScan(Class<?> clazz) { ScanPackages scan = Metadata.getAnnotationRecursive(clazz, ScanPackages.class); if (scan != null) { String[] pkgs = scan.value(); U.must(U.notEmpty(pkgs), "@ScanPackages requires a list of packages to scan!"); return U.set(pkgs); } else { return U.set(); } }
Example 5
Source File: ClassMetadata.java From rapidoid with Apache License 2.0 | 5 votes |
public static Set<Constructor<?>> getInjectableConstructors(Class<?> clazz) { Set<Constructor<?>> constructors = U.set(); for (Constructor<?> constr : clazz.getDeclaredConstructors()) { if (Metadata.hasAny(constr.getAnnotations(), ClassMetadata.INJECTION_ANNOTATIONS)) { constructors.add(constr); } } return constructors; }
Example 6
Source File: GuiceBeans.java From rapidoid with Apache License 2.0 | 5 votes |
private Set<Object> getBeans(Collection<Class<? extends Annotation>> annotations) { Set<Object> beans = U.set(); for (Map.Entry<Key<?>, Binding<?>> e : injector.getAllBindings().entrySet()) { Key<?> key = e.getKey(); Binding<?> value = e.getValue(); boolean include = false; if (U.notEmpty(annotations)) { if (key.getTypeLiteral() != null && key.getTypeLiteral().getRawType() != null) { Class<?> type = key.getTypeLiteral().getRawType(); if (Metadata.isAnnotatedAny(type, annotations)) { include = true; } } } else { include = true; } if (include) { beans.add(value.getProvider().get()); } } return beans; }
Example 7
Source File: CryptoTest.java From rapidoid with Apache License 2.0 | 5 votes |
@Test public void testSpecifiedSecret() { Env.setArgs("secret=mysecret"); String key = Str.toHex(Crypto.getSecretKey().encryptionKey); String key1 = "DCE88CB5E440BC26D371D64E55DBB67832BBB44C2887BEE9C1DF17F88BC1764B"; String key2 = "3CDB902856D13CC88139DD290822DA99E85242F16E575E73ED7953208B88B045"; Set<String> keys = U.set(key1, key2, key1.substring(0, key1.length() / 2), key2.substring(0, key2.length() / 2)); isTrue(keys.contains(key)); }
Example 8
Source File: Msc.java From rapidoid with Apache License 2.0 | 5 votes |
public static String detectZipRoot(InputStream zip) { Set<String> roots = U.set(); try { ZipInputStream zis = new ZipInputStream(zip); ZipEntry ze = zis.getNextEntry(); while (ze != null) { if (ze.isDirectory()) { String fileName = ze.getName(); String parentDir = fileName.split("/|\\\\")[0]; roots.add(parentDir); } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException e) { throw U.rte(e); } return roots.size() == 1 ? U.single(roots) : null; }
Example 9
Source File: Coll.java From rapidoid with Apache License 2.0 | 5 votes |
public static <T> Set<T> copyOf(Set<T> src) { Set<T> copy; synchronized (src) { copy = U.set(src); } return copy; }
Example 10
Source File: Secure.java From rapidoid with Apache License 2.0 | 5 votes |
public static Set<String> getRolesAllowed(Map<Class<?>, Annotation> annotations) { Set<String> roles = U.set(); for (Map.Entry<Class<?>, Annotation> e : annotations.entrySet()) { Annotation ann = e.getValue(); Class<? extends Annotation> type = ann.annotationType(); if (type.equals(Administrator.class)) { roles.add(Role.ADMINISTRATOR); } else if (type.equals(Manager.class)) { roles.add(Role.MANAGER); } else if (type.equals(Moderator.class)) { roles.add(Role.MODERATOR); } else if (type.equals(LoggedIn.class)) { roles.add(Role.LOGGED_IN); } else if (type.equals(Roles.class)) { String[] values = ((Roles) ann).value(); U.must(values.length > 0, "At least one role must be specified in @Roles annotation!"); for (String r : values) { roles.add(r.toLowerCase()); } } } return roles; }
Example 11
Source File: ConfigImpl.java From rapidoid with Apache License 2.0 | 5 votes |
private void substitutePlaceholders() { Map<String, String> flat = toFlatMap(); Set<String> changedKeys = U.set(); for (int i = 0; i < 1000; i++) { if (!substitutePlaceholders(flat, changedKeys)) { break; } } for (String key : changedKeys) { set(key, flat.get(key)); } }
Example 12
Source File: Cls.java From rapidoid with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static <T> T newInstance(Class<T> clazz) { Err.argMust(clazz != AutoExpandingMap.class, "Cannot instantiate AutoExpandingMap!"); if (clazz == List.class) { return (T) U.list(); } else if (clazz == Set.class) { return (T) U.set(); } else if (clazz == Map.class) { return (T) U.map(); } else if (clazz == ConcurrentMap.class) { return (T) Coll.concurrentMap(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedSet")) { return (T) Coll.synchronizedSet(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedList")) { return (T) Coll.synchronizedList(); } else if (clazz.getName().equals("java.util.Collections$SynchronizedMap")) { return (T) Coll.synchronizedMap(); } else if (clazz == Var.class) { return (T) Vars.var("<new>", null); } else if (clazz == Object.class) { return (T) new Object(); } return newBeanInstance(clazz); }
Example 13
Source File: App.java From rapidoid with Apache License 2.0 | 5 votes |
private static void notifyListenersBeforeRestart() { Set<AppRestartListener> listeners = U.set(On.changes().getRestartListeners()); for (AppRestartListener listener : listeners) { try { listener.beforeAppRestart(); } catch (Exception e) { Log.error("Error occurred in the app restart listener!", e); } } }
Example 14
Source File: ClasspathUtil.java From rapidoid with Apache License 2.0 | 5 votes |
public static synchronized Set<String> getClasspathJars() { Set<String> jars = U.set(); Set<String> cps = ClasspathUtil.getClasspath(); for (String cp : cps) { if (new File(cp).isFile() && cp.substring(cp.length() - 4).equalsIgnoreCase(".JAR")) { jars.add(cp); } } return jars; }
Example 15
Source File: ClasspathUtil.java From rapidoid with Apache License 2.0 | 5 votes |
public static synchronized Set<String> getClasspathFolders() { Set<String> folders = U.set(); Set<String> cps = ClasspathUtil.getClasspath(); for (String cp : cps) { if (new File(cp).isDirectory()) { folders.add(cp); } } return folders; }
Example 16
Source File: ClasspathScanner.java From rapidoid with Apache License 2.0 | 5 votes |
private static List<String> scanClasses(ScanParams params) { String[] pkgs = params.in(); String rootPackage = ClasspathUtil.getRootPackage(); if (U.isEmpty(pkgs)) { pkgs = rootPackage != null ? new String[]{rootPackage} : new String[]{""}; } long startingAt = U.time(); String regex = params.matching(); Pattern pattern = U.notEmpty(regex) ? Pattern.compile(regex) : null; if (regex != null) { Log.info("Scanning classpath", "!annotated", Msc.annotations(params.annotated()), "!packages", Arrays.toString(pkgs), "!matching", regex); } else { Log.info("Scanning classpath", "!annotated", Msc.annotations(params.annotated()), "!packages", Arrays.toString(pkgs)); } Set<String> classpath = U.notEmpty(params.classpath()) ? U.set(params.classpath()) : ClasspathUtil.getClasspath(); AtomicInteger searched = new AtomicInteger(); Set<String> classes = U.set(); for (String pkg : pkgs) { classes.addAll(retrieveClasses(classpath, pkg, params.annotated(), params.bytecodeFilter(), pattern, params.classLoader(), searched)); } List<String> classList = U.list(classes); long timeMs = U.time() - startingAt; Log.info("Finished classpath scan", "time", Msc.maybeMasked(timeMs) + "ms", "searched", searched.get(), "!found", Msc.classNames(classList)); return classList; }
Example 17
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 18
Source File: HttpRoutesImpl.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public Set<Route> allExceptInternal() { return U.set(Do.findIn(all()).all(route -> !route.isInternal())); }
Example 19
Source File: PropertyFilter.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public Set<String> exclude() { return U.set(); }
Example 20
Source File: PropertyFilter.java From rapidoid with Apache License 2.0 | 4 votes |
@Override public Set<String> include() { return U.set(); }