List of usage examples for java.util LinkedList get
public E get(int index)
From source file:org.exoplatform.social.common.xmlprocessor.filters.URLConverterFilterPlugin.java
private int nodeFilter(Node currentNode) { LinkedList<Node> currentChildNode = currentNode.getChildNodes(); if (currentNode.getTitle().isEmpty()) { int insertedCount = convertNode(currentNode); if (insertedCount > 0) { return insertedCount; }/*from w ww . ja v a 2 s .c o m*/ } for (int i = 0; i < currentChildNode.size(); i++) { if (!currentChildNode.get(i).getTitle().equals("a")) { int insertedCount = nodeFilter(currentChildNode.get(i)); if (insertedCount > 0) { i = i + insertedCount; } } } return 0; }
From source file:org.apache.hadoop.hdfs.TestExternalBlockReader.java
@Test public void testExternalBlockReader() throws Exception { Configuration conf = new Configuration(); conf.set(HdfsClientConfigKeys.REPLICA_ACCESSOR_BUILDER_CLASSES_KEY, SyntheticReplicaAccessorBuilder.class.getName()); conf.setLong(HdfsClientConfigKeys.DFS_BLOCK_SIZE_KEY, 1024); conf.setLong(DFSConfigKeys.DFS_NAMENODE_MIN_BLOCK_SIZE_KEY, 0); String uuid = UUID.randomUUID().toString(); conf.set(SYNTHETIC_BLOCK_READER_TEST_UUID_KEY, uuid); MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf) .hosts(new String[] { NetUtils.getLocalHostname() }).build(); final int TEST_LENGTH = 2047; DistributedFileSystem dfs = cluster.getFileSystem(); try {//w w w. j a va 2 s . c om DFSTestUtil.createFile(dfs, new Path("/a"), TEST_LENGTH, (short) 1, SEED); HdfsDataInputStream stream = (HdfsDataInputStream) dfs.open(new Path("/a")); byte buf[] = new byte[TEST_LENGTH]; stream.seek(1000); IOUtils.readFully(stream, buf, 1000, TEST_LENGTH - 1000); stream.seek(0); IOUtils.readFully(stream, buf, 0, 1000); byte expected[] = DFSTestUtil.calculateFileContentsFromSeed(SEED, TEST_LENGTH); ReadStatistics stats = stream.getReadStatistics(); Assert.assertEquals(1024, stats.getTotalShortCircuitBytesRead()); Assert.assertEquals(2047, stats.getTotalLocalBytesRead()); Assert.assertEquals(2047, stats.getTotalBytesRead()); Assert.assertArrayEquals(expected, buf); stream.close(); ExtendedBlock block = DFSTestUtil.getFirstBlock(dfs, new Path("/a")); Assert.assertNotNull(block); LinkedList<SyntheticReplicaAccessor> accessorList = accessors.get(uuid); Assert.assertNotNull(accessorList); Assert.assertEquals(3, accessorList.size()); SyntheticReplicaAccessor accessor = accessorList.get(0); Assert.assertTrue(accessor.builder.allowShortCircuit); Assert.assertEquals(block.getBlockPoolId(), accessor.builder.blockPoolId); Assert.assertEquals(block.getBlockId(), accessor.builder.blockId); Assert.assertEquals(dfs.getClient().clientName, accessor.builder.clientName); Assert.assertEquals("/a", accessor.builder.fileName); Assert.assertEquals(block.getGenerationStamp(), accessor.getGenerationStamp()); Assert.assertTrue(accessor.builder.verifyChecksum); Assert.assertEquals(1024L, accessor.builder.visibleLength); Assert.assertEquals(24L, accessor.totalRead); Assert.assertEquals("", accessor.getError()); Assert.assertEquals(1, accessor.numCloses); byte[] tempBuf = new byte[5]; Assert.assertEquals(-1, accessor.read(TEST_LENGTH, tempBuf, 0, 0)); Assert.assertEquals(-1, accessor.read(TEST_LENGTH, tempBuf, 0, tempBuf.length)); accessors.remove(uuid); } finally { dfs.close(); cluster.shutdown(); } }
From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolatorSimple.java
protected void interpolateSurface(LinkedList<Point3d> points) throws InterruptedException { double pixSize = Magellan.getCore().getPixelSizeUm(); //provide interpolator with current list of data points Point_dt triangulationPoints[] = new Point_dt[points.size()]; for (int i = 0; i < points.size(); i++) { triangulationPoints[i] = new Point_dt(points.get(i).x, points.get(i).y, points.get(i).z); }/* w ww . j a va2 s .c om*/ Delaunay_Triangulation dTri = new Delaunay_Triangulation(triangulationPoints); int maxPixelDimension = (int) (Math.max(boundXMax_ - boundXMin_, boundYMax_ - boundYMin_) / pixSize); //Start with at least 20 interp points and go smaller and smaller until every pixel interped? int pixelsPerInterpPoint = 1; while (maxPixelDimension / (pixelsPerInterpPoint + 1) > 20) { pixelsPerInterpPoint *= 2; } if (Thread.interrupted()) { throw new InterruptedException(); } while (pixelsPerInterpPoint >= MIN_PIXELS_PER_INTERP_POINT) { int numInterpPointsX = (int) (((boundXMax_ - boundXMin_) / pixSize) / pixelsPerInterpPoint); int numInterpPointsY = (int) (((boundYMax_ - boundYMin_) / pixSize) / pixelsPerInterpPoint); double dx = (boundXMax_ - boundXMin_) / (numInterpPointsX - 1); double dy = (boundYMax_ - boundYMin_) / (numInterpPointsY - 1); float[][] interpVals = new float[numInterpPointsY][numInterpPointsX]; float[][] interpNormals = new float[numInterpPointsY][numInterpPointsX]; boolean[][] interpDefined = new boolean[numInterpPointsY][numInterpPointsX]; for (int yInd = 0; yInd < interpVals.length; yInd++) { for (int xInd = 0; xInd < interpVals[0].length; xInd++) { if (Thread.interrupted()) { throw new InterruptedException(); } double xVal = boundXMin_ + dx * xInd; double yVal = boundYMin_ + dy * yInd; boolean inHull = convexHullRegion_ .checkPoint(new Vector2D(xVal, yVal)) == Region.Location.INSIDE; if (inHull) { Triangle_dt tri = dTri.find(new Point_dt(xVal, yVal)); //convert to apache commons coordinates to make a plane Vector3D v1 = new Vector3D(tri.p1().x(), tri.p1().y(), tri.p1().z()); Vector3D v2 = new Vector3D(tri.p2().x(), tri.p2().y(), tri.p2().z()); Vector3D v3 = new Vector3D(tri.p3().x(), tri.p3().y(), tri.p3().z()); Plane plane = new Plane(v1, v2, v3, TOLERANCE); //intersetion of vertical line at these x+y values with plane gives point in plane Vector3D pointInPlane = plane.intersection( new Line(new Vector3D(xVal, yVal, 0), new Vector3D(xVal, yVal, 1), TOLERANCE)); float zVal = (float) pointInPlane.getZ(); interpVals[yInd][xInd] = zVal; float angle = (float) (Vector3D.angle(plane.getNormal(), new Vector3D(0, 0, 1)) / Math.PI * 180.0); interpNormals[yInd][xInd] = angle; interpDefined[yInd][xInd] = true; } else { interpDefined[yInd][xInd] = false; } } } if (Thread.interrupted()) { throw new InterruptedException(); } synchronized (interpolationLock_) { currentInterpolation_ = new SingleResolutionInterpolation(pixelsPerInterpPoint, interpDefined, interpVals, interpNormals, boundXMin_, boundXMax_, boundYMin_, boundYMax_, convexHullRegion_, convexHullVertices_, getPoints()); interpolationLock_.notifyAll(); } // System.gc(); pixelsPerInterpPoint /= 2; } }
From source file:representation.Generator.java
/** * Generate AST*.java files.//from ww w . ja v a 2 s .com */ private void createASTTreeNodeFiles() { for (final String node : astNodes.keySet()) { final Integer numArguments = astNodes.get(node).size(); final LinkedList<String> types = astNodes.get(node); // constructor args String argsString = ""; for (int i = 0; i < numArguments; i++) { argsString += types.get(i).equals("n") ? "AST node" + i + ", " : "Token node" + i + ", "; } if (argsString.length() > 2) { argsString = argsString.substring(0, argsString.length() - 2); } // fields String fieldsString = ""; for (int i = 0; i < numArguments; i += 1) { fieldsString += types.get(i).equals("n") ? "private AST node" + i + ";\n" : "private Token node" + i + ";\n"; } // constructor content String constructorContent = ""; for (int i = 0; i < numArguments; i += 1) { constructorContent += "this.node" + i + " = node" + i + ";\n"; } final String filename = "AST" + node + ".java"; createFile("src/main/java/", filename, "Empty"); appendFile("src/main/java/", filename, "public class AST" + node + " implements AST {\n"); appendFile("src/main/java/", filename, fieldsString); appendFile("src/main/java/", filename, "public AST" + node + "(" + argsString + ") {\n"); appendFile("src/main/java/", filename, constructorContent); appendFile("src/main/java/", filename, "}\n"); appendFile("src/main/java/", filename, "}\n"); } }
From source file:org.openmeetings.app.remote.ChatService.java
public LinkedList<LinkedList<String>> getAllPublicEmoticons() { try {//from ww w . ja v a 2s.co m LinkedList<LinkedList<String>> publicemotes = new LinkedList<LinkedList<String>>(); LinkedList<LinkedList<String>> allEmotes = EmoticonsManager.getEmotfilesList(); for (Iterator<LinkedList<String>> iter = allEmotes.iterator(); iter.hasNext();) { LinkedList<String> emot = iter.next(); LinkedList<String> emotPub = new LinkedList<String>(); if (emot.get((emot.size() - 1)).equals("y")) { emotPub.add(emot.get(0)); emotPub.add(emot.get(1).replace("\\", "")); if (emot.size() > 4) { emotPub.add(emot.get(2).replace("\\", "")); emotPub.add(emot.get(3)); emotPub.add(emot.get(4)); } else { emotPub.add(emot.get(2)); emotPub.add(emot.get(3)); } publicemotes.add(emotPub); } } return publicemotes; } catch (Exception err) { log.error("[getAllPublicEmoticons] ", err); return null; } }
From source file:com.commander4j.util.JUtility.java
public static JHost getFirtActiveHost() { JHost hst = new JHost(); LinkedList<JHost> temp = Common.hostList.getHosts(); for (int j = 0; j < temp.size(); j++) { hst = (JHost) temp.get(j); if (hst.getEnabled().equals("Y")) { if (hst.getDatabaseParameters().getjdbcDriver().equals("http") == false) { return hst; }// w w w . j a va 2s. co m } } return hst; }
From source file:com.commander4j.util.JUtility.java
public static int getActiveHostCount() { int result = 0; JHost hst = new JHost(); LinkedList<JHost> temp = Common.hostList.getHosts(); for (int j = 0; j < temp.size(); j++) { hst = (JHost) temp.get(j); if (hst.getEnabled().equals("Y")) { if (hst.getDatabaseParameters().getjdbcDriver().equals("http") == false) { result++;/*from w w w . jav a 2 s.c om*/ } } } return result; }
From source file:com.zimbra.cs.fb.ExchangeMessage.java
private void encodeIntervals(Iterable<Interval> fb, long startMonth, long endMonth, String type, Element months, Element events, IntervalList consolidated) { HashMap<Long, LinkedList<Byte>> fbMap = new HashMap<Long, LinkedList<Byte>>(); for (long i = startMonth; i <= endMonth; i++) fbMap.put(i, new LinkedList<Byte>()); for (FreeBusy.Interval interval : fb) { String status = interval.getStatus(); if (status.equals(type)) { long start = interval.getStart(); long end = interval.getEnd(); long fbMonth = millisToMonths(start); LinkedList<Byte> buf = fbMap.get(fbMonth); encodeFb(start, end, buf);/* ww w . ja v a2 s .co m*/ if (consolidated != null) consolidated.addInterval(new Interval(start, end, IcalXmlStrMap.FBTYPE_BUSY)); } } for (long m = startMonth; m <= endMonth; m++) { String buf = ""; LinkedList<Byte> encodedList = fbMap.get(m); if (encodedList.size() > 0) { try { byte[] raw = new byte[encodedList.size()]; for (int i = 0; i < encodedList.size(); i++) raw[i] = encodedList.get(i).byteValue(); byte[] encoded = Base64.encodeBase64(raw); buf = new String(encoded, "UTF-8"); } catch (IOException e) { ZimbraLog.fb.warn("error converting millis to minutes for month " + m, e); continue; } } addElement(months, EL_V, Long.toString(m)); addElement(events, EL_V, buf); } }
From source file:org.drugis.mtc.graph.MinimumDiameterSpanningTree.java
private void addPath(DelegateTree<V, E> tree, V u, V v) { Map<V, E> incomingEdgeMap = d_shortestPath.getIncomingEdgeMap(u); LinkedList<V> path = new LinkedList<V>(); while (!v.equals(u)) { path.addFirst(v);/* w ww . j a v a2 s . com*/ E e = incomingEdgeMap.get(v); List<V> incidentVertices = new ArrayList<V>(d_graph.getIncidentVertices(e)); v = incidentVertices.get(0).equals(v) ? incidentVertices.get(1) : incidentVertices.get(0); } path.addFirst(u); for (int i = 0; i < path.size() - 1; ++i) { E e = d_graph.findEdge(path.get(i), path.get(i + 1)); if (!tree.containsEdge(e)) { tree.addChild(e, path.get(i), path.get(i + 1)); } } }
From source file:com.stimulus.archiva.domain.Volumes.java
public synchronized void setVolumePriority(int id, Priority priority) { LinkedList<Volume> list = volumes; Volume v = list.get(id); if (v.getStatus() != Volume.Status.UNUSED) // can only reorder unused return;//from ww w . ja v a2 s . co m if (priority == Priority.PRIORITY_HIGHER && id - 1 >= 0) { // cannot affect non unused vols Volume vs = list.get(id - 1); if (vs.getStatus() != Volume.Status.UNUSED) return; } list.remove(v); switch (priority) { case PRIORITY_HIGHER: if ((id - 1) <= 0) list.addFirst(v); else list.add(id - 1, v); break; case PRIORITY_LOWER: if ((id + 1) >= list.size()) list.addLast(v); else list.add(id + 1, v); break; } }