List of usage examples for java.util LinkedList addLast
public void addLast(E e)
From source file:ubic.gemma.datastructure.matrix.ExpressionDataMatrixColumnSort.java
/** * @param start/* ww w .ja va 2 s.co m*/ * @param factorsToUse * @return list of factors, sorted from simplest (fewest number of values from the biomaterials passed in) to least * simple */ public static List<ExperimentalFactor> orderFactorsByExperimentalDesign(List<BioMaterial> start, Collection<ExperimentalFactor> factors) { if (factors == null || factors.isEmpty()) { log.warn("No factors supplied for sorting"); return new LinkedList<ExperimentalFactor>(); } LinkedList<ExperimentalFactor> sortedFactors = new LinkedList<ExperimentalFactor>(); Collection<ExperimentalFactor> factorsToTake = new HashSet<ExperimentalFactor>(factors); while (!factorsToTake.isEmpty()) { ExperimentalFactor simplest = chooseSimplestFactor(start, factorsToTake); if (simplest == null) { // none of the factors have more than one factor value. One-sided t-tests ... /* * This assertion isn't right -- we now allow this, though we can only have ONE such constant factor. * See bug 2390. Unless we are dealing with a subset, in which case there can be any number of constant * factors within the subset. */ // assert factors.size() == 1 : // "It's possible to have just one factor value, but only if there is only one factor."; sortedFactors.addAll(factors); return sortedFactors; } sortedFactors.addLast(simplest); factorsToTake.remove(simplest); } return sortedFactors; }
From source file:ubic.gemma.datastructure.matrix.ExpressionDataMatrixColumnSort.java
/** * @param start//from w w w. j av a 2s . c o m * @param factorsToUse * @return list of factors, sorted from simplest (fewest number of values from the biomaterials passed in) to least * simple */ public static List<ExperimentalFactor> orderFactorsByExperimentalDesignVO(List<BioMaterialValueObject> start, Collection<ExperimentalFactor> factors) { if (factors == null || factors.isEmpty()) { log.warn("No factors supplied for sorting"); return new LinkedList<ExperimentalFactor>(); } LinkedList<ExperimentalFactor> sortedFactors = new LinkedList<ExperimentalFactor>(); Collection<ExperimentalFactor> factorsToTake = new HashSet<ExperimentalFactor>(factors); while (!factorsToTake.isEmpty()) { ExperimentalFactor simplest = chooseSimplestFactorVO(start, factorsToTake); if (simplest == null) { // none of the factors have more than one factor value. One-sided t-tests ... /* * This assertion isn't right -- we now allow this, though we can only have ONE such constant factor. * See bug 2390. Unless we are dealing with a subset, in which case there can be any number of constant * factors within the subset. */ // assert factors.size() == 1 : // "It's possible to have just one factor value, but only if there is only one factor."; sortedFactors.addAll(factors); return sortedFactors; } sortedFactors.addLast(simplest); factorsToTake.remove(simplest); } return sortedFactors; }
From source file:com.zimbra.cs.imap.ImapMessage.java
static void serializeStructure(PrintStream ps, MimeMessage root, boolean extensions) throws IOException, MessagingException { LinkedList<LinkedList<MPartInfo>> queue = new LinkedList<LinkedList<MPartInfo>>(); LinkedList<MPartInfo> level = new LinkedList<MPartInfo>(); level.add(Mime.getParts(root).get(0)); queue.add(level);/*from w w w. java 2 s . c o m*/ boolean pop = false; while (!queue.isEmpty()) { level = queue.getLast(); if (level.isEmpty()) { queue.removeLast(); pop = true; continue; } MPartInfo mpi = level.getFirst(); MimePart mp = mpi.getMimePart(); boolean hasChildren = mpi.getChildren() != null && !mpi.getChildren().isEmpty(); // we used to force unset charsets on text/plain parts to US-ASCII, but that always seemed unwise... ContentType ctype = new ContentType(mp.getHeader("Content-Type", null)) .setContentType(mpi.getContentType()); String primary = nATOM(ctype.getPrimaryType()), subtype = nATOM(ctype.getSubType()); if (!pop) ps.write('('); if (primary.equals("\"MULTIPART\"")) { if (!pop) { // 7.4.2: "Multiple parts are indicated by parenthesis nesting. Instead of a body type // as the first element of the parenthesized list, there is a sequence of one // or more nested body structures. The second element of the parenthesized // list is the multipart subtype (mixed, digest, parallel, alternative, etc.)." if (!hasChildren) { ps.print("NIL"); } else { queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren())); continue; } } ps.write(' '); ps.print(subtype); if (extensions) { // 7.4.2: "Extension data follows the multipart subtype. Extension data is never // returned with the BODY fetch, but can be returned with a BODYSTRUCTURE // fetch. Extension data, if present, MUST be in the defined order. The // extension data of a multipart body part are in the following order: // body parameter parenthesized list, body disposition, body language, // body location" ps.write(' '); nparams(ps, ctype); ps.write(' '); ndisposition(ps, mp.getHeader("Content-Disposition", null)); ps.write(' '); nlist(ps, mp.getContentLanguage()); ps.write(' '); nstring(ps, mp.getHeader("Content-Location", null)); } } else { if (!pop) { // 7.4.2: "The basic fields of a non-multipart body part are in the following order: // body type, body subtype, body parameter parenthesized list, body id, body // description, body encoding, body size." String cte = mp.getEncoding(); cte = (cte == null || cte.trim().equals("") ? "7bit" : cte); aSTRING(ps, ctype.getPrimaryType()); ps.write(' '); aSTRING(ps, ctype.getSubType()); ps.write(' '); nparams(ps, ctype); ps.write(' '); nstring(ps, mp.getContentID()); ps.write(' '); nstring2047(ps, mp.getDescription()); ps.write(' '); aSTRING(ps, cte); ps.write(' '); ps.print(Math.max(mp.getSize(), 0)); } boolean rfc822 = primary.equals("\"MESSAGE\"") && subtype.equals("\"RFC822\""); if (rfc822) { // 7.4.2: "A body type of type MESSAGE and subtype RFC822 contains, immediately // after the basic fields, the envelope structure, body structure, and // size in text lines of the encapsulated message." if (!pop) { if (!hasChildren) { ps.print(" NIL NIL"); } else { MimeMessage mm = (MimeMessage) mpi.getChildren().get(0).getMimePart(); ps.write(' '); serializeEnvelope(ps, mm); ps.write(' '); queue.addLast(new LinkedList<MPartInfo>(mpi.getChildren())); continue; } } ps.write(' '); ps.print(getLineCount(mp)); } else if (primary.equals("\"TEXT\"")) { // 7.4.2: "A body type of type TEXT contains, immediately after the basic fields, the // size of the body in text lines. Note that this size is the size in its // content transfer encoding and not the resulting size after any decoding." ps.write(' '); ps.print(getLineCount(mp)); } if (extensions) { // 7.4.2: "Extension data follows the basic fields and the type-specific fields // listed above. Extension data is never returned with the BODY fetch, // but can be returned with a BODYSTRUCTURE fetch. Extension data, if // present, MUST be in the defined order. The extension data of a // non-multipart body part are in the following order: body MD5, body // disposition, body language, body location" ps.write(' '); nstring(ps, mp.getContentMD5()); ps.write(' '); ndisposition(ps, mp.getHeader("Content-Disposition", null)); ps.write(' '); nlist(ps, mp.getContentLanguage()); ps.write(' '); nstring(ps, mp.getHeader("Content-Location", null)); } } ps.write(')'); level.removeFirst(); pop = false; } }
From source file:net.cliseau.composer.javacor.MissingToolException.java
/** * Compiles the unit startup file from Java source to Java bytecode. * * This compiles the startup file. During this process, multiple class files * may be generated even though only a single input file to compile is * specified. The reason for this is that classes other than the main class * may be defined in the single file and are written to distinct class * files. All created files are collected and returned by the method. * * @param startupFile The file to be compiled. * @param startupDependencies Names of classpath entries to use for compilation. * @return List of names of created (class) files during compilation. * @exception UnitGenerationException Thrown when finding a Java compiler failed. *//* ww w.j ava 2 s. c om*/ private LinkedList<String> compile(final File startupFile, final Collection<String> startupDependencies) throws MissingToolException, InvalidConfigurationException { // code inspired by the examples at // http://docs.oracle.com/javase/6/docs/api/javax/tools/JavaCompiler.html final LinkedList<String> createdFiles = new LinkedList<String>(); // set the file manager, which records the written files JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); if (compiler == null) { throw new MissingToolException("Could not find system Java compiler."); } StandardJavaFileManager stdFileManager = compiler.getStandardFileManager(null, null, null); JavaFileManager fileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(stdFileManager) { /** * Collect the list of all output (class) files. * * Besides its side-effect on the createdFiles list of the containing * method, this method is functionally equivalent to its superclass * version. */ public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException { JavaFileObject fileForOutput = super.getJavaFileForOutput(location, className, kind, sibling); createdFiles.addLast(fileForOutput.getName()); return fileForOutput; } }; // set the files to compile Iterable<? extends JavaFileObject> compilationUnits = stdFileManager .getJavaFileObjectsFromFiles(Arrays.asList(startupFile)); // do the actual compilation ArrayList<String> compileParams = new ArrayList<String>(2); boolean verbose = org.apache.log4j.Level.DEBUG.isGreaterOrEqual(config.getInstantiationLogLevel()); if (verbose) compileParams.add("-verbose"); compileParams .addAll(Arrays.asList("-classpath", StringUtils.join(startupDependencies, File.pathSeparator))); if (!compiler.getTask(null, fileManager, null, compileParams, null, compilationUnits).call()) { // could not compile all files without error //TODO: throw an exception ... see where to get the required information from } return createdFiles; }
From source file:org.guzz.builder.GuzzConfigFileBuilder.java
/** * annotated/*ww w .j a v a2s . co m*/ * @throws Exception * @return List (@link POJOBasedObjectMapping) */ public List listAnnotatedBusinessObjectMappings() throws Exception { /* <a-business name="user" class="org.guzz.test.User"/> */ LinkedList mappings = new LinkedList(); List bus = this.rootDoc.selectNodes("a-business"); for (int i = 0; i < bus.size(); i++) { Element e = (Element) bus.get(i); String m_name = e.attributeValue("name"); String m_dbgroup = e.attributeValue("dbgroup"); String m_class = e.attributeValue("class"); if (StringUtil.isEmpty(m_class)) { throw new GuzzException("domain class name not found. xml:[" + e.asXML() + "]"); } POJOBasedObjectMapping map = JPA2AnnotationsBuilder.parseDomainClass(gf, m_dbgroup, m_name, Class.forName(m_class)); mappings.addLast(map); } return mappings; }
From source file:com.jaspersoft.studio.property.section.style.StylesListSection.java
/** * Build the hierarchy of styles of an element * /*from w ww . j a v a 2 s . c o m*/ * @param element * Element from which the styles list will be generated * @return A list of MStyle, where the first is the style assigned to the element, the second is the style assigned to * the first item of the list and so on */ private LinkedList<MStyle> buildStylesGerarchy(APropertyNode element) { LinkedList<MStyle> result = new LinkedList<MStyle>(); Object styleKey; if (element instanceof MConditionalStyle) { //The external style dosen't allow a conditional style, so the parent must be a jrstyle styleKey = ((MStyle) element.getParent()).getValue(); } else { styleKey = getStyleKey(element); } StyleContainer styleContainer = styleMaps.get(styleKey); if (styleContainer != null) { MStyle styleModel = styleContainer.getStyle(); result.addLast(styleModel); Object nextStylKey = getStyleKey(styleModel); while (nextStylKey != null) { styleModel = styleMaps.get(nextStylKey).getStyle(); result.addLast(styleModel); nextStylKey = getStyleKey(styleModel); } } return result; }
From source file:org.gephi.statistics.plugin.ConnectedComponents.java
public void weaklyConnected(HierarchicalUndirectedGraph hgraph, AttributeModel attributeModel) { isCanceled = false;/* w w w . ja v a2 s. c o m*/ componentCount = 0; AttributeTable nodeTable = attributeModel.getNodeTable(); AttributeColumn componentCol = nodeTable.getColumn(WEAKLY); if (componentCol == null) { componentCol = nodeTable.addColumn(WEAKLY, "Component ID", AttributeType.INT, AttributeOrigin.COMPUTED, new Integer(0)); } List<Integer> sizeList = new ArrayList<Integer>(); hgraph.readLock(); HashMap<Node, Integer> indicies = new HashMap<Node, Integer>(); int index = 0; for (Node s : hgraph.getNodes()) { indicies.put(s, index); index++; } int N = hgraph.getNodeCount(); //Keep track of which nodes have been seen int[] color = new int[N]; Progress.start(progress, hgraph.getNodeCount()); int seenCount = 0; while (seenCount < N) { //The search Q LinkedList<Node> Q = new LinkedList<Node>(); //The component-list LinkedList<Node> component = new LinkedList<Node>(); //Seed the seach Q NodeIterable iter = hgraph.getNodes(); for (Node first : iter) { if (color[indicies.get(first)] == 0) { Q.add(first); iter.doBreak(); break; } } //While there are more nodes to search while (!Q.isEmpty()) { if (isCanceled) { hgraph.readUnlock(); return; } //Get the next Node and add it to the component list Node u = Q.removeFirst(); component.add(u); //Iterate over all of u's neighbors EdgeIterable edgeIter = hgraph.getEdgesAndMetaEdges(u); //For each neighbor for (Edge edge : edgeIter) { Node reachable = hgraph.getOpposite(u, edge); int id = indicies.get(reachable); //If this neighbor is unvisited if (color[id] == 0) { color[id] = 1; //Add it to the search Q Q.addLast(reachable); //Mark it as used Progress.progress(progress, seenCount); } } color[indicies.get(u)] = 2; seenCount++; } for (Node s : component) { AttributeRow row = (AttributeRow) s.getNodeData().getAttributes(); row.setValue(componentCol, componentCount); } sizeList.add(component.size()); componentCount++; } hgraph.readUnlock(); componentsSize = new int[sizeList.size()]; for (int i = 0; i < sizeList.size(); i++) { componentsSize[i] = sizeList.get(i); } }
From source file:net.jenet.Host.java
Event dispatchIncomingCommands() { Event result = new Event(); Peer currentPeer;//from w w w .j a va 2 s. c o m LinkedList<Peer> peersList = new LinkedList<Peer>(peers.values()); if (peers.size() == 0) return result; /* * Simply calling containsKey( lastServicedPeer.getIncomingPeerId() ) will * not be sufficient because the peerID of lastServicedPeer may have been * reassigned. The get operation is quicker than containsValue because * it does not have to search through all the peers. * * lastServicedPeer.isDisconnected() may be sufficient, but this feels more robust. */ if (lastServicedPeer == null || peers.get(lastServicedPeer.getIncomingPeerID()) != lastServicedPeer) lastServicedPeer = peersList.getFirst(); else while (peersList.getLast() != lastServicedPeer) peersList.addLast(peersList.removeFirst()); do { currentPeer = peersList.removeFirst(); peersList.addLast(currentPeer); if (currentPeer.isZombie()) { recalculateBandwithLimits = true; currentPeer.reset(); result.setType(Event.TYPE.DISCONNECTED); result.setPeer(currentPeer); lastServicedPeer = currentPeer; return result; } if (!currentPeer.isConnected()) continue; for (byte channelID : currentPeer.getChannels().keySet()) { Channel channel = currentPeer.getChannels().get(channelID); if (channel.getIncomingReliableCommands().isEmpty() && channel.getIncomingUnreliableCommands().isEmpty()) continue; Packet packet = currentPeer.receive(channelID); result.setPacket(packet); if (packet == null) continue; result.setType(Event.TYPE.RECEIVED); result.setPeer(currentPeer); result.setChannelID(channelID); result.setPacket(packet); lastServicedPeer = currentPeer; return result; } } while (currentPeer != lastServicedPeer); return result; }
From source file:com.oltpbenchmark.benchmarks.auctionmark.AuctionMarkProfile.java
private boolean addItem(LinkedList<ItemInfo> items, ItemInfo itemInfo) { boolean added = false; int idx = items.indexOf(itemInfo); if (idx != -1) { // HACK: Always swap existing ItemInfos with our new one, since it will // more up-to-date information ItemInfo existing = items.set(idx, itemInfo); assert (existing != null); return (true); }/* w w w .ja v a 2 s . c o m*/ if (itemInfo.hasCurrentPrice()) assert (itemInfo.getCurrentPrice() > 0) : "Negative current price for " + itemInfo; // If we have room, shove it right in // We'll throw it in the back because we know it hasn't been used yet if (items.size() < AuctionMarkConstants.ITEM_ID_CACHE_SIZE) { items.addLast(itemInfo); added = true; // Otherwise, we can will randomly decide whether to pop one out } else if (this.rng.nextBoolean()) { items.pop(); items.addLast(itemInfo); added = true; } return (added); }
From source file:org.commonjava.maven.atlas.spi.jung.effective.JungEGraphDriver.java
private void dfsIterate(final ProjectVersionRef node, final ProjectNetTraversal traversal, final LinkedList<ProjectRelationship<?>> path, final int pass) { final List<ProjectRelationship<?>> edges = getSortedOutEdges(node); if (edges != null) { for (final ProjectRelationship<?> edge : edges) { if (traversal.traverseEdge(edge, path, pass)) { if (!(edge instanceof ParentRelationship) || !((ParentRelationship) edge).isTerminus()) { ProjectVersionRef target = edge.getTarget(); if (target instanceof ArtifactRef) { target = ((ArtifactRef) target).asProjectVersionRef(); }// w w w. java 2s .c om // FIXME: Are there cases where a traversal needs to see cycles?? boolean cycle = false; for (final ProjectRelationship<?> item : path) { if (item.getDeclaring().equals(target)) { cycle = true; break; } } if (!cycle) { path.addLast(edge); dfsIterate(target, traversal, path, pass); path.removeLast(); } } traversal.edgeTraversed(edge, path, pass); } } } }