List of usage examples for java.util Queue add
boolean add(E e);
From source file:com.github.fauu.natrank.service.RankingServiceImpl.java
@Override public void createRankings() throws DataAccessException { List<Match> matches = (List<Match>) matchRepository.findAll(); calculateTeamRatingsAndRankChanges(matches); calculateTeamExtremes();//from w w w.j a v a 2s . c om List<Ranking> rankings = new LinkedList<>(); Map<Integer, RankingEntry> entryMap = new HashMap<>(); rankingRepository.deleteAll(); Queue<LocalDate> rankingDateQueue = new LinkedList<>(); rankingDateQueue.add(matches.get(matches.size() - 1).getDate()); for (Match match : matches) { LocalDate nextRankingDate = rankingDateQueue.peek(); if (nextRankingDate == null) { break; } if (match.getDate().isAfter(nextRankingDate)) { rankings.add(createRankingForDate(rankingDateQueue.poll(), entryMap)); } List<Team> matchTeams = new ArrayList<>(); matchTeams.add(match.getTeam1()); matchTeams.add(match.getTeam2()); for (Team team : matchTeams) { if (!entryMap.containsKey(team.getId())) { RankingEntry newEntry = new RankingEntry(); newEntry.setTeam(team); entryMap.put(team.getId(), newEntry); } } List<RankingEntry> matchTeamEntries = new ArrayList<>(); matchTeamEntries.add(entryMap.get(matchTeams.get(0).getId())); matchTeamEntries.add(entryMap.get(matchTeams.get(1).getId())); matchTeamEntries.get(0).incrementMatchesTotal(); matchTeamEntries.get(1).incrementMatchesTotal(); if (match.getHomeTeam() == null) { matchTeamEntries.get(0).incrementMatchesOnNeutralGround(); matchTeamEntries.get(1).incrementMatchesOnNeutralGround(); } else if (match.getHomeTeam() == matchTeams.get(0)) { matchTeamEntries.get(0).incrementMatchesHome(); matchTeamEntries.get(1).incrementMatchesAway(); } else if (match.getHomeTeam() == matchTeams.get(1)) { matchTeamEntries.get(0).incrementMatchesAway(); matchTeamEntries.get(1).incrementMatchesHome(); } if (match.getWinnerTeam() == null) { matchTeamEntries.get(0).incrementDraws(); matchTeamEntries.get(1).incrementDraws(); } else if (match.getWinnerTeam() == matchTeams.get(0)) { matchTeamEntries.get(0).incrementWins(); matchTeamEntries.get(1).incrementLosses(); } else if (match.getWinnerTeam() == matchTeams.get(1)) { matchTeamEntries.get(0).incrementLosses(); matchTeamEntries.get(1).incrementWins(); } matchTeamEntries.get(0).addGoalsFor(match.getTeam1Goals()); matchTeamEntries.get(0).addGoalsAgainst(match.getTeam2Goals()); matchTeamEntries.get(1).addGoalsFor(match.getTeam2Goals()); matchTeamEntries.get(1).addGoalsAgainst(match.getTeam1Goals()); } LocalDate nextRankingDate; while ((nextRankingDate = rankingDateQueue.poll()) != null) { rankings.add(createRankingForDate(nextRankingDate, entryMap)); } rankingRepository.save(rankings); }
From source file:org.protempa.Executor.java
private void retain(Set<PropositionDefinition> propDefs) { if (this.propIdsToRetain != null) { Map<String, PropositionDefinition> propDefMap = new HashMap<>(); for (PropositionDefinition and : propDefs) { propDefMap.put(and.getId(), and); }// w w w . ja va2 s. co m Queue<String> propIdsQueue = new LinkedList<>(this.propIds); String pid; Set<PropositionDefinition> propDefsToKeep = new HashSet<>(); while ((pid = propIdsQueue.poll()) != null) { if (this.propIdsToRetain.contains(pid)) { Queue<String> propIdsToKeep = new LinkedList<>(); propIdsToKeep.add(pid); String pid2; while ((pid2 = propIdsToKeep.poll()) != null) { PropositionDefinition get = propDefMap.get(pid2); propDefsToKeep.add(get); Arrays.addAll(propIdsToKeep, get.getChildren()); } } else { PropositionDefinition get = propDefMap.get(pid); Arrays.addAll(propIdsQueue, get.getChildren()); } } allNarrowerDescendants = propDefsToKeep; } else { allNarrowerDescendants = propDefs; } }
From source file:it.geosolutions.geobatch.nrl.csvingest.CSVIngestActionTest.java
@Test public void laodAll() throws Exception { createCropDescriptors();/*from w w w. j a va2 s. c o m*/ Queue<EventObject> events = new LinkedList<EventObject>(); File dir = loadFile("all"); assertNotNull(dir); assertTrue(dir.isDirectory()); CSVIngestAction action = new CSVIngestAction(new CSVIngestConfiguration(null, null, null)); action.setCropDataDao(cropDataDAO); action.setCropDescriptorDao(cropDescriptorDAO); action.setAgrometDao(agrometDAO); action.afterPropertiesSet(); for (File file : FileUtils.listFiles(dir, new String[] { "csv" }, true)) { FileSystemEvent event = new FileSystemEvent(file, FileSystemEventType.FILE_ADDED); events.add(event); Queue result = action.execute(events); } }
From source file:com.barchart.netty.server.http.TestHttpServer.java
@Test public void testTooManyConnections() throws Exception { final Queue<Integer> status = new LinkedBlockingQueue<Integer>(); final Runnable r = new Runnable() { @Override//from w ww.j av a 2 s . c o m public void run() { try { final HttpResponse response = client .execute(new HttpGet("http://localhost:" + port + "/client-disconnect")); status.add(response.getStatusLine().getStatusCode()); EntityUtils.consume(response.getEntity()); } catch (final Exception e) { e.printStackTrace(); } } }; final Thread t1 = new Thread(r); t1.start(); final Thread t2 = new Thread(r); t2.start(); t1.join(); t2.join(); assertEquals(2, status.size()); assertTrue(status.contains(200)); assertTrue(status.contains(503)); }
From source file:eu.stratosphere.nephele.jobmanager.splitassigner.file.FileInputSplitList.java
/** * Returns a list of file input splits specifically ordered for the given {@link AbstractInstance}. When the list is * initially created, it contains all the unconsumed file input splits at that point in time, ascendingly ordered by * the minimum distance between the input splits' storage locations and the given {@link AbstractInstance}. * //from w ww . ja va 2 s . c o m * @param instance * the instance for which the file input split list has been computed * @return the list of file input splits ordered specifically for the given instance */ private Queue<QueueElem> getInstanceSplitList(final AbstractInstance instance) { Queue<QueueElem> instanceSplitList = this.instanceMap.get(instance); if (instanceSplitList == null) { // Create and populate instance specific split list instanceSplitList = new PriorityQueue<FileInputSplitList.QueueElem>(); final Iterator<FileInputSplit> it = this.masterSet.iterator(); while (it.hasNext()) { final FileInputSplit split = it.next(); final String[] hostNames = split.getHostNames(); if (hostNames == null) { instanceSplitList.add(new QueueElem(split, Integer.MAX_VALUE)); } else { int minDistance = Integer.MAX_VALUE; for (int i = 0; i < hostNames.length; ++i) { final int distance = instance.getDistance(hostNames[i]); if (LOG.isDebugEnabled()) { LOG.debug("Distance between " + instance + " and " + hostNames[i] + " is " + distance); } if (distance < minDistance) { minDistance = distance; } } instanceSplitList.add(new QueueElem(split, minDistance)); } } this.instanceMap.put(instance, instanceSplitList); } return instanceSplitList; }
From source file:org.apache.flink.runtime.jobmanager.splitassigner.file.FileInputSplitList.java
/** * Returns a list of file input splits specifically ordered for the given {@link org.apache.flink.runtime.instance.Instance}. When the list is * initially created, it contains all the unconsumed file input splits at that point in time, ascendingly ordered by * the minimum distance between the input splits' storage locations and the given {@link org.apache.flink.runtime.instance.Instance}. * //from w w w . ja v a 2s . c o m * @param instance * the instance for which the file input split list has been computed * @return the list of file input splits ordered specifically for the given instance */ private Queue<QueueElem> getInstanceSplitList(final Instance instance) { Queue<QueueElem> instanceSplitList = this.instanceMap.get(instance); if (instanceSplitList == null) { // Create and populate instance specific split list instanceSplitList = new PriorityQueue<FileInputSplitList.QueueElem>(); final Iterator<FileInputSplit> it = this.masterSet.iterator(); while (it.hasNext()) { final FileInputSplit split = it.next(); final String[] hostNames = split.getHostNames(); if (hostNames == null) { instanceSplitList.add(new QueueElem(split, Integer.MAX_VALUE)); } else { int minDistance = Integer.MAX_VALUE; for (int i = 0; i < hostNames.length; ++i) { final int distance = instance.getDistance(hostNames[i]); if (LOG.isDebugEnabled()) { LOG.debug("Distance between " + instance + " and " + hostNames[i] + " is " + distance); } if (distance < minDistance) { minDistance = distance; } } instanceSplitList.add(new QueueElem(split, minDistance)); } } this.instanceMap.put(instance, instanceSplitList); } return instanceSplitList; }
From source file:org.gradle.model.internal.method.WeaklyTypeReferencingMethod.java
private Method findMethod(Class<?> clazz, Class<?>[] paramTypes) { Set<Class<?>> seenInterfaces = null; Queue<Class<?>> queue = null; Class<?> type = clazz;/*from w w w . ja va 2 s . c o m*/ while (type != null) { for (Method method : type.getDeclaredMethods()) { if (method.getName().equals(name) && Arrays.equals(paramTypes, method.getParameterTypes())) { return method; } } if (queue == null) { queue = new ArrayDeque<Class<?>>(); seenInterfaces = Sets.newHashSet(); } Class<?> superclass = type.getSuperclass(); if (superclass != null) { queue.add(superclass); } for (Class<?> iface : type.getInterfaces()) { if (seenInterfaces.add(iface)) { queue.add(iface); } } type = queue.poll(); } throw new org.gradle.internal.reflect.NoSuchMethodException( String.format("Could not find method %s(%s) on %s.", name, Joiner.on(", ").join(paramTypes), this.target.getRawClass().getSimpleName())); }
From source file:eu.stratosphere.nephele.jobmanager.splitassigner.LocatableInputSplitList.java
/** * Returns a list of locatable input splits specifically ordered for the given {@link AbstractInstance}. When the * list is initially created, it contains all the unconsumed located input splits at that point in time, ascendingly * ordered//ww w . java 2s . c o m * by the minimum distance between the input splits' storage locations and the given {@link AbstractInstance}. * * @param instance * the instance for which the locatable input split list has been computed * @return the list of file input splits ordered specifically for the given instance */ private Queue<QueueElem> getInstanceSplitList(final AbstractInstance instance) { Queue<QueueElem> instanceSplitList = this.instanceMap.get(instance); if (instanceSplitList == null) { // Create and populate instance specific split list instanceSplitList = new PriorityQueue<LocatableInputSplitList.QueueElem>(); final Iterator<LocatableInputSplit> it = this.masterSet.iterator(); while (it.hasNext()) { final LocatableInputSplit split = it.next(); final String[] hostnames = split.getHostnames(); if (hostnames == null) { instanceSplitList.add(new QueueElem(split, Integer.MAX_VALUE)); } else { int minDistance = Integer.MAX_VALUE; for (int i = 0; i < hostnames.length; ++i) { final int distance = instance.getDistance(hostnames[i]); if (LOG.isDebugEnabled()) { LOG.debug("Distance between " + instance + " and " + hostnames[i] + " is " + distance); } if (distance < minDistance) { minDistance = distance; } } instanceSplitList.add(new QueueElem(split, minDistance)); } } this.instanceMap.put(instance, instanceSplitList); } return instanceSplitList; }
From source file:org.grouplens.grapht.solver.DependencySolver.java
/** * Update the dependency graph to include the given desire. An edge from the * root node to the desire's resolved satisfaction will exist after this is * finished./*from w w w .j a v a 2 s. c o m*/ * * @param desire The desire to include in the graph */ public synchronized void resolve(Desire desire) throws ResolutionException { logger.info("Resolving desire: {}", desire); Queue<Deferral> deferralQueue = new ArrayDeque<Deferral>(); // before any deferred nodes are processed, we use a synthetic root // and null original desire since nothing produced this root deferralQueue.add(new Deferral(rootNode(), initialContext())); while (!deferralQueue.isEmpty()) { Deferral current = deferralQueue.poll(); DAGNode<Component, Dependency> parent = current.node; // deferred nodes are either root - depless - or having deferred dependencies assert parent.getOutgoingEdges().isEmpty(); if (current.node.getLabel().equals(ROOT_SATISFACTION)) { Pair<DAGNode<Component, Dependency>, Dependency> rootNode = resolveFully(desire, current.context, deferralQueue); // add this to the global graph graph = DAGNode.copyBuilder(graph).addEdge(mergePool.merge(rootNode.getLeft()), rootNode.getRight()) .build(); } else if (graph.getReachableNodes().contains(parent)) { // the node needs to be re-scanned. This means that it was not consolidated by // a previous merge operation. This branch only arises with provider injection. Satisfaction sat = parent.getLabel().getSatisfaction(); for (Desire d : sat.getDependencies()) { logger.debug("Attempting to resolve deferred dependency {} of {}", d, sat); // resolve the dependency Pair<DAGNode<Component, Dependency>, Dependency> result = resolveFully(d, current.context, deferralQueue); // merge it in DAGNode<Component, Dependency> merged = mergePool.merge(result.getLeft()); // now see if there's a real cycle if (merged.getReachableNodes().contains(parent)) { // parent node is referenced from merged, we have a circle! // that means we need a back edge backEdges.put(parent, DAGEdge.create(parent, merged, result.getRight())); } else { // an edge from parent to merged does not add a cycle // we have to update graph right away so it's available to merge the next // dependency DAGNode<Component, Dependency> newP = DAGNode.copyBuilder(parent) .addEdge(merged, result.getRight()).build(); replaceNode(parent, newP); parent = newP; } } } else { // node unreachable - it's a leftover or unneeded deferral logger.debug("node {} not in graph, ignoring", parent); } } }
From source file:org.apache.flink.runtime.jobmanager.splitassigner.LocatableInputSplitList.java
/** * Returns a list of locatable input splits specifically ordered for the given {@link org.apache.flink.runtime.instance.Instance}. When the * list is initially created, it contains all the unconsumed located input splits at that point in time, ascendingly * ordered/*w ww.ja v a 2s .c om*/ * by the minimum distance between the input splits' storage locations and the given {@link org.apache.flink.runtime.instance.Instance}. * * @param instance * the instance for which the locatable input split list has been computed * @return the list of file input splits ordered specifically for the given instance */ private Queue<QueueElem> getInstanceSplitList(final Instance instance) { Queue<QueueElem> instanceSplitList = this.instanceMap.get(instance); if (instanceSplitList == null) { // Create and populate instance specific split list instanceSplitList = new PriorityQueue<LocatableInputSplitList.QueueElem>(); final Iterator<LocatableInputSplit> it = this.masterSet.iterator(); while (it.hasNext()) { final LocatableInputSplit split = it.next(); final String[] hostnames = split.getHostnames(); if (hostnames == null) { instanceSplitList.add(new QueueElem(split, Integer.MAX_VALUE)); } else { int minDistance = Integer.MAX_VALUE; for (int i = 0; i < hostnames.length; ++i) { final int distance = instance.getDistance(hostnames[i]); if (LOG.isDebugEnabled()) { LOG.debug("Distance between " + instance + " and " + hostnames[i] + " is " + distance); } if (distance < minDistance) { minDistance = distance; } } instanceSplitList.add(new QueueElem(split, minDistance)); } } this.instanceMap.put(instance, instanceSplitList); } return instanceSplitList; }