List of usage examples for java.util Collection addAll
boolean addAll(Collection<? extends E> c);
From source file:org.simbasecurity.core.domain.repository.RuleDatabaseRepository.java
public Collection<ResourceRule> findResourceRules(String username, String resource) { Collection<ResourceRule> resourceRules = getResourceRulesDirectly(username, resource); resourceRules.addAll(getResourceRulesViaGroups(username, resource)); return resourceRules; }
From source file:com.github.junrar.vfs2.provider.rar.RARFileSystem.java
/** * Returns the capabilities of this file system. *///from w ww . ja v a2 s . c o m @Override protected void addCapabilities(final Collection<Capability> caps) { caps.addAll(RARFileProvider.capabilities); }
From source file:com.hp.autonomy.searchcomponents.hod.parametricvalues.HodParametricValuesService.java
@Override @Cacheable(CacheNames.PARAMETRIC_VALUES) public Set<QueryTagInfo> getAllParametricValues(final HodParametricRequest parametricRequest) throws HodErrorException { final Collection<String> fieldNames = new HashSet<>(); fieldNames.addAll(parametricRequest.getFieldNames()); if (fieldNames.isEmpty()) { fieldNames.addAll(fieldsService.getParametricFields(new HodFieldsRequest.Builder() .setDatabases(parametricRequest.getQueryRestrictions().getDatabases()).build())); }/*from w w w . j a va 2s . c o m*/ final Set<QueryTagInfo> results; if (fieldNames.isEmpty()) { results = Collections.emptySet(); } else { final ResourceIdentifier queryProfile = parametricRequest.isModified() ? getQueryProfile() : null; final GetParametricValuesRequestBuilder parametricParams = new GetParametricValuesRequestBuilder() .setQueryProfile(queryProfile).setSort(ParametricSort.document_count) .setText(parametricRequest.getQueryRestrictions().getQueryText()) .setFieldText(parametricRequest.getQueryRestrictions().getFieldText()) .setMaxValues(parametricRequest.getMaxValues()); final FieldNames parametricFieldNames = getParametricValuesService.getParametricValues(fieldNames, new ArrayList<>(parametricRequest.getQueryRestrictions().getDatabases()), parametricParams); final Set<String> fieldNamesSet = parametricFieldNames.getFieldNames(); results = new HashSet<>(); for (final String name : fieldNamesSet) { final Set<QueryTagCountInfo> values = new HashSet<>( parametricFieldNames.getValuesAndCountsForFieldName(name)); if (!values.isEmpty()) { results.add(new QueryTagInfo(name, values)); } } } return results; }
From source file:com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.java
private static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, XMLConfiguration config, int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, final StateManager stateManager, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { // 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/*ww w.j a v a2 s . c o m*/ 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); //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:jsprit.core.algorithm.io.VehicleRoutingAlgorithms.java
private static VehicleRoutingAlgorithm readAndCreateAlgorithm(final VehicleRoutingProblem vrp, XMLConfiguration config, int nuOfThreads, final SolutionCostCalculator solutionCostCalculator, final StateManager stateManager, ConstraintManager constraintManager, boolean addDefaultCostCalculators) { // 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// w ww .ja v a 2 s . co m 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()); 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)); 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); //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:com.nextdoor.bender.monitoring.cw.CloudwatchReporter.java
@Override public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) { Date dt = new Date(); dt.setTime(invokeTimeMs);//from www .j ava2s .co m Collection<Dimension> parentDims = tagsToDimensions(tags); List<MetricDatum> metrics = new ArrayList<MetricDatum>(); /* * Create CW metric objects from bender internal Stat objects */ for (Stat stat : stats) { /* * Dimension are CW's version of metric tags. A conversion must be done. */ Collection<Dimension> metricDims = tagsToDimensions(stat.getTags()); metricDims.addAll(parentDims); MetricDatum metric = new MetricDatum(); metric.setMetricName(stat.getName()); // TODO: add units to Stat object SYSTEMS-870 metric.setUnit(StandardUnit.None); metric.setTimestamp(dt); metric.setDimensions(metricDims); metric.setValue((double) stat.getValue()); metrics.add(metric); } /* * Not very well documented in java docs but CW only allows 20 metrics at a time. */ List<List<MetricDatum>> chunks = ListUtils.partition(metrics, 20); for (List<MetricDatum> chunk : chunks) { PutMetricDataRequest req = new PutMetricDataRequest(); req.withMetricData(chunk); req.setNamespace(namespace); this.client.putMetricData(req); } }
From source file:demo.config.diff.ConfigDiffResult.java
public Collection<ConfigGroupDiff> getAllGroups() { Collection<ConfigGroupDiff> result = new ArrayList<>(); for (List<ConfigGroupDiff> configGroupDiffs : this.groups.values()) { result.addAll(configGroupDiffs); }// w ww .j a v a 2s. co m return result; }
From source file:org.apache.batchee.cli.lifecycle.impl.SpringLifecycle.java
@Override public AbstractApplicationContext start() { final Map<String, Object> config = configuration("spring"); final AbstractApplicationContext ctx; if (config.containsKey("locations")) { final Collection<String> locations = new LinkedList<String>(); locations.addAll(asList(config.get("locations").toString().split(","))); ctx = new ClassPathXmlApplicationContext(locations.toArray(new String[locations.size()])); } else if (config.containsKey("classes")) { final Collection<Class<?>> classes = new LinkedList<Class<?>>(); final ClassLoader loader = currentThread().getContextClassLoader(); for (final String clazz : config.get("classes").toString().split(",")) { try { classes.add(loader.loadClass(clazz)); } catch (final ClassNotFoundException e) { throw new BatchContainerRuntimeException(e); }//w w w . j av a 2 s. c o m } ctx = new AnnotationConfigApplicationContext(classes.toArray(new Class<?>[classes.size()])); } else { throw new IllegalArgumentException( LIFECYCLE_PROPERTIES_FILE + " should contain 'classes' or 'locations' key"); } final Properties p = new Properties(); p.put(BatchArtifactFactory.class.getName(), new SpringArtifactFactory(ctx)); final ServicesManager mgr = new ServicesManager(); mgr.init(p); ServicesManager.setServicesManagerLocator(new ServicesManagerLocator() { @Override public ServicesManager find() { return mgr; } }); return ctx; }
From source file:ca.uhn.fhir.rest.method.ElementsParameter.java
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Object translateQueryParametersIntoServerArgument(RequestDetails theRequest, BaseMethodBinding<?> theMethodBinding) throws InternalErrorException, InvalidRequestException { Set<String> value = getElementsValueOrNull(theRequest); if (value == null || value.isEmpty()) { return null; }/*from w ww. ja va2 s. c o m*/ if (myInnerCollectionType == null) { return StringUtils.join(value, ','); } try { Collection retVal = myInnerCollectionType.newInstance(); retVal.addAll(value); return retVal; } catch (InstantiationException e) { throw new InternalErrorException("Failed to instantiate " + myInnerCollectionType, e); } catch (IllegalAccessException e) { throw new InternalErrorException("Failed to instantiate " + myInnerCollectionType, e); } }
From source file:com.assemblade.server.model.Property.java
public Collection<String> getAttributeNames() { Collection<String> attributeNames = super.getAttributeNames(); attributeNames.addAll(Arrays.asList("cn", "asb-value", "description", "aclRights")); return attributeNames; }