List of usage examples for java.util LinkedList size
int size
To view the source code for java.util LinkedList size.
Click Source Link
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 a va2 s. c o 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:de.fabianonline.telegram_backup.exporter.HTMLExporter.java
public void export(UserManager user) { try {/*from www. j a v a 2s .co m*/ Database db = new Database(user, null); // Create base dir logger.debug("Creating base dir"); String base = user.getFileBase() + "files" + File.separatorChar; new File(base).mkdirs(); new File(base + "dialogs").mkdirs(); logger.debug("Fetching dialogs"); LinkedList<Database.Dialog> dialogs = db.getListOfDialogsForExport(); logger.trace("Got {} dialogs", dialogs.size()); logger.debug("Fetching chats"); LinkedList<Database.Chat> chats = db.getListOfChatsForExport(); logger.trace("Got {} chats", chats.size()); logger.debug("Generating index.html"); HashMap<String, Object> scope = new HashMap<String, Object>(); scope.put("user", user); scope.put("dialogs", dialogs); scope.put("chats", chats); // Collect stats data scope.put("count.chats", chats.size()); scope.put("count.dialogs", dialogs.size()); int count_messages_chats = 0; int count_messages_dialogs = 0; for (Database.Chat c : chats) count_messages_chats += c.count; for (Database.Dialog d : dialogs) count_messages_dialogs += d.count; scope.put("count.messages", count_messages_chats + count_messages_dialogs); scope.put("count.messages.chats", count_messages_chats); scope.put("count.messages.dialogs", count_messages_dialogs); scope.put("count.messages.from_me", db.getMessagesFromUserCount()); scope.put("heatmap_data", intArrayToString(db.getMessageTimesMatrix())); scope.putAll(db.getMessageAuthorsWithCount()); scope.putAll(db.getMessageTypesWithCount()); scope.putAll(db.getMessageMediaTypesWithCount()); MustacheFactory mf = new DefaultMustacheFactory(); Mustache mustache = mf.compile("templates/html/index.mustache"); OutputStreamWriter w = getWriter(base + "index.html"); mustache.execute(w, scope); w.close(); mustache = mf.compile("templates/html/chat.mustache"); int i = 0; logger.debug("Generating {} dialog pages", dialogs.size()); for (Database.Dialog d : dialogs) { i++; logger.trace("Dialog {}/{}: {}", i, dialogs.size(), Utils.anonymize("" + d.id)); LinkedList<HashMap<String, Object>> messages = db.getMessagesForExport(d); scope.clear(); scope.put("user", user); scope.put("dialog", d); scope.put("messages", messages); scope.putAll(db.getMessageAuthorsWithCount(d)); scope.put("heatmap_data", intArrayToString(db.getMessageTimesMatrix(d))); scope.putAll(db.getMessageTypesWithCount(d)); scope.putAll(db.getMessageMediaTypesWithCount(d)); w = getWriter(base + "dialogs" + File.separatorChar + "user_" + d.id + ".html"); mustache.execute(w, scope); w.close(); } i = 0; logger.debug("Generating {} chat pages", chats.size()); for (Database.Chat c : chats) { i++; logger.trace("Chat {}/{}: {}", i, chats.size(), Utils.anonymize("" + c.id)); LinkedList<HashMap<String, Object>> messages = db.getMessagesForExport(c); scope.clear(); scope.put("user", user); scope.put("chat", c); scope.put("messages", messages); scope.putAll(db.getMessageAuthorsWithCount(c)); scope.put("heatmap_data", intArrayToString(db.getMessageTimesMatrix(c))); scope.putAll(db.getMessageTypesWithCount(c)); scope.putAll(db.getMessageMediaTypesWithCount(c)); w = getWriter(base + "dialogs" + File.separatorChar + "chat_" + c.id + ".html"); mustache.execute(w, scope); w.close(); } logger.debug("Generating additional files"); // Copy CSS URL cssFile = getClass().getResource("/templates/html/style.css"); File dest = new File(base + "style.css"); FileUtils.copyURLToFile(cssFile, dest); logger.debug("Done exporting."); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("Exception above!"); } }
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 ww w .j a v 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:com.bilibili.magicasakura.utils.ColorStateListUtils.java
static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException { final int innerDepth = parser.getDepth() + 1; int depth;//from w w w . j av a2 s . c o m int type; LinkedList<int[]> stateList = new LinkedList<>(); LinkedList<Integer> colorList = new LinkedList<>(); while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG || depth > innerDepth || !parser.getName().equals("item")) { continue; } TypedArray a1 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.color }); final int value = a1.getResourceId(0, Color.MAGENTA); final int baseColor = value == Color.MAGENTA ? Color.MAGENTA : ThemeUtils.replaceColorById(context, value); a1.recycle(); TypedArray a2 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.alpha }); final float alphaMod = a2.getFloat(0, 1.0f); a2.recycle(); colorList.add(alphaMod != 1.0f ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod)) : baseColor); stateList.add(extractStateSet(attrs)); } if (stateList.size() > 0 && stateList.size() == colorList.size()) { int[] colors = new int[colorList.size()]; for (int i = 0; i < colorList.size(); i++) { colors[i] = colorList.get(i); } return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors); } return null; }
From source file:de.uniwue.info6.misc.StringTools.java
/** * * * @param queryText//from w w w . j ava 2 s. c o m * @param tables * @param user * @return */ public static String addUserPrefix(String queryText, List<String> tables, User user) { LinkedList<Integer> substrings = new LinkedList<Integer>(); int start = 0, end = queryText.length(); for (String tab : tables) { // q&d fix Matcher matcher = Pattern.compile(tab.trim(), Pattern.CASE_INSENSITIVE).matcher(queryText); while (matcher.find()) { start = matcher.start(0); end = matcher.end(0); // String group = matcher.group(); boolean leftCharacterValid = StringTools.trailingCharacter(queryText, start, true); boolean rightCharacterValid = StringTools.trailingCharacter(queryText, end, false); if (leftCharacterValid && rightCharacterValid) { substrings.add(start); } } } Collections.sort(substrings); for (int i = substrings.size() - 1; i >= 0; i--) { Integer sub = substrings.get(i); queryText = queryText.substring(0, sub) + user.getId() + "_" + queryText.substring(sub, queryText.length()); } return queryText; }
From source file:com.samanamp.algorithms.RandomSelectionAlgorithm.java
private void runSimulation(LinkedList<Node> selectedNodes) { LoopingIterator<Node> selectedNodesIterator = new LoopingIterator<Node>(selectedNodes); int sigma = 0; for (int i = 0; i < runs; i++) { selectedNodesIterator.reset();/*from w ww . ja va 2s . co m*/ resetGraph(); for (int j = 0; j < selectedNodes.size(); j++) { sigma += simulator.sigmaOfNode(selectedNodesIterator.next(), maxTime); } } selectedNodesIterator.reset(); int finalSigma = sigma / runs; printResults(finalSigma, selectedNodesIterator); }
From source file:SearchStyleText.java
public SearchStyleText() { shell.setLayout(new GridLayout(2, false)); styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 2;/* w w w . j a v a2 s. com*/ styledText.setLayoutData(gridData); keywordText = new Text(shell, SWT.SINGLE | SWT.BORDER); keywordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Font font = new Font(shell.getDisplay(), "Courier New", 12, SWT.NORMAL); styledText.setFont(font); button = new Button(shell, SWT.PUSH); button.setText("Search"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { keyword = keywordText.getText(); styledText.redraw(); } }); styledText.addLineStyleListener(new LineStyleListener() { public void lineGetStyle(LineStyleEvent event) { if (keyword == null || keyword.length() == 0) { event.styles = new StyleRange[0]; return; } String line = event.lineText; int cursor = -1; LinkedList list = new LinkedList(); while ((cursor = line.indexOf(keyword, cursor + 1)) >= 0) { list.add(getHighlightStyle(event.lineOffset + cursor, keyword.length())); } event.styles = (StyleRange[]) list.toArray(new StyleRange[list.size()]); } }); keyword = "SW"; styledText.setText("AWT, SWING \r\nSWT & JFACE"); shell.pack(); shell.open(); //textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
From source file:edu.cwru.sepia.model.SimplePlannerTest.java
@Test public void testPlanFollowsShortestPath() { LinkedList<Action> plan = planner.planMove(0, 5, 6); System.out.println("\n\n"); for (Action a : plan) { System.out.println(a);/*from ww w . ja v a 2s . com*/ } assertEquals("Planner did not take shortest path!", 8, plan.size()); }
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);//from ww w. j a v a2 s.c om 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:ch.icclab.cyclops.resource.impl.TelemetryResource.java
/** * In this method, usage made is calculated on per resource basis in the cumulative meters * * Pseudo Code/* www. j a va2s . co m*/ * 1. Traverse through the linkedlist * 2. Subtract the volumes of i and (i+1) samples * 3. Set the difference into the i sample object * 4. Add the updates sample object into an arraylist * * @param cMeterArr This is an arrayList of type CumulativeMeterData containing sample object with the usage information * @param linkedList This is a Linked List of type CumulativeMeterData containing elements from a particular resource * @return An arrayList of type CumulativeMeterData containing sample objects with the usage information */ private ArrayList<CumulativeMeterData> calculateCumulativeMeterUsage(ArrayList<CumulativeMeterData> cMeterArr, LinkedList<CumulativeMeterData> linkedList) { long diff; //BigInteger maxMeterValue ; for (int i = 0; i < (linkedList.size() - 1); i++) { if ((i + 1) <= linkedList.size()) { diff = linkedList.get(i).getVolume() - linkedList.get(i + 1).getVolume(); if (diff < 0) { linkedList.get(i).setUsage(0); //TODO: Update the negative difference usecase } else { linkedList.get(i).setUsage(diff); } cMeterArr.add(linkedList.get(i)); } } cMeterArr.add(linkedList.getLast()); return cMeterArr; }