List of usage examples for java.util LinkedList addFirst
public void addFirst(E e)
From source file:org.cloudata.core.common.ipc.CClient.java
/** * ?? call? ?? Pool? ./*from w w w . j a v a 2 s . c o m*/ * @param address * @param conn */ private void returnToConnections(InetSocketAddress address, Connection conn) { synchronized (connections) { LinkedList<Connection> hostConnections = connections.get(address); if (hostConnections != null) { LOG.debug("return connection to pool : " + conn); conn.touch(); hostConnections.addFirst(conn); } } }
From source file:pivotal.au.se.gemfirexdweb.controller.QueryController.java
private void addCommandToHistory(HttpSession session, UserPref prefs, String sql) { @SuppressWarnings("unchecked") LinkedList<String> historyList = (LinkedList<String>) session.getAttribute("history"); int maxsize = prefs.getHistorySize(); if (historyList.size() == maxsize) { historyList.remove((maxsize - 1)); historyList.addFirst(sql); } else {/*from www . j a v a 2 s .c om*/ historyList.addFirst(sql); } }
From source file:com.wordnik.swaggersocket.server.SwaggerSocketProtocolInterceptor.java
private final void attachWriter(final AtmosphereResource r) { final AtmosphereRequest request = r.getRequest(); AtmosphereResponse res = r.getResponse(); AsyncIOWriter writer = res.getAsyncIOWriter(); BlockingQueue<AtmosphereResource> queue = (BlockingQueue<AtmosphereResource>) getContextValue(request, SUSPENDED_RESPONSE);/* w w w. ja v a 2s . c om*/ if (queue == null) { queue = new LinkedBlockingQueue<AtmosphereResource>(); request.getSession().setAttribute(SUSPENDED_RESPONSE, queue); } if (AtmosphereInterceptorWriter.class.isAssignableFrom(writer.getClass())) { // WebSocket already had one. if (r.transport() != AtmosphereResource.TRANSPORT.WEBSOCKET) { writer = new AtmosphereInterceptorWriter() { @Override protected void writeReady(AtmosphereResponse response, byte[] data) throws IOException { // We are buffering response. if (data == null) return; BlockingQueue<AtmosphereResource> queue = (BlockingQueue<AtmosphereResource>) getContextValue( request, SUSPENDED_RESPONSE); if (queue != null) { AtmosphereResource resource; try { // TODO: Should this be configurable // We stay suspended for 60 seconds resource = queue.poll(60, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.trace("", e); return; } if (resource == null) { logger.debug("No resource was suspended, resuming the second connection."); } else { logger.trace("Resuming {}", resource.uuid()); try { OutputStream o = resource.getResponse().getResponse().getOutputStream(); o.write(data); o.flush(); resource.resume(); } catch (IOException ex) { logger.warn("", ex); } } } else { logger.error("Queue was null"); } } /** * Add an {@link AsyncIOInterceptor} that will be invoked in the order it was added. * * @param filter {@link AsyncIOInterceptor * @return this */ public AtmosphereInterceptorWriter interceptor(AsyncIOInterceptor filter) { if (!filters.contains(filter)) { filters.addLast(filter); } return this; } }; res.asyncIOWriter(writer); } //REVIST need a better way to add a custom filter at the first entry and not at the last as // e.g. interceptor(AsyncIOInterceptor interceptor, int position) LinkedList<AsyncIOInterceptor> filters = AtmosphereInterceptorWriter.class.cast(writer).filters(); if (!filters.contains(interceptor)) { filters.addFirst(interceptor); } } }
From source file:org.dcm4chee.archive.conf.defaults.DeepEquals.java
/** * Deeply compare to Arrays []. Both arrays must be of the same type, same length, and all * elements within the arrays must be deeply equal in order to return true. * @param dualKey arrays/*from w w w . j av a 2 s .c o m*/ * @param stack add items to compare to the Stack (Stack versus recursion) * @param visited Set of objects already compared (prevents cycles) * @return true if the two arrays are the same length and contain deeply equivalent items. */ private static boolean compareArrays(DualKey dualKey, LinkedList stack, Set visited) { Object array1 = dualKey._key1; Object array2 = dualKey._key2; // Same instance check already performed... int len = Array.getLength(array1); if (len != Array.getLength(array2)) { return false; } // try sorting // if (len >0 ) { // if (Array.get(array1, 0) instanceof Comparable) // { // // Class<?> c = Array.get(array1, 0).getClass(); // // if (ClassUtils.isPrimitiveOrWrapper(c)) // { // /* Arrays.sort(array1); // Arrays.sort((Object[]) array2);*/ // // } else { // // Arrays.sort((Object[]) array1); // Arrays.sort((Object[]) array2); // } // // } // } for (int i = 0; i < len; i++) { DualKey dk = new DualKey(Array.get(array1, i), Array.get(array2, i), Integer.toString(i), dualKey); if (!visited.contains(dk)) { // push contents for further comparison stack.addFirst(dk); } } return true; }
From source file:org.commonjava.emb.project.ProjectLoader.java
private void addProjects(final ProjectToolsSession session, final List<MavenProject> projects) { final DependencyGraph depGraph = session.getDependencyGraph(); for (final MavenProject project : projects) { final LinkedList<Artifact> parentage = new LinkedList<Artifact>(); MavenProject parent = project;/* ww w . j av a 2s .c o m*/ while (parent != null) { final org.apache.maven.artifact.Artifact pomArtifact = mavenRepositorySystem .createArtifact(project.getGroupId(), project.getArtifactId(), project.getVersion(), "pom"); final Artifact aetherPomArtifact = RepositoryUtils.toArtifact(pomArtifact); parentage.addFirst(aetherPomArtifact); parent = parent.getParent(); } Artifact current = parentage.removeFirst(); while (!parentage.isEmpty()) { final Artifact next = parentage.getFirst(); // This is WEIRD, but the parent POM is actually a dependency of the current one, // since it's required in order to build the current project... if (LOGGER.isDebugEnabled()) { LOGGER.debug("Marking parent POM: " + current + " as dependency of POM: " + next); } depGraph.addDependency(next, current, true, true); if (!parentage.isEmpty()) { current = parentage.removeFirst(); } } } }
From source file:org.openconcerto.sql.preferences.SQLPreferences.java
private final LinkedList<SQLPreferences> findAncestors() { // parent() and node() take lock on root, so we have no way of finding our ancestor while we // hold this.lock assert !Thread.holdsLock(this.lock) : "Deadlock possible since we access parent()"; final LinkedList<SQLPreferences> res = new LinkedList<SQLPreferences>(); res.add(this); SQLPreferences current = this; SQLPreferences p;//from w w w . j a v a 2s .co m while ((p = (SQLPreferences) current.parent()) != null) { res.addFirst(p); current = p; } return res; }
From source file:edu.uci.ics.jung.algorithms.shortestpath.DijkstraShortestPath.java
/** * Returns a <code>List</code> of the edges on the shortest path from * <code>source</code> to <code>target</code>, in order of their * occurrence on this path. /*from w w w . j av a 2s .co m*/ * If either vertex is not in the graph for which this instance * was created, throws <code>IllegalArgumentException</code>. */ public List<E> getPath(V source, V target) { if (!g.containsVertex(source)) throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); if (!g.containsVertex(target)) throw new IllegalArgumentException("Specified target vertex " + target + " is not part of graph " + g); LinkedList<E> path = new LinkedList<E>(); // collect path data; must use internal method rather than // calling getIncomingEdge() because getIncomingEdge() may // wipe out results if results are not cached Set<V> targets = new HashSet<V>(); targets.add(target); singleSourceShortestPath(source, targets, g.getVertexCount()); Map<V, E> incomingEdges = ((SourcePathData) sourceMap.get(source)).incomingEdges; if (incomingEdges.isEmpty() || incomingEdges.get(target) == null) return path; V current = target; while (!current.equals(source)) { E incoming = incomingEdges.get(current); path.addFirst(incoming); current = ((Graph<V, E>) g).getOpposite(current, incoming); } return path; }
From source file:com.jaspersoft.jasperserver.export.modules.repository.ResourceImporter.java
protected void createPrependFolder() { if (prependPath != null) { LinkedList toCreateURIs = new LinkedList(); for (String path = prependPath; repository.getFolder(executionContext, path) == null; path = PathUtils.splitPath(path).parentPath) { toCreateURIs.addFirst(path); }/* www . j av a2s . c o m*/ while (!toCreateURIs.isEmpty()) { String path = (String) toCreateURIs.removeFirst(); Folder folder = createFolder(path); commandOut.debug("About to save folder " + path); try { repository.saveFolder(executionContext, folder); } catch (SpringSecurityException er) { this.updateSecuredResource(executionContext, folder); } } } }
From source file:org.quickconnectfamily.json.JSONParser.java
/** * Parse JSON text into java object from the input source. * //from ww w.ja v a 2s. c om * @param in * @param containerFactory - Use this factory to create your own JSON object and JSON array containers. * @return Instance of the following: * org.json.simple.JSONObject, * org.json.simple.JSONArray, * java.lang.String, * java.lang.Number, * java.lang.Boolean, * null * * @throws IOException * @throws ParseException */ @SuppressWarnings({ "unchecked", "rawtypes" }) public Object parse(ContainerFactory containerFactory) throws IOException, ParseException { LinkedList statusStack = new LinkedList(); LinkedList valueStack = new LinkedList(); try { do { if (status != S_IN_FINISHED_VALUE) { nextToken(); } switch (status) { case S_INIT: switch (token.type) { case Yytoken.TYPE_VALUE: status = S_IN_FINISHED_VALUE; statusStack.addFirst(new Integer(status)); valueStack.addFirst(token.value); break; case Yytoken.TYPE_LEFT_BRACE: if (firstCharType == FIRST_JSON_CHAR_TYPE_UNSET) { firstCharType = Yytoken.TYPE_LEFT_BRACE; } if (firstCharType == Yytoken.TYPE_LEFT_BRACE) { numUnmatchedCharTypeCount++; } status = S_IN_OBJECT; statusStack.addFirst(new Integer(status)); valueStack.addFirst(createObjectContainer(containerFactory)); break; case Yytoken.TYPE_LEFT_SQUARE: if (firstCharType == FIRST_JSON_CHAR_TYPE_UNSET) { firstCharType = Yytoken.TYPE_LEFT_SQUARE; } if (firstCharType == Yytoken.TYPE_LEFT_SQUARE) { numUnmatchedCharTypeCount++; } status = S_IN_ARRAY; statusStack.addFirst(new Integer(status)); valueStack.addFirst(createArrayContainer(containerFactory)); break; default: status = S_IN_ERROR; }//inner switch break; case S_IN_FINISHED_VALUE: if (token.type == Yytoken.TYPE_EOF || numUnmatchedCharTypeCount == 0) { firstCharType = FIRST_JSON_CHAR_TYPE_UNSET; status = S_INIT; return valueStack.removeFirst(); } else throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); case S_IN_OBJECT: switch (token.type) { case Yytoken.TYPE_COMMA: break; case Yytoken.TYPE_VALUE: if (token.value instanceof String) { String key = (String) token.value; valueStack.addFirst(key); status = S_PASSED_PAIR_KEY; statusStack.addFirst(new Integer(status)); } else { status = S_IN_ERROR; } break; case Yytoken.TYPE_RIGHT_BRACE: if (firstCharType == Yytoken.TYPE_LEFT_BRACE) { numUnmatchedCharTypeCount--; } if (valueStack.size() > 1) { statusStack.removeFirst(); valueStack.removeFirst(); status = peekStatus(statusStack); } else { status = S_IN_FINISHED_VALUE; } break; default: status = S_IN_ERROR; break; }//inner switch break; case S_PASSED_PAIR_KEY: switch (token.type) { case Yytoken.TYPE_COLON: break; case Yytoken.TYPE_VALUE: statusStack.removeFirst(); String key = (String) valueStack.removeFirst(); Map parent = (Map) valueStack.getFirst(); parent.put(key, token.value); status = peekStatus(statusStack); break; case Yytoken.TYPE_LEFT_SQUARE: if (firstCharType == Yytoken.TYPE_LEFT_SQUARE) { numUnmatchedCharTypeCount++; } statusStack.removeFirst(); key = (String) valueStack.removeFirst(); parent = (Map) valueStack.getFirst(); List newArray = createArrayContainer(containerFactory); parent.put(key, newArray); status = S_IN_ARRAY; statusStack.addFirst(new Integer(status)); valueStack.addFirst(newArray); break; case Yytoken.TYPE_LEFT_BRACE: if (firstCharType == Yytoken.TYPE_LEFT_BRACE) { numUnmatchedCharTypeCount++; } statusStack.removeFirst(); key = (String) valueStack.removeFirst(); parent = (Map) valueStack.getFirst(); Map newObject = createObjectContainer(containerFactory); parent.put(key, newObject); status = S_IN_OBJECT; statusStack.addFirst(new Integer(status)); valueStack.addFirst(newObject); break; default: status = S_IN_ERROR; } break; case S_IN_ARRAY: switch (token.type) { case Yytoken.TYPE_COMMA: break; case Yytoken.TYPE_VALUE: List val = (List) valueStack.getFirst(); val.add(token.value); break; case Yytoken.TYPE_RIGHT_SQUARE: if (firstCharType == Yytoken.TYPE_LEFT_SQUARE) { numUnmatchedCharTypeCount--; } if (valueStack.size() > 1) { statusStack.removeFirst(); valueStack.removeFirst(); status = peekStatus(statusStack); } else { status = S_IN_FINISHED_VALUE; } break; case Yytoken.TYPE_LEFT_BRACE: if (firstCharType == Yytoken.TYPE_LEFT_BRACE) { numUnmatchedCharTypeCount++; } val = (List) valueStack.getFirst(); Map newObject = createObjectContainer(containerFactory); val.add(newObject); status = S_IN_OBJECT; statusStack.addFirst(new Integer(status)); valueStack.addFirst(newObject); break; case Yytoken.TYPE_LEFT_SQUARE: if (firstCharType == Yytoken.TYPE_LEFT_SQUARE) { numUnmatchedCharTypeCount++; } val = (List) valueStack.getFirst(); List newArray = createArrayContainer(containerFactory); val.add(newArray); status = S_IN_ARRAY; statusStack.addFirst(new Integer(status)); valueStack.addFirst(newArray); break; default: status = S_IN_ERROR; }//inner switch break; case S_IN_ERROR: throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); }//switch if (status == S_IN_ERROR) { throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); } } while (token.type != Yytoken.TYPE_EOF); } catch (IOException ie) { throw ie; } throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token); }
From source file:vnreal.algorithms.utils.SubgraphBasicVN.MyDijkstraShortestPath.java
/** * Returns a <code>List</code> of the edges on the shortest path from * <code>source</code> to <code>target</code>, in order of their * occurrence on this path./* w w w .j av a2 s. co m*/ * If either vertex is not in the graph for which this instance * was created, throws <code>IllegalArgumentException</code>. * * @param epsilon max path length */ public LinkedList<E> getPath(V source, V target, int epsilon) { if (!g.containsVertex(source)) throw new IllegalArgumentException("Specified source vertex " + source + " is not part of graph " + g); if (!g.containsVertex(target)) throw new IllegalArgumentException("Specified target vertex " + target + " is not part of graph " + g); LinkedList<E> path = new LinkedList<E>(); // collect path data; must use internal method rather than // calling getIncomingEdge() because getIncomingEdge() may // wipe out results if results are not cached Set<V> targets = new HashSet<V>(); targets.add(target); singleSourceShortestPath(source, targets, g.getVertexCount()); Map<V, E> incomingEdges = ((SourcePathData) sourceMap.get(source)).incomingEdges; if (incomingEdges.isEmpty() || incomingEdges.get(target) == null) { return null; } V current = target; while (!current.equals(source)) { E incoming = incomingEdges.get(current); path.addFirst(incoming); current = ((Graph<V, E>) g).getOpposite(current, incoming); } if (epsilon != -1 && path.size() > epsilon) { return null; } Double d = getDistance(source, target).doubleValue(); if (d == Double.POSITIVE_INFINITY) { return null; } return path; }