List of usage examples for java.util Collection addAll
boolean addAll(Collection<? extends E> c);
From source file:com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithms.java
private static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, XMLConfiguration config, int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, final StateManager stateManager, ConstraintManager constraintManager, boolean addDefaultCostCalculators, boolean addCoreConstraints) { // map to store constructed modules TypedMap definedClasses = new TypedMap(); // algorithm listeners Set<PrioritizedVRAListener> algorithmListeners = new HashSet<PrioritizedVRAListener>(); // insertion listeners List<InsertionListener> insertionListeners = new ArrayList<InsertionListener>(); //threading//from ww w . j a v a 2s .com final ExecutorService executorService; if (nuOfThreads > 0) { log.debug("setup executor-service with " + nuOfThreads + " threads"); executorService = Executors.newFixedThreadPool(nuOfThreads); algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, new AlgorithmEndsListener() { @Override public void informAlgorithmEnds(VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) { log.debug("shutdown executor-service"); executorService.shutdown(); } })); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread arg0, Throwable arg1) { System.err.println(arg1.toString()); } }); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { if (!executorService.isShutdown()) { System.err.println("shutdowHook shuts down executorService"); executorService.shutdown(); } } }); } else executorService = null; //create fleetmanager final VehicleFleetManager vehicleFleetManager = createFleetManager(vrp); String switchString = config.getString("construction.insertion.allowVehicleSwitch"); final boolean switchAllowed; if (switchString != null) { switchAllowed = Boolean.parseBoolean(switchString); } else switchAllowed = true; ActivityTimeTracker.ActivityPolicy activityPolicy; if (stateManager.timeWindowUpdateIsActivated()) { UpdateVehicleDependentPracticalTimeWindows timeWindowUpdater = new UpdateVehicleDependentPracticalTimeWindows( stateManager, vrp.getTransportCosts(), vrp.getActivityCosts()); timeWindowUpdater .setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() { Map<VehicleTypeKey, Vehicle> uniqueTypes = new HashMap<VehicleTypeKey, Vehicle>(); @Override public Collection<Vehicle> get(VehicleRoute vehicleRoute) { if (uniqueTypes.isEmpty()) { for (Vehicle v : vrp.getVehicles()) { if (!uniqueTypes.containsKey(v.getVehicleTypeIdentifier())) { uniqueTypes.put(v.getVehicleTypeIdentifier(), v); } } } Collection<Vehicle> vehicles = new ArrayList<Vehicle>(); vehicles.addAll(uniqueTypes.values()); return vehicles; } }); stateManager.addStateUpdater(timeWindowUpdater); activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS; } else { activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_ARRIVED; } stateManager.addStateUpdater( new UpdateActivityTimes(vrp.getTransportCosts(), activityPolicy, vrp.getActivityCosts())); stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager, activityPolicy)); final SolutionCostCalculator costCalculator; if (solutionCostCalculator == null) costCalculator = getDefaultCostCalculator(stateManager); else costCalculator = solutionCostCalculator; PrettyAlgorithmBuilder prettyAlgorithmBuilder = PrettyAlgorithmBuilder.newInstance(vrp, vehicleFleetManager, stateManager, constraintManager); if (addCoreConstraints) prettyAlgorithmBuilder.addCoreStateAndConstraintStuff(); //construct initial solution creator final InsertionStrategy initialInsertionStrategy = createInitialSolution(config, vrp, vehicleFleetManager, stateManager, algorithmListeners, definedClasses, executorService, nuOfThreads, costCalculator, constraintManager, addDefaultCostCalculators); if (initialInsertionStrategy != null) prettyAlgorithmBuilder.constructInitialSolutionWith(initialInsertionStrategy, costCalculator); //construct algorithm, i.e. search-strategies and its modules int solutionMemory = config.getInt("strategy.memory"); List<HierarchicalConfiguration> strategyConfigs = config .configurationsAt("strategy.searchStrategies.searchStrategy"); for (HierarchicalConfiguration strategyConfig : strategyConfigs) { String name = getName(strategyConfig); SolutionAcceptor acceptor = getAcceptor(strategyConfig, vrp, algorithmListeners, definedClasses, solutionMemory); SolutionSelector selector = getSelector(strategyConfig, vrp, algorithmListeners, definedClasses); SearchStrategy strategy = new SearchStrategy(name, selector, acceptor, costCalculator); strategy.setName(name); List<HierarchicalConfiguration> modulesConfig = strategyConfig.configurationsAt("modules.module"); for (HierarchicalConfiguration moduleConfig : modulesConfig) { SearchStrategyModule module = buildModule(moduleConfig, vrp, vehicleFleetManager, stateManager, algorithmListeners, definedClasses, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators); strategy.addModule(module); } prettyAlgorithmBuilder.withStrategy(strategy, strategyConfig.getDouble("probability")); } //construct algorithm VehicleRoutingAlgorithm metaAlgorithm = prettyAlgorithmBuilder.build(); int maxIterations = getMaxIterations(config); if (maxIterations > -1) metaAlgorithm.setMaxIterations(maxIterations); //define prematureBreak PrematureAlgorithmTermination prematureAlgorithmTermination = getPrematureTermination(config, algorithmListeners); if (prematureAlgorithmTermination != null) metaAlgorithm.setPrematureAlgorithmTermination(prematureAlgorithmTermination); else { List<HierarchicalConfiguration> terminationCriteria = config .configurationsAt("terminationCriteria.termination"); for (HierarchicalConfiguration terminationConfig : terminationCriteria) { PrematureAlgorithmTermination termination = getTerminationCriterion(terminationConfig, algorithmListeners); if (termination != null) metaAlgorithm.addTerminationCriterion(termination); } } for (PrioritizedVRAListener l : algorithmListeners) { metaAlgorithm.getAlgorithmListeners().add(l); } return metaAlgorithm; }
From source file:org.springmodules.validation.valang.javascript.taglib.ValangValidateTag.java
public int doEndTag() throws JspException { try {//from w w w . ja v a 2s . c o m Collection rules = new ArrayList(); if (commandName != null) { rules.addAll(getRulesForCommand()); } if (bodyContent != null) { rules.addAll(parseRulesFromBodyContent()); } if (rules.size() == 0) { throw new JspException("no valang validation rules were found"); } JspWriter out = pageContext.getOut(); out.write("<script type=\"text/javascript\" id=\""); out.write(commandName + "ValangValidator"); out.write("\">"); translator.writeJavaScriptValangValidator(out, commandName, true, rules, new MessageSourceAccessor( getRequestContext().getWebApplicationContext(), getRequestContext().getLocale())); out.write("</script>"); return EVAL_PAGE; } catch (IOException e) { throw new JspException("Could not write validation rules", e); } }
From source file:com.codecrate.shard.modifier.ModifiableObject.java
public Collection<Modifier> getModifiers() { Collection<Modifier> results = new ArrayList<Modifier>(); for (ModifierContainer container : modifiers.values()) { results.addAll(container.getModifiers()); }/*from w ww . j a v a 2s. com*/ return results; }
From source file:com.opensymphony.webwork.util.classloader.listeners.CompilingListener.java
public void onStop(final File pRepository) { this.pRepository = pRepository; log.debug("resources " + created.size() + " created, " + changed.size() + " changed, " + deleted.size() + " deleted"); boolean reload = false; if (deleted.size() > 0) { for (Iterator it = deleted.iterator(); it.hasNext();) { final File file = (File) it.next(); transactionalStore.remove(ReloadingClassLoader.clazzName(pRepository, file)); }//ww w. j a v a2 s . c o m reload = true; } final Collection compileables = new ArrayList(); compileables.addAll(created); compileables.addAll(changed); final String[] clazzes = new String[compileables.size()]; if (compileables.size() > 0) { int i = 0; for (Iterator it = compileables.iterator(); it.hasNext();) { final File file = (File) it.next(); clazzes[i] = ReloadingClassLoader.clazzName(pRepository, file); //log.debug(clazzes[i]); i++; } compiler.compile(clazzes, reader, transactionalStore, problemHandler); final CompilationProblem[] errors = problemHandler.getErrors(); final CompilationProblem[] warnings = problemHandler.getWarnings(); log.debug(errors.length + " errors, " + warnings.length + " warnings"); if (errors.length > 0) { for (int j = 0; j < clazzes.length; j++) { transactionalStore.remove(clazzes[j]); } } reload = true; } transactionalStore.onStop(); if (reload) { reload(); } }
From source file:hudson.util.CopyOnWriteList.java
public void addAllTo(Collection<? super E> dst) { dst.addAll(core); }
From source file:info.magnolia.beanmerger.BeanMergerBase.java
protected Collection mergeCollections(List<Collection> sources) { try {/*from w ww . j a va 2 s . co m*/ Collection mergedCol = sources.get(0).getClass().newInstance(); for (Collection col : sources) { mergedCol.addAll(col); } return mergedCol; } catch (Exception e) { log.error("", e); return sources.get(0); } }
From source file:org.eclipse.winery.repository.Utils.java
public static String getAllXSDefinitionsForTypeAheadSelection(short type) { SortedSet<XSDImportId> allImports = Repository.INSTANCE.getAllTOSCAComponentIds(XSDImportId.class); Map<Namespace, Collection<String>> data = new HashMap<>(); for (XSDImportId id : allImports) { XSDImportResource resource = new XSDImportResource(id); Collection<String> allLocalNames = resource.getAllDefinedLocalNames(type); Collection<String> list; if ((list = data.get(id.getNamespace())) == null) { // list does not yet exist list = new ArrayList<>(); data.put(id.getNamespace(), list); }/*from ww w . j a v a2 s .co m*/ list.addAll(allLocalNames); } ArrayNode rootNode = Utils.mapper.createArrayNode(); // ensure ordering in JSON object Collection<Namespace> allns = new TreeSet<>(); allns.addAll(data.keySet()); for (Namespace ns : allns) { Collection<String> localNames = data.get(ns); if (!localNames.isEmpty()) { ObjectNode groupEntry = Utils.mapper.createObjectNode(); rootNode.add(groupEntry); groupEntry.put("text", ns.getDecoded()); ArrayNode children = Utils.mapper.createArrayNode(); groupEntry.put("children", children); Collection<String> sortedLocalNames = new TreeSet<>(); sortedLocalNames.addAll(localNames); for (String localName : sortedLocalNames) { String value = "{" + ns.getDecoded() + "}" + localName; //noinspection UnnecessaryLocalVariable String text = localName; ObjectNode o = Utils.mapper.createObjectNode(); o.put("text", text); o.put("value", value); children.add(o); } } } try { return Utils.mapper.writeValueAsString(rootNode); } catch (JsonProcessingException e) { throw new IllegalStateException("Could not create JSON", e); } }
From source file:de.uni_potsdam.hpi.bpt.promnicat.importer.AbstractImporter.java
/** * Collects recursively all files in the given directory and all of it's sub-directories. * //from ww w . j a v a 2s . c om * @param rootDir the directory to start with * @return a {@link Collection} of all found files. */ protected Collection<File> getFilesRecursivelyFromDir(File rootDir) { Collection<File> files = new ArrayList<File>(); for (File file : rootDir.listFiles()) { if (file.isDirectory()) { files.addAll(getFilesRecursivelyFromDir(file)); } else { files.add(file); } } return files; }
From source file:edu.umd.cs.psl.util.graph.memory.MemoryNode.java
@Override public Collection<? extends Edge> getEdges() { Collection<MemoryEdge> edges = new HashSet<MemoryEdge>(getNoEdges()); edges.addAll(getProperties()); edges.addAll(getRelationships());// w ww . ja v a 2s.c om return edges; }
From source file:org.hdiv.web.multipart.HDIVMultipartResolver.java
/** * Return the multipart files as Map of field name to MultipartFile instance. *///from w w w . j a v a 2 s . c o m public Collection<MultipartFile> getMultipartFileValues(Hashtable fileElements) { Collection<MultipartFile> multipartFileValues = new ArrayList<MultipartFile>(); multipartFileValues.addAll(fileElements.values()); return multipartFileValues; }