List of usage examples for java.util Collection addAll
boolean addAll(Collection<? extends E> c);
From source file:com.blurengine.blur.framework.ticking.TickMethodsCache.java
/** * Loads and caches a {@link Class}//from w ww . j ava 2s . c o m * * @param clazz class to load and cache for future usage * * @return list of {@link TickMethod} represented the cached methods * * @throws IllegalArgumentException thrown if {@code clazz} is {@code Tickable.class} */ public static Collection<TickMethod> loadClass(@Nonnull Class<?> clazz) throws IllegalArgumentException { Preconditions.checkNotNull(clazz, "clazz cannot be null."); if (!LOADED_CLASSES.contains(clazz)) { Collection<TickMethod> tickMethods = CLASS_TICK_METHODS.get(clazz); // empty cache list, automatically updates { // Load superclasses first Class<?> superclass = clazz.getSuperclass(); // No need for while loop as loadClass will end up reaching here if necessary. if (!superclass.equals(Object.class)) { tickMethods.addAll(loadClass(superclass)); } } for (Method method : clazz.getDeclaredMethods()) { TickMethod tickMethod = getTickMethod(clazz, method); if (tickMethod != null) { tickMethods.add(tickMethod); } else { Tick tick = method.getDeclaredAnnotation(Tick.class); if (tick != null) { try { Preconditions.checkArgument(method.getParameterCount() <= 1, "too many parameters in tick method " + method.getName() + "."); if (method.getParameterCount() > 0) { Preconditions.checkArgument( method.getParameterTypes()[0].isAssignableFrom(TickerTask.class), "Invalid parameter in tick method " + method.getName() + "."); } boolean passParams = method.getParameterCount() > 0; // Tickables may be marked private for organisation. method.setAccessible(true); tickMethods.add(new TickMethod(method, passParams, tick)); } catch (Exception e) { e.printStackTrace(); } } } } LOADED_CLASSES.add(clazz); } return Collections.unmodifiableCollection(CLASS_TICK_METHODS.get(clazz)); }
From source file:com.bluexml.side.form.clazz.utils.ClassDiagramUtils.java
/** * Return inherited Clazzs from a class/*w ww. j a v a 2s . c o m*/ * * @param cl * @return */ public static Collection<AbstractClass> getInheritedClazzs(AbstractClass cl) { Collection<AbstractClass> listClazz = new ArrayList<AbstractClass>(); listClazz.add(cl); listClazz.addAll(cl.getInheritedClasses()); return listClazz; }
From source file:delfos.dataset.util.DatasetPrinter.java
public static String printCompactRatingTable(Map<Integer, Map<Integer, Number>> ratings, Collection<Integer> users, Collection<Integer> items) { Map<Integer, Map<Integer, Rating>> ratings_r = new TreeMap<>(); for (int idUser : ratings.keySet()) { items.addAll(ratings.get(idUser).keySet()); ratings_r.put(idUser, new TreeMap<>()); for (Map.Entry<Integer, Number> entry : ratings.get(idUser).entrySet()) { int idItem = entry.getKey(); Number ratingValue = entry.getValue(); ratings_r.get(idUser).put(idItem, new Rating(idUser, idItem, ratingValue)); }// w w w . jav a2 s .c o m } return printCompactRatingTable(new BothIndexRatingsDataset<>(ratings_r), users, items); }
From source file:com.samsung.sjs.theorysolver.TheorySolver.java
public static <Constraint, Model> Pair<Model, Collection<Constraint>> minimizeFixingSet( Theory<Constraint, Model> theorySolver, List<Constraint> hardConstraints, List<Constraint> softConstraints, Model model, Collection<Constraint> fixingSet) { System.out.println("MINIMIZING FIXING SET [initial size=" + fixingSet.size() + ']'); int iter = 0; Collection<Constraint> positive = new LinkedHashSet<>(); boolean changed; do {// w w w . ja v a 2 s.c o m ++iter; System.out.println(" --> iteration " + iter + "..."); changed = false; for (Constraint c : fixingSet) { Collection<Constraint> candidate = without(fixingSet, c); positive.addAll(hardConstraints); positive.addAll(softConstraints); positive.removeAll(candidate); Either<Model, Collection<Constraint>> result = theorySolver.check(positive); if (result.left != null) { // it's still a fixing set! changed = true; fixingSet = candidate; model = result.left; break; } } } while (changed); System.out.println("FINISHED MINIMIZING [final size=" + fixingSet.size() + ']'); return Pair.of(model, fixingSet); }
From source file:com.samsung.sjs.theorysolver.TheorySolver.java
public static <Constraint, Model> void enumerateFixingSets(FixingSetFinder<Constraint> fixingSetFinder, Theory<Constraint, Model> theorySolver, Collection<Constraint> hardConstraints, Collection<Constraint> softConstraints, FixingSetListener<Constraint, Model> listener) { Collection<Constraint> constraints = new ArrayList<>(); Collection<Constraint> core = new ArrayList<>(); Collection<Constraint> fixingSet = new LinkedHashSet<>(); for (;;) {//from w w w .j ava 2s . c o m if (fixingSetFinder.currentFixingSet(fixingSet, listener) == FixingSetListener.Action.STOP) { return; } constraints.addAll(hardConstraints); softConstraints.stream().filter(c -> !fixingSet.contains(c)).forEach(constraints::add); Either<Model, Collection<Constraint>> result = theorySolver.check(constraints); if (result.left != null) { if (listener.onFixingSet(result.left, fixingSet) == FixingSetListener.Action.STOP) { return; } fixingSetFinder.addCore( constraints.stream().filter(softConstraints::contains).collect(Collectors.toList())); } else { result.right.stream().filter(softConstraints::contains).forEach(core::add); if (listener.onCore(core) == FixingSetListener.Action.STOP) { return; } assert core.stream().allMatch(c -> !fixingSet.contains(c)); fixingSetFinder.addCore(core); } core.clear(); constraints.clear(); fixingSet.clear(); } }
From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java
/** * ?field,/*from w w w .j ava 2 s. c o m*/ * * @param fields * @param type * @return */ public static Field[] getAllFields(Collection<Field> fields, Class<?> type) { if (Argument.isEmpty(fields)) { fields = new HashSet<Field>(); } for (Field field : type.getDeclaredFields()) { fields.add(field); } if (type.getSuperclass() != null) { fields.addAll(Arrays.asList(getAllFields(fields, type.getSuperclass()))); } return fields.toArray(new Field[fields.size()]); }
From source file:com.google.code.guice.repository.spi.TypeUtil.java
public static void getGenericInterfacesActualTypes(Collection<Type> types, Class aClass) { if (aClass != null && types != null) { Type[] interfaces = aClass.getGenericInterfaces(); for (Type anInterface : interfaces) { if (anInterface instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) anInterface; Type[] actualTypes = parameterizedType.getActualTypeArguments(); types.addAll(Arrays.asList(actualTypes)); } else if (anInterface instanceof Class) { Class typeClass = (Class) anInterface; getGenericInterfacesActualTypes(types, typeClass); }// w ww .j a v a 2s. c om } } }
From source file:com.samsung.sjs.theorysolver.TheorySolver.java
/** * Given a fixing set finder, a solver for some particular theory, and some constraints, * this procedure either finds a model or it finds a minimum set of constraints * which, if broken, make the system satisfiable (a "fixing set"). * * <p>A <em>theory</em> is a solver that solves simple conjunctions of constraints. * The performance of this algorithm highly depends on the ability of the theory to * produce small unsatisfiable cores./*w w w .j a va 2s. co m*/ * * @param <Constraint> the type of constraint solved by the theory * @param <Model> the type of model produced by the theory * @param theorySolver a solver for some theory * @param fixingSetFinder a strategy for finding a fixing set * @param hardConstraints the hard constraints which MUST be satisfied * @param softConstraints the labeled soft constraints from which the fixing set is drawn * @return A pair (m,l) where l is the fixing set (a minimum set of constraints which had * to be weakened to satisfy the system), and m is the resulting model after weakening. * Note that <code>l.isEmpty()</code> means the entire set of constraints is satisfiable. * @see SatSolver * @see Theory */ public static <Constraint, Model> Pair<Model, Collection<Constraint>> solve( Theory<Constraint, Model> theorySolver, FixingSetFinder<Constraint> fixingSetFinder, List<Constraint> hardConstraints, List<Constraint> softConstraints) { FixingSetListener<Constraint, Model> listener = NOISY ? loggingListener() : FixingSetListener.dummyListener(); fixingSetFinder.setup(softConstraints); // These two are complements of each other: // - fixingSet is the constraints we are going to remove // - positive is the constraints we are going to keep // (i.e. all those not in the fixing set) Collection<Constraint> fixingSet = new ArrayList<>(); Collection<Constraint> positive = new LinkedHashSet<>(); for (;;) { // Be polite---interruptions mean that someone else wants // this thread to stop what it's doing. if (Thread.currentThread().isInterrupted()) { throw new RuntimeException("thread was interrupted"); } positive.addAll(hardConstraints); positive.addAll(softConstraints); positive.removeAll(fixingSet); // Check the proposed fixing set against the theory. Either<Model, Collection<Constraint>> result = timed(() -> theorySolver.check(positive), "CHECKING THEORY"); if (result.right == null) { // The proposed fixing set works! We are done! if (NOISY) System.out.println("VALID MODEL"); listener.onFixingSet(result.left, fixingSet); return Pair.of(result.left, fixingSet); } else { // The proposed fixing set didn't work. We will use the core // to adjust what fixing set gets returned next. // Inform the listener listener.onCore(result.right); // The fixing set finder shouldn't care about hard constraints Collection<Constraint> softCore = result.right.stream().filter(c -> !hardConstraints.contains(c)) .collect(Collectors.toList()); if (softCore.isEmpty()) { throw new IllegalStateException("Hard clauses are unsat!"); } // Push the core to the fixing set finder fixingSet.clear(); fixingSetFinder.addCore(softCore); timed(() -> fixingSetFinder.currentFixingSet(fixingSet, listener), "FINDING FIXING SET"); System.out.println(" --> PROPOSAL SIZE = " + fixingSet.size()); } } }
From source file:de.xwic.appkit.core.util.CollectionUtil.java
/** * @param where collection to clear and add to * @param fromWhere what to add//from w w w. j av a 2 s. c om * @throws NullPointerException if <code>where</code> is empty */ public static <E> void clearAndAddAll(final Collection<? super E> where, final Collection<? extends E> fromWhere) throws NullPointerException { if (where == fromWhere) { return; } where.clear(); if (!isEmpty(fromWhere)) { where.addAll(fromWhere); } }
From source file:marytts.features.FeatureRegistry.java
public static Collection<Locale> getSupportedLocales() { Collection<Locale> locales = new TreeSet<Locale>(new Comparator<Locale>() { public int compare(Locale o1, Locale o2) { if (o1 == null) { if (o2 == null) return 0; return -1; }//from ww w .ja v a 2 s . co m if (o2 == null) { return 1; } return o1.toString().compareTo(o2.toString()); } }); locales.addAll(managersByLocale.keySet()); return locales; }