List of usage examples for java.util Collections synchronizedList
public static <T> List<T> synchronizedList(List<T> list)
From source file:mitm.djigzo.web.services.security.AuthenticationEntryPointWithRequestParams.java
public AuthenticationEntryPointWithRequestParams(List<String> requestParameters, String loginPageParameter, Map<String, String> loginURLs) { Check.notNull(requestParameters, "requestParameters"); Check.notNull(loginPageParameter, "loginPageParameter"); Check.notNull(loginURLs, "loginURLs"); this.requestParameters = Collections.synchronizedList(new ArrayList<String>(requestParameters)); this.loginPageParameter = loginPageParameter; this.loginURLs = Collections.synchronizedMap(new HashMap<String, String>(loginURLs)); }
From source file:org.sonar.batch.mediumtest.log.LogListenerTest.java
@Before public void prepare() throws IOException { System.setOut(new PrintStream(stdOutTarget)); System.setErr(new PrintStream(stdErrTarget)); // logger from the batch might write to it asynchronously logOutput = Collections.synchronizedList(new LinkedList<LogEvent>()); logOutputStr = new StringBuilder(); tester.start();//from w w w. j a v a2 s . com baseDir = temp.getRoot(); builder = ImmutableMap.<String, String>builder().put("sonar.task", "scan") .put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project") .put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT") .put("sonar.projectDescription", "Description of Foo Project"); }
From source file:internal.static_util.scorer.TermRelatednessScorer.java
/** * Given a word and a set of its related relatedTerms, returns an ordered list of relatedTerms ranked from most relevant to least. * * @param original The word you want to find ranked relatedTerms for * @param relatedTerms The set of terms related to the original * @param minRelevanceRatio An optional parameter for the minimum a synonym must score to be returned. If none * given, .50 is assumed. * @return A list of scoredTerms, in descending order of their scores. *//*www . j a v a2 s . c om*/ public static List<ScoredTerm> getRankedTermsWithScores(String original, Set<String> relatedTerms, double minRelevanceRatio) { // Handle null/empty cases if (original == null || relatedTerms == null || relatedTerms.isEmpty()) { return Collections.EMPTY_LIST; } // A HashMap with the word as the key, and its corresponding score List<ScoredTerm> scoredTerms = Collections.synchronizedList(new ArrayList<>()); // Open up a parallel stream on the relatedTerms to perform the doc search on them all relatedTerms.parallelStream().forEach(term -> scoredTerms.add(new ScoredTerm(term, score(original, term)))); // TODO: NOTICE: if the change is made to use a 'top ten' type, refactor to just take first 'x' relatedTerms // Trim the fat - anything below relevance rank gets the D List<ScoredTerm> relevantTerms = getRelevantTerms(scoredTerms, minRelevanceRatio); // Use common.data.ScoredTerm's built-in comparator for sorting purposes // It is by default in ascending order; we want most relevant first, so reverse it Collections.sort(relevantTerms, Comparator.reverseOrder()); // If there were no relevant relatedTerms, return null. // TODO: throw a NoRelevantTerms exception? return relevantTerms.size() > 0 ? relevantTerms : Collections.EMPTY_LIST; }
From source file:org.opennms.sms.monitor.internal.config.MobileSequenceConfig.java
private List<SequenceSessionVariable> createSessionVariableList() { return Collections.synchronizedList(new ArrayList<SequenceSessionVariable>()); }
From source file:it.units.malelab.ege.core.listener.PropertiesListener.java
public PropertiesListener(Comparator<F> fitnessComparator, Distance<G> genotypeDistance, Distance<Node<T>> phenotypeDistance, Map<Class<? extends GeneticOperator>, String> operatorNames) { super(MappingEvent.class, OperatorApplicationEvent.class, EvolutionStartEvent.class); this.fitnessComparator = fitnessComparator; this.genotypeDistance = genotypeDistance; this.phenotypeDistance = phenotypeDistance; this.operatorNames = operatorNames; partialDistances = (Map) Collections.synchronizedMap(new LinkedHashMap<>()); cumulativeDistances = (Map) Collections.synchronizedMap(new LinkedHashMap<>()); counts = (Map) Collections.synchronizedMap(new LinkedHashMap<>()); //reset data// w ww . ja v a 2 s . co m counts.put(NO_OPERATOR, (Multiset) ConcurrentHashMultiset.create()); for (String operatorName : operatorNames.values()) { counts.put(operatorName, (Multiset) ConcurrentHashMultiset.create()); partialDistances.put(operatorName, Collections.synchronizedList(new ArrayList<Pair<Double, Double>>())); cumulativeDistances.put(operatorName, Collections.synchronizedList(new ArrayList<Pair<Double, Double>>())); } }
From source file:interactivespaces.service.comm.twitter.internal.twitter4j.Twitter4jTwitterConnection.java
/** * Construct a twitter connection.//from w ww . ja va 2 s. co m * * @param apiKey * the API key for the connection * @param apiKeySecret * the API secret for the connection * @param userAccessToken * the user access token for the connection * @param userAccessTokenSecret * the user access token secret for the connection * @param log * the logger for this endpoint */ public Twitter4jTwitterConnection(String apiKey, String apiKeySecret, String userAccessToken, String userAccessTokenSecret, Log log) { this.apiKey = apiKey; this.apiKeySecret = apiKeySecret; this.userAccessToken = userAccessToken; this.userAccessTokenSecret = userAccessTokenSecret; listeners = Lists.newArrayList(); listeners = Collections.synchronizedList(listeners); }
From source file:com.adaptris.core.RetryMessageErrorHandlerImp.java
public RetryMessageErrorHandlerImp() { super();//from w w w .j ava 2s . c o m retryList = Collections.synchronizedList(new ArrayList<AdaptrisMessage>()); inProgress = Collections.synchronizedList(new ArrayList<AdaptrisMessage>()); }
From source file:hr.fer.zemris.vhdllab.platform.ui.command.DevFloodWithCompliationRequestsCommand.java
private void floodWithCompilationRequests(final Integer fileId, final String name) { String input = JOptionPane.showInputDialog("How many?", "30"); int floodCount = Integer.parseInt(input); final List<String> results = Collections.synchronizedList(new ArrayList<String>(floodCount)); final CyclicBarrier barrier = new CyclicBarrier(floodCount); List<Thread> threads = new ArrayList<Thread>(floodCount); long start = System.currentTimeMillis(); for (int i = 0; i < floodCount; i++) { Thread thread = new Thread(new Runnable() { @SuppressWarnings("synthetic-access") @Override//from www .ja v a 2 s . co m public void run() { try { barrier.await(); } catch (Exception e) { throw new UnhandledException(e); } logger.info("sending at: " + System.currentTimeMillis()); List<CompilationMessage> messages; try { messages = simulator.compile(fileId); } catch (SimulatorTimeoutException e) { String message = localizationSource.getMessage("simulator.compile.timout", new Object[] { name }); messages = Collections.singletonList(new CompilationMessage(message)); } catch (NoAvailableProcessException e) { String message = localizationSource.getMessage("simulator.compile.no.processes", new Object[] { name }); messages = Collections.singletonList(new CompilationMessage(message)); } if (messages.isEmpty()) { results.add("Successful"); } else { results.add(messages.get(0).getText()); } } }); thread.start(); threads.add(thread); } logger.info("waiting for threads to complete..."); for (Thread thread : threads) { try { thread.join(); } catch (InterruptedException e) { throw new UnhandledException(e); } } long end = System.currentTimeMillis(); logger.info("ended in " + (end - start) + " ms"); showResults(results); }
From source file:ch.chrigu.datastructures.demo.instances.CollectionInstance.java
/** * The best matching {@link Collections}'s synchronized... function is applied. */// w w w . j a va 2 s. c o m private Collection<T> synchronizedCollection(Collection<T> instance) { if (instance instanceof List) { return Collections.synchronizedList((List<T>) instance); } if (instance instanceof Set) { if (instance instanceof NavigableSet) { return Collections.synchronizedNavigableSet((NavigableSet<T>) instance); } return Collections.synchronizedSet((Set<T>) instance); } return Collections.synchronizedCollection(instance); }
From source file:org.rifidi.designer.rcp.views.view3d.threads.UpdateThread.java
/** * //from w w w . j av a 2 s .co m * @param rootNode * root of the scene to update * @param physicsSpace * associated physics space * @param update * update queue to use * @param fieldService * current fieldservice */ public UpdateThread(ReentrantLock lock, SceneData sceneData, List<RepeatedUpdateAction> repeatedActions, FieldService fieldService, CameraService cameraService) { logger.debug("New UpdateThread instantiated."); timer = Timer.getTimer(); this.lock = lock; this.setName("UpdateThread"); this.sceneData = sceneData; this.repeatedActions = Collections.synchronizedList(repeatedActions); this.fieldService = fieldService; this.cameraService = cameraService; }