List of usage examples for java.util LinkedList iterator
Iterator<E> iterator();
From source file:bigfat.hadoop.HDFSDirInputStream.java
/** * Create a input stream that will read through all the files in one * directory note that the file will be sorted by name, using the * comparator./*from w w w. ja va 2 s . com*/ * * @param fs * @param dir * @param comp * @throws IOException */ public HDFSDirInputStream(FileSystem fs, String dir, Comparator<String> comp) throws IOException { this.fs = fs; Path p = new Path(dir); FileStatus fstate = fs.getFileStatus(p); if (fstate.isDir()) { FileStatus[] child = fs.globStatus(new Path(dir + "/*")); LinkedList<String> s = new LinkedList<String>(); Map<String, Path> map = new HashMap<String, Path>(); for (FileStatus c : child) { if (c.isDir()) continue; map.put(c.getPath().getName(), c.getPath()); s.add(c.getPath().getName()); } if (comp != null) Collections.sort(s, comp); else Collections.sort(s); Iterator<String> it = s.iterator(); while (it.hasNext()) { String n = it.next(); Path pr = map.get(n); this.appendFile(pr.toString()); } } else { this.appendFile(dir); } }
From source file:org.openmeetings.app.remote.ChatService.java
public LinkedList<LinkedList<String>> getAllPublicEmoticons() { try {/*from w w w . j a v a 2s . c o 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.google.ie.business.service.impl.ProjectServiceImpl.java
@SuppressWarnings("unchecked") private void addIdeaToRecentlyPickedIdeaListInCache(Idea ideaToBeAdded) { /* Get the list of recently picked ideas from cache */ LinkedList<Idea> ideas = (LinkedList<Idea>) CacheHelper.getObject(CacheConstants.IDEA_NAMESPACE, CacheConstants.RECENTLY_PICKED_IDEAS); if (ideas != null) { Iterator<Idea> iterator = ideas.iterator(); Idea ideaFromCache = null;/*from w w w . j a v a2 s.c om*/ /* Iterate to check whether the list already contains the idea */ while (iterator.hasNext()) { ideaFromCache = iterator.next(); String ideaKey = ideaFromCache.getKey(); if (ideaKey.equalsIgnoreCase(ideaToBeAdded.getKey())) { /* * If idea already exists in the list , move it to the head */ ideas.remove(ideaFromCache); ideas.addFirst(ideaFromCache); CacheHelper.putObject(CacheConstants.IDEA_NAMESPACE, CacheConstants.RECENTLY_PICKED_IDEAS, ideas, CacheConstants.RECENTLY_PICKED_IDEAS_EXPIRATION_DELAY); return; } } } /* This is executed if the idea does not already exist in cache */ ideaService.addIdeaToListInCache(ideaToBeAdded, CacheConstants.RECENTLY_PICKED_IDEAS, DEFAULT_NO_OF_RECENT_PROJECTS, CacheConstants.RECENTLY_PICKED_IDEAS_EXPIRATION_DELAY); }
From source file:edu.csun.ecs.cs.multitouchj.application.whiteboard.ui.InteractiveCanvas.java
protected void drawPoints() { synchronized (previousPoints) { synchronized (resizableBufferedImage) { // clear points for pen if it's been long since last changed long currentTime = new Date().getTime(); for (int id : pens.keySet()) { if (previousTimes.containsKey(id)) { long time = previousTimes.get(id); if ((currentTime - time) > POINT_CLEAR_DURATION) { previousPoints.remove(id); previousTimes.remove(id); }/*from w w w .j av a 2s. co m*/ } } DisplayMode displayMode = getWindowManager().getDisplayManager().getCurrentDisplayMode(); BufferedImage bufferedImage = resizableBufferedImage.getBufferedImage(); Graphics2D graphics = bufferedImage.createGraphics(); for (int id : pens.keySet()) { Pen pen = pens.get(id); LinkedList<Point> points = previousPoints.get(id); if ((pen != null) && (points != null) && (points.size() > 1)) { log.debug("id: " + id + ", points: " + points.size()); Point previousPoint = points.removeFirst(); Iterator<Point> iterator = points.iterator(); while (iterator.hasNext()) { Point point = iterator.next(); if (iterator.hasNext()) { iterator.remove(); } graphics.setStroke(pen.getStroke()); graphics.setPaint(pen.getPaint()); graphics.drawLine((int) Math.floor(previousPoint.getX()), (displayMode.getHeight() - (int) Math.floor(previousPoint.getY())), (int) Math.floor(point.getX()), (displayMode.getHeight() - (int) Math.floor(point.getY()))); previousPoint = point; } setDirty(true); } } graphics.dispose(); } } }
From source file:azkaban.metric.inmemoryemitter.InMemoryMetricEmitter.java
/** * filter snapshots by evenly selecting points across the interval * @param selectedLists list of snapshots *//*from w w w . j av a2s. co m*/ private void generalSelectMetricHistory(final LinkedList<InMemoryHistoryNode> selectedLists) { logger.debug("selecting snapshots evenly from across the time interval"); if (selectedLists.size() > numInstances) { double step = (double) selectedLists.size() / numInstances; long nextIndex = 0, currentIndex = 0, numSelectedInstances = 1; Iterator<InMemoryHistoryNode> ite = selectedLists.iterator(); while (ite.hasNext()) { ite.next(); if (currentIndex == nextIndex) { nextIndex = (long) Math.floor(numSelectedInstances * step + 0.5); numSelectedInstances++; } else { ite.remove(); } currentIndex++; } } }
From source file:azkaban.metric.inmemoryemitter.InMemoryMetricEmitter.java
/** * filter snapshots using statistically significant points only * @param selectedLists list of snapshots */// ww w. j a v a2 s . c o m private void statBasedSelectMetricHistory(final LinkedList<InMemoryHistoryNode> selectedLists) throws ClassCastException { logger.debug("selecting snapshots which are far away from mean value"); DescriptiveStatistics descStats = getDescriptiveStatistics(selectedLists); Double mean = descStats.getMean(); Double std = descStats.getStandardDeviation(); Iterator<InMemoryHistoryNode> ite = selectedLists.iterator(); while (ite.hasNext()) { InMemoryHistoryNode currentNode = ite.next(); double value = ((Number) currentNode.getValue()).doubleValue(); // remove all elements which lies in 95% value band if (value < mean + standardDeviationFactor * std && value > mean - standardDeviationFactor * std) { ite.remove(); } } }
From source file:net.semanticmetadata.lire.utils.FileUtils.java
public static void saveImageResultsToPng(String prefix, TopDocs hits, String queryImage, IndexReader ir) throws IOException { LinkedList<BufferedImage> results = new LinkedList<BufferedImage>(); int width = 0; for (int i = 0; i < Math.min(hits.scoreDocs.length, 10); i++) { // hits.score(i) // hits.doc(i).get("descriptorImageIdentifier") BufferedImage tmp = ImageIO .read(new FileInputStream(ir.document(hits.scoreDocs[i].doc).get("descriptorImageIdentifier"))); if (tmp.getHeight() > 200) { double factor = 200d / ((double) tmp.getHeight()); tmp = ImageUtils.scaleImage(tmp, (int) (tmp.getWidth() * factor), 200); }//from ww w . ja v a2s. c om width += tmp.getWidth() + 5; results.add(tmp); } BufferedImage result = new BufferedImage(width, 220, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) result.getGraphics(); g2.setColor(Color.black); g2.clearRect(0, 0, result.getWidth(), result.getHeight()); g2.setColor(Color.green); g2.setFont(Font.decode("\"Arial\", Font.BOLD, 12")); int offset = 0; int count = 0; for (Iterator<BufferedImage> iterator = results.iterator(); iterator.hasNext();) { BufferedImage next = iterator.next(); g2.drawImage(next, offset, 20, null); g2.drawString(hits.scoreDocs[count].score + "", offset + 5, 12); offset += next.getWidth() + 5; count++; } ImageIO.write(result, "PNG", new File(prefix + "_" + (System.currentTimeMillis() / 1000) + ".png")); }
From source file:com.rapidminer.operator.preprocessing.discretization.MinimalEntropyDiscretization.java
private Double getMinEntropySplitpoint(LinkedList<double[]> truncatedExamples, Attribute label) { HashSet<Double> candidateSplitpoints = new HashSet<Double>(); Iterator<double[]> it = truncatedExamples.iterator(); int[] totalLabelDistribution = new int[label.getMapping().size()]; // Label distribution for // all examples. while (it.hasNext()) { // Get splitpoint candidates and total label distribution. double[] attributeLabelPair = it.next(); candidateSplitpoints.add(attributeLabelPair[0]); int labelIndex = (int) attributeLabelPair[1]; totalLabelDistribution[labelIndex]++; }// www . ja va 2s .co m double[] totalFrequencies = new double[label.getMapping().size()]; for (int i = 0; i < label.getMapping().size(); i++) { totalFrequencies[i] = (double) totalLabelDistribution[i] / (double) truncatedExamples.size(); } double totalEntropy = 0.0d; for (int i = 0; i < label.getMapping().size(); i++) { totalEntropy -= totalFrequencies[i] * MathFunctions.ld(totalFrequencies[i]); } double minClassInformationEntropy = totalEntropy; double bestSplitpoint = Double.NaN; double bestSplitpointEntropy1 = Double.POSITIVE_INFINITY; double bestSplitpointEntropy2 = Double.POSITIVE_INFINITY; int k1 = 0; // Number of different class labels in class 1. int k2 = 0; // Number of different class labels in class 2. for (double currentSplitpoint : candidateSplitpoints) { // Test every value as splitpoint // Initialize. int s1 = 0; // Instances in partition 1. int s2 = 0; // Instances in partition 2. k1 = 0; k2 = 0; int[] labelDistribution1 = new int[label.getMapping().size()]; // Label distribution in // class 1. int[] labelDistribution2 = new int[label.getMapping().size()]; // Label distribution in // class 2. // Determine the class of each instance and the corresponding label distribution. for (double[] attributeLabelPair : truncatedExamples) { double valueToCompare = attributeLabelPair[0]; int labelIndex = (int) attributeLabelPair[1]; if (valueToCompare <= currentSplitpoint) { // Partition 1 gets all instances with values less or equal to the current // splitpoint. s1++; labelDistribution1[labelIndex]++; } else { // Partition 2 gets all instances with values // greater than the current split point. s2++; labelDistribution2[labelIndex]++; } } // Calculate frequencies and number of different labels for this // splitpoint each class. double[] frequencies1 = new double[label.getMapping().size()]; double[] frequencies2 = new double[label.getMapping().size()]; for (int i = 0; i < label.getMapping().size(); i++) { frequencies1[i] = (double) labelDistribution1[i] / (double) s1; frequencies2[i] = (double) labelDistribution2[i] / (double) s2; if (labelDistribution1[i] > 0) { // Label value i exists in // class 1. k1++; } if (labelDistribution2[i] > 0) { // Label value i exists in // class 2. k2++; } } /* * Calculate entropies. * * In the case of p(x_i) = 0 for some i, the value of the corresponding summand 0 * * ld(0) is taken to be 0, which is consistent with the well-known limit: * * lim_(p -> 0+) p*log(p) = 0 */ double entropy1 = 0.0d; for (int i = 0; i < label.getMapping().size(); i++) { double frequency = frequencies1[i]; // if frequency is zero, skip label if (frequency != 0.0d) { entropy1 -= frequency * MathFunctions.ld(frequency); } } double entropy2 = 0.0d; for (int i = 0; i < label.getMapping().size(); i++) { double frequency = frequencies2[i]; // if frequency is zero, skip label if (frequency != 0.0d) { entropy2 -= frequency * MathFunctions.ld(frequency); } } double classInformationEntropy = ((double) s1 / (double) truncatedExamples.size()) * entropy1 + ((double) s2 / (double) truncatedExamples.size()) * entropy2; if (classInformationEntropy < minClassInformationEntropy) { minClassInformationEntropy = classInformationEntropy; bestSplitpoint = currentSplitpoint; bestSplitpointEntropy1 = entropy1; bestSplitpointEntropy2 = entropy2; } } // Calculate the termination criterion. Return null if termination // criterion is met. double gain = totalEntropy - minClassInformationEntropy; double delta = MathFunctions.ld(Math.pow(3.0, label.getMapping().size()) - 2) - (label.getMapping().size() * totalEntropy - k1 * bestSplitpointEntropy1 - k2 * bestSplitpointEntropy2); if (gain >= MathFunctions.ld(truncatedExamples.size() - 1) / truncatedExamples.size() + delta / truncatedExamples.size()) { return Double.valueOf(bestSplitpoint); } else { return null; } }
From source file:org.mybatisorm.annotation.handler.JoinHandler.java
private String getOnPhrase(List<Field> fieldList, Hashtable<Set<Class<?>>, LinkedList<Field[]>> refMap) { StringBuilder sb = new StringBuilder(); Field field = fieldList.get(fieldList.size() - 1), field2; Class<?> clazz = field.getType(), clazz2; List<String> cnames = new LinkedList<String>(); int j;// w ww . java 2 s . c om for (j = fieldList.size() - 2; j >= 0; j--) { field2 = fieldList.get(j); clazz2 = field2.getType(); cnames.add(0, clazz2.getSimpleName()); LinkedList<Field[]> refs = refMap.get(pair(clazz, clazz2)); if (refs == null) continue; sb.append(" ON ("); Iterator<Field[]> it = refs.iterator(); while (it.hasNext()) { Field[] fs = it.next(); if (field.getType().equals(fs[0].getDeclaringClass())) { sb.append(field.getName()).append("_.").append(ColumnAnnotation.getName(fs[0])).append(" = ") .append(field2.getName()).append("_.").append(ColumnAnnotation.getName(fs[1])); } else { sb.append(field2.getName()).append("_.").append(ColumnAnnotation.getName(fs[0])).append(" = ") .append(field.getName()).append("_.").append(ColumnAnnotation.getName(fs[1])); } if (it.hasNext()) sb.append(" AND "); } sb.append(") "); break; } if (j < 0) throw new InvalidJoinException( "The class " + clazz.getSimpleName() + " doesn't refer to the former classes(" + StringUtil.join(cnames, ",") + "), nor vice versa."); return sb.toString(); }
From source file:net.semanticmetadata.lire.utils.FileUtils.java
public static void saveImageResultsToPng(String prefix, ImageSearchHits hits, String queryImage, IndexReader reader) throws IOException { LinkedList<BufferedImage> results = new LinkedList<BufferedImage>(); int width = 0; for (int i = 0; i < hits.length(); i++) { // hits.score(i) // hits.doc(i).get("descriptorImageIdentifier") BufferedImage tmp = ImageIO.read(new FileInputStream( reader.document(hits.documentID(i)).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0])); // if (tmp.getHeight() > 200) { double factor = 200d / ((double) tmp.getHeight()); tmp = ImageUtils.scaleImage(tmp, (int) (tmp.getWidth() * factor), 200); // } width += tmp.getWidth() + 5;/* ww w . j a va 2 s. com*/ results.add(tmp); } BufferedImage result = new BufferedImage(width, 220, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) result.getGraphics(); g2.setColor(Color.white); g2.setBackground(Color.white); g2.clearRect(0, 0, result.getWidth(), result.getHeight()); g2.setColor(Color.black); g2.setFont(Font.decode("\"Arial\", Font.BOLD, 12")); int offset = 0; int count = 0; for (Iterator<BufferedImage> iterator = results.iterator(); iterator.hasNext();) { BufferedImage next = iterator.next(); g2.drawImage(next, offset, 20, null); g2.drawString(hits.score(count) + "", offset + 5, 12); offset += next.getWidth() + 5; count++; } ImageIO.write(result, "PNG", new File(prefix + "_" + (System.currentTimeMillis() / 1000) + ".png")); }