List of usage examples for java.util List listIterator
ListIterator<E> listIterator();
From source file:playground.christoph.evacuation.analysis.EvacuationTimePictureWriter.java
private ScreenOverlayType createHistogram(String transportMode, Map<Id, Double> evacuationTimes) throws IOException { /*//from w w w . j av a 2 s . co m * Remove NaN entries from the List */ List<Double> listWithoutNaN = new ArrayList<Double>(); for (Double d : evacuationTimes.values()) if (!d.isNaN()) listWithoutNaN.add(d); /* * If trip with significant to high evacuation times should be cut off */ if (limitMaxEvacuationTime) { double cutOffValue = meanEvacuationTime + standardDeviation * evacuationTimeCutOffFactor; ListIterator<Double> iter = listWithoutNaN.listIterator(); while (iter.hasNext()) { double value = iter.next(); if (value > cutOffValue) iter.remove(); } } double[] array = new double[listWithoutNaN.size()]; int i = 0; for (double d : listWithoutNaN) array[i++] = d; JFreeChart chart = createHistogramChart(transportMode, array); BufferedImage chartImage = chart.createBufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT); BufferedImage image = new BufferedImage(OVERALLHISTOGRAMWIDTH, OVERALLHISTOGRAMHEIGHT, BufferedImage.TYPE_4BYTE_ABGR); // clone image and set alpha value for (int x = 0; x < OVERALLHISTOGRAMWIDTH; x++) { for (int y = 0; y < OVERALLHISTOGRAMHEIGHT; y++) { int rgb = chartImage.getRGB(x, y); Color c = new Color(rgb); int r = c.getRed(); int b = c.getBlue(); int g = c.getGreen(); int argb = 225 << 24 | r << 16 | g << 8 | b; // 225 as transparency value image.setRGB(x, y, argb); } } byte[] imageBytes = bufferedImageToByteArray(image); this.kmzWriter.addNonKMLFile(imageBytes, transportMode + OVERALLHISTROGRAM); ScreenOverlayType overlay = kmlObjectFactory.createScreenOverlayType(); LinkType icon = kmlObjectFactory.createLinkType(); icon.setHref(transportMode + OVERALLHISTROGRAM); overlay.setIcon(icon); overlay.setName("Histogram " + transportMode); // place the image top right Vec2Type overlayXY = kmlObjectFactory.createVec2Type(); overlayXY.setX(0.0); overlayXY.setY(1.0); overlayXY.setXunits(UnitsEnumType.FRACTION); overlayXY.setYunits(UnitsEnumType.FRACTION); overlay.setOverlayXY(overlayXY); Vec2Type screenXY = kmlObjectFactory.createVec2Type(); screenXY.setX(0.02); screenXY.setY(0.98); screenXY.setXunits(UnitsEnumType.FRACTION); screenXY.setYunits(UnitsEnumType.FRACTION); overlay.setScreenXY(screenXY); return overlay; }
From source file:edu.unc.lib.dl.util.ContainerContentsHelper.java
/** * @param oldXML//from w ww . j a v a2 s . co m * @param container * @param children * @return */ public static Document addChildContentListInCustomOrder(Document oldXML, PID container, List<PID> children, Collection<PID> reorderedPids) { log.debug("HERE incoming children:"); for (int i = 0; i < children.size(); i++) { log.debug(i + " => " + children.get(i)); } // first build a list of existing pid order in the container Element parentDiv = oldXML.getRootElement().getChild("div", JDOMNamespaceUtil.METS_NS); List<Element> childDivs = parentDiv.getChildren(); int maxExistingOrder = 5; if (childDivs.size() > 0) { maxExistingOrder = Integer.parseInt(childDivs.get(childDivs.size() - 1).getAttributeValue("ORDER")); } ArrayList<PID> order = new ArrayList<PID>(maxExistingOrder); try { for (Element child : childDivs) { int ord = Integer.parseInt(child.getAttributeValue("ORDER")); PID pid = new PID(child.getAttributeValue("ID")); if (ord >= order.size()) { while (ord > order.size()) { // insert nulls order.add(null); } order.add(pid); } else { order.add(ord, pid); } } } catch (NullPointerException e) { throw new IllegalRepositoryStateException("Invalid container contents XML (MD_CONTENTS) on: ", e); } log.debug("HERE order before merge:"); for (int i = 0; i < order.size(); i++) { log.debug(i + " => " + order.get(i)); } PID[] originalOrder = order.toArray(new PID[0]); // clear out the current children parentDiv.removeContent(); int maxIncomingOrder = 0; if (children.size() > 0) { maxIncomingOrder = children.size() - 1; } int capacityEstimate = Math.max(maxIncomingOrder, maxExistingOrder) + 10; order.ensureCapacity(capacityEstimate); for (ListIterator<PID> foo = children.listIterator(); foo.hasNext();) { int ord = foo.nextIndex(); PID child = foo.next(); if (ord >= order.size()) { while (ord > order.size()) { // insert nulls order.add(null); } order.add(child); } else { order.add(ord, child); } } log.debug("HERE order after merge:"); for (int i = 0; i < order.size(); i++) { log.debug(i + " => " + order.get(i)); } for (int i = 0; i < originalOrder.length; i++) { PID orig = originalOrder[i]; if (orig != null) { if (!orig.equals(order.get(i))) { reorderedPids.add(orig); } } } for (ListIterator<PID> li = order.listIterator(); li.hasNext();) { int ord = li.nextIndex(); PID pid = li.next(); if (pid != null) { Element el = new Element("div", parentDiv.getNamespace()).setAttribute("ID", pid.getPid()) .setAttribute("ORDER", String.valueOf(ord)); parentDiv.addContent(el); } } return oldXML; }
From source file:com.taobao.adfs.database.tdhsocket.client.response.TDHSResutSet.java
public TDHSResutSet(List<String> fieldNames, List<TDHSResponseEnum.FieldType> fieldTypes, List<List<String>> fieldData) { if (fieldNames != null) { int i = 1; for (String f : fieldNames) { fieldMap.put(f, i++);/* w ww .ja v a 2 s. c om*/ } } if (fieldTypes != null) { this.fieldTypes = fieldTypes; } this.fieldData = fieldData; if (fieldData != null) { this.iterator = fieldData.listIterator(); } }
From source file:CopyOnWriteArrayList.java
/** * Compares the specified object with this list for equality. * Returns true if and only if the specified object is also a {@link * List}, both lists have the same size, and all corresponding pairs * of elements in the two lists are <em>equal</em>. (Two elements * <tt>e1</tt> and <tt>e2</tt> are <em>equal</em> if <tt>(e1==null ? * e2==null : e1.equals(e2))</tt>.) In other words, two lists are * defined to be equal if they contain the same elements in the same * order./*from w ww . j a va 2 s. co m*/ * * @param o the object to be compared for equality with this list * @return <tt>true</tt> if the specified object is equal to this list */ public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof List)) return false; List l2 = (List) (o); if (size() != l2.size()) return false; ListIterator e1 = listIterator(); ListIterator e2 = l2.listIterator(); while (e1.hasNext()) { if (!eq(e1.next(), e2.next())) return false; } return true; }
From source file:CopyOnWriteArrayList.java
/** * Compares the specified Object with this List for equality. Returns true * if and only if the specified Object is also a List, both Lists have the * same size, and all corresponding pairs of elements in the two Lists are * <em>equal</em>. (Two elements <code>e1</code> and <code>e2</code> * are <em>equal</em> if//from ww w .j a v a 2s. com * <code>(e1==null ? e2==null : e1.equals(e2))</code>.) In other words, * two Lists are defined to be equal if they contain the same elements in * the same order. * <p> * This implementation first checks if the specified object is this List. If * so, it returns true; if not, it checks if the specified object is a List. * If not, it returns false; if so, it iterates over both lists, comparing * corresponding pairs of elements. If any comparison returns false, this * method returns false. If either Iterator runs out of elements before * before the other it returns false (as the Lists are of unequal length); * otherwise it returns true when the iterations complete. * * @param o * the Object to be compared for equality with this List. * @return true if the specified Object is equal to this List. */ public boolean equals(Object o) { if (o == this) return true; if (!(o instanceof List)) return false; List l2 = (List) (o); if (size() != l2.size()) return false; ListIterator e1 = listIterator(); ListIterator e2 = l2.listIterator(); while (e1.hasNext()) { Object o1 = e1.next(); Object o2 = e2.next(); if (!(o1 == null ? o2 == null : o1.equals(o2))) return false; } return true; }
From source file:com.verisignlabs.dnssec.cl.ZoneFormat.java
private static void determineNSEC3Owners(List<Record> zone) throws NoSuchAlgorithmException { // Put the zone into a consistent (name and RR type) order. Collections.sort(zone, new RecordComparator()); // first, find the NSEC3PARAM record -- this is an inefficient linear // search, although it should be near the head of the list. NSEC3PARAMRecord nsec3param = null;/*w w w .j ava 2s. c om*/ HashMap<String, String> map = new HashMap<String, String>(); base32 b32 = new base32(base32.Alphabet.BASE32HEX, false, true); Name zonename = null; for (Record r : zone) { if (r.getType() == Type.SOA) { zonename = r.getName(); continue; } if (r.getType() == Type.NSEC3PARAM) { nsec3param = (NSEC3PARAMRecord) r; break; } } // If we couldn't determine a zone name, we have an issue. if (zonename == null) return; // If there wasn't one, we have nothing to do. if (nsec3param == null) return; // Next pass, calculate a mapping between ownernames and hashnames Name last_name = null; for (Record r : zone) { if (r.getName().equals(last_name)) continue; if (r.getType() == Type.NSEC3) continue; Name n = r.getName(); byte[] hash = nsec3param.hashName(n); String hashname = b32.toString(hash); map.put(hashname, n.toString().toLowerCase()); last_name = n; // inefficiently create hashes for the possible ancestor ENTs for (int i = zonename.labels() + 1; i < n.labels(); ++i) { Name parent = new Name(n, n.labels() - i); byte[] parent_hash = nsec3param.hashName(parent); String parent_hashname = b32.toString(parent_hash); if (!map.containsKey(parent_hashname)) { map.put(parent_hashname, parent.toString().toLowerCase()); } } } // Final pass, assign the names if we can for (ListIterator<Record> i = zone.listIterator(); i.hasNext();) { Record r = i.next(); if (r.getType() != Type.NSEC3) continue; NSEC3Record nsec3 = (NSEC3Record) r; String hashname = nsec3.getName().getLabelString(0).toLowerCase(); String ownername = (String) map.get(hashname); NSEC3Record new_nsec3 = new NSEC3Record(nsec3.getName(), nsec3.getDClass(), nsec3.getTTL(), nsec3.getHashAlgorithm(), nsec3.getFlags(), nsec3.getIterations(), nsec3.getSalt(), nsec3.getNext(), nsec3.getTypes(), ownername); i.set(new_nsec3); } }
From source file:io.swagger.codegen.languages.AbstractJavaCodegen.java
@Override public Map<String, Object> postProcessModels(Map<String, Object> objs) { // recursively add import for mapping one type to multiple imports List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports"); if (recursiveImports == null) return objs; ListIterator<Map<String, String>> listIterator = recursiveImports.listIterator(); while (listIterator.hasNext()) { String _import = listIterator.next().get("import"); // if the import package happens to be found in the importMapping (key) // add the corresponding import package to the list if (importMapping.containsKey(_import)) { Map<String, String> newImportMap = new HashMap<String, String>(); newImportMap.put("import", importMapping.get(_import)); listIterator.add(newImportMap); }// w w w . ja v a2s. c om } return postProcessModelsEnum(objs); }
From source file:com.architexa.diagrams.relo.jdt.parts.CodeUnitEditPart.java
public List<ArtifactFragment> getNonDerivedModelChildren() { List<ArtifactFragment> retVal = new ArrayList<ArtifactFragment>(getModelChildren()); ListIterator<ArtifactFragment> li = retVal.listIterator(); while (li.hasNext()) { if (li.next() instanceof DerivedArtifact) { li.remove();/*from w w w . java 2 s . co m*/ } } return retVal; }
From source file:com.amazonaws.services.kinesis.clientlibrary.lib.worker.WorkerTest.java
private void verifyAllRecordsWereConsumedAtLeastOnce(List<Record> expectedRecords, List<Record> actualRecords) { //@formatter:on ListIterator<Record> expectedIter = expectedRecords.listIterator(); for (int i = 0; i < expectedRecords.size(); ++i) { Record expectedRecord = expectedIter.next(); Assert.assertTrue(actualRecords.contains(expectedRecord)); }// w w w . java 2s .co m }
From source file:org.canova.api.conf.Configuration.java
private void toString(List resources, StringBuilder sb) { ListIterator i = resources.listIterator(); while (i.hasNext()) { if (i.nextIndex() != 0) { sb.append(", "); }//from w ww . ja v a2s . co m sb.append(i.next()); } }