List of usage examples for java.util LinkedList get
public E get(int index)
From source file:org.trnltk.experiment.morphology.ambiguity.ParseResultDiffTool.java
public ParseResultDifference findDifference(ParseResult _parseResultA, ParseResult _parseResultB) { final ParseResult firstParseResult; final ParseResult secondParseResult; if (Comparators.parseResultOrdering.compare(_parseResultA.getStr(), _parseResultB.getStr()) <= 0) { firstParseResult = _parseResultA; secondParseResult = _parseResultB; } else {/* ww w . j a v a2s. c om*/ firstParseResult = _parseResultB; secondParseResult = _parseResultA; } final RootDifference rootDifference = buildRootDifference(firstParseResult, secondParseResult); final DataDiffUtil<ParseResultPart> diffUtil = new DataDiffUtil<ParseResultPart>(); final List<ParseResultPart> firstParseResultParts = CollectionUtils.isEmpty(firstParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : firstParseResult.getParts(); final List<ParseResultPart> secondParseResultParts = CollectionUtils.isEmpty(secondParseResult.getParts()) ? Collections.<ParseResultPart>emptyList() : secondParseResult.getParts(); final LinkedList<DataDiffUtil.Diff<ParseResultPart>> diffs = diffUtil.diff_main(firstParseResultParts, secondParseResultParts); diffUtil.diff_cleanupSemantic(diffs); final ParseResultDifference parseResultDifference = new ParseResultDifference(rootDifference); final int diffsLength = diffs.size(); int i = 0; while (i < diffsLength) { final DataDiffUtil.Diff<ParseResultPart> currentDiff = diffs.get(i); final DataDiffUtil.Diff<ParseResultPart> nextDiff = i + 1 >= diffsLength ? null : diffs.get(i + 1); //note: delete always comes before insert switch (currentDiff.operation) { case EQUAL: { i++; break; } case INSERT: { final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(null, currentDiff.text); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i++; break; } case DELETE: { // List<ParseResultPart> secondPart; if (nextDiff != null && nextDiff.operation.equals(DataDiffUtil.Operation.INSERT)) secondPart = nextDiff.text; else secondPart = null; final Pair<List<ParseResultPart>, List<ParseResultPart>> pair = Pair.of(currentDiff.text, secondPart); final ParseResultPartDifference partDifference = new ParseResultPartDifference(pair); parseResultDifference.addParseResultPartDifference(partDifference); i = i + 2; break; } } } return parseResultDifference; }
From source file:com.gargoylesoftware.htmlunit.WebConsole.java
/** * This method is used by all the public method to process the passed * parameters./*from w ww.j a v a 2 s. c o m*/ * * If the last parameter implements the Formatter interface, it will be * used to format the parameters and print the object. * @param objs the logging parameters * @return a String to be printed using the logger */ private String process(final Object[] objs) { if (objs == null) { return "null"; } final StringBuffer sb = new StringBuffer(); final LinkedList<Object> args = new LinkedList<>(Arrays.asList(objs)); final Formatter formatter = getFormatter(); if (args.size() > 1 && args.get(0) instanceof String) { final StringBuilder msg = new StringBuilder((String) args.remove(0)); int startPos = msg.indexOf("%"); while (startPos > -1 && startPos < msg.length() - 1 && args.size() > 0) { if (startPos != 0 && msg.charAt(startPos - 1) == '%') { // double % msg.replace(startPos, startPos + 1, ""); } else { final char type = msg.charAt(startPos + 1); String replacement = null; switch (type) { case 'o': case 's': replacement = formatter.parameterAsString(pop(args)); break; case 'd': case 'i': replacement = formatter.parameterAsInteger(pop(args)); break; case 'f': replacement = formatter.parameterAsFloat(pop(args)); break; default: break; } if (replacement != null) { msg.replace(startPos, startPos + 2, replacement); startPos = startPos + replacement.length(); } else { startPos++; } } startPos = msg.indexOf("%", startPos); } sb.append(msg); } for (final Object o : args) { if (sb.length() != 0) { sb.append(' '); } sb.append(formatter.printObject(o)); } return sb.toString(); }
From source file:net.unconventionalthinking.hierarchy.langsymboltable.LangSymbol_Type.java
public void set_Name(String simpleName, LinkedList<TypeInfo> nestedTypeStack) { name_withNestedNames_PartsList = new ArrayList<String>(); for (int i = 0; i < nestedTypeStack.size(); ++i) name_withNestedNames_PartsList.add(nestedTypeStack.get(i).get_Name_Simple()); // add the simpleName too name_withNestedNames_PartsList.add(simpleName); StringBuilder fullName = new StringBuilder(); boolean isNotFirstIter = false; for (String namePart : name_withNestedNames_PartsList) { if (isNotFirstIter) fullName.append("."); else {//w w w.jav a2 s .co m isNotFirstIter = true; name_Root = namePart; } fullName.append(namePart); } name_withNestedNames = fullName.toString(); name_Simple = simpleName; }
From source file:report.mainReport.java
private static int getDuration(LinkedList pList, String dvId, int index) { int tmps = 0; Events evt = (Events) pList.get(index); tmps = 0;/*from w w w. jav a2s.c o m*/ if (index == 0) { for (int j = index + 1; j < pList.size(); j++) { Events evtnxt = (Events) pList.get(j); if (evtnxt.getSpeed() > 1.0) { double diff = evtnxt.getDateEvt().getTime() - evt.getDateEvt().getTime(); tmps = (int) diff / 1000; j = pList.size(); } } } else { Events evtbef = (Events) pList.get(index - 1); if (evtbef.getSpeed() > 0.) { for (int j = index + 1; j < pList.size(); j++) { Events evtnxt = (Events) pList.get(j); if (evtnxt.getSpeed() > 1.0) { double diff = evtnxt.getDateEvt().getTime() - evt.getDateEvt().getTime(); tmps = (int) diff / 1000; j = pList.size(); } } } } /*for (int i = index; i < pList.size(); i++) { Events evt = (Events) pList.get(i); if (evt.getDeviceID().equals(dvId)) { int k = i + 1; tmps = 0; if (k < pList.size()){ Events evtnxt = (Events) pList.get(k); if (evtnxt.getDeviceID().equals(dvId)){ double diff = evtnxt.getDateEvt().getTime() - evt.getDateEvt().getTime(); tmps = (int) diff / 1000; i = pList.size(); } } } }*/ //System.out.println("duree: "+tmps); return tmps; }
From source file:org.micromanager.plugins.magellan.surfacesandregions.SurfaceInterpolatorSimple.java
@Override public float getExtrapolatedValue(double x, double y) { //duplicate points for thread safety final LinkedList<Point3d> points = new LinkedList<Point3d>(points_); //find 3 closest points and calculate value //find closest convex hull vertex final LinkedList<Integer> closestIndices = new LinkedList<Integer>(); final LinkedList<Double> closestDistances = new LinkedList<Double>(); for (int i = 0; i < points.size(); i++) { //get current distance Vector2D vertex = new Vector2D(points.get(i).x, points.get(i).y); double distance = vertex.distance(new Vector2D(x, y)); if (closestDistances.size() < 3) { closestIndices.add(i);/*w w w . j av a2 s .com*/ closestDistances.add(distance); } else if (distance < closestDistances.get(2)) { closestIndices.removeLast(); closestDistances.removeLast(); closestIndices.add(i); closestDistances.add(distance); } //sort Collections.sort(closestIndices, new Comparator<Integer>() { public int compare(Integer left, Integer right) { return (new Double(closestDistances.get(closestIndices.indexOf(left)))) .compareTo(closestDistances.get(closestIndices.indexOf(right))); } }); Collections.sort(closestDistances); } Point3d point1 = points.get(closestIndices.get(0)); Point3d point2 = points.get(closestIndices.get(1)); Point3d point3 = points.get(closestIndices.get(2)); Vector3D v1 = new Vector3D(point1.x, point1.y, point1.z); Vector3D v2 = new Vector3D(point2.x, point2.y, point2.z); Vector3D v3 = new Vector3D(point3.x, point3.y, point3.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(x, y, 0), new Vector3D(x, y, 1), TOLERANCE)); float zVal = (float) pointInPlane.getZ(); return zVal; }
From source file:com.commander4j.sys.JHostList.java
public String getHTMLmenu(String defaultItem) { String selected = ""; String data = ""; String result = ""; LinkedList<JHost> temp = new LinkedList<JHost>(); JHost hst = new JHost(); temp = Common.hostList.getHosts();//w ww . ja v a 2s. c om defaultItem = JUtility.replaceNullStringwithBlank(defaultItem); checkedIndex = 0; if (temp.size() > 0) { for (int j = 0; j < temp.size(); j++) { hst = (JHost) temp.get(j); logger.debug(hst.getSiteNumber() + " " + hst.getSiteDescription()); if (hst.getEnabled().equals("Y")) { if (defaultItem.equals("") == true) { defaultItem = Common.hostList.getHost(String.valueOf(j + 1)).getSiteNumber(); } if (Common.hostList.getHost(String.valueOf(j + 1)).getSiteNumber().equals(defaultItem)) { selected = "checked=\"checked\""; checkedIndex = j; } else { selected = ""; } data = "<label><input type=\"radio\" name=\"selectedHost\" value=\"" + hst.getSiteNumber() + "\" " + selected + "/>" + hst.getSiteDescription() + "</label><br/>" + CRLF; result = result + data; } } } else { checkedIndex = -1; } return result; }
From source file:lv.semti.morphology.webservice.VerbResource.java
public String parsequery(Boolean verb) { String query = (String) getRequest().getAttributes().get("query"); try {//w ww.j a v a2s. c o m query = URLDecoder.decode(query, "UTF8"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } MorphoServer.analyzer.defaultSettings(); LinkedList<Word> tokens = Splitting.tokenize(MorphoServer.analyzer, query); String debug = ""; for (Word token : tokens) { if (token.isRecognized()) debug += token.wordforms.get(0).getDescription(); else debug += token.getToken(); debug += "\n"; } debug += String.valueOf(tokens.size()); String tag = ""; if (tokens.size() == 1) tag = tagWord(tokens.get(0), verb); else tag = tagChunk(tokens); // Heiristikas vair?kv?rdu situ?cijas risin?anai if (tag == "") return debug; else return tag; }
From source file:org.apache.olingo.server.core.requests.DataRequest.java
static String buildNavPath(UriHelper helper, EdmEntityType rootType, LinkedList<UriResourceNavigation> navigations, boolean includeLastPredicates) throws SerializerException { if (navigations.isEmpty()) { return null; }/*www .j a v a 2 s. c om*/ StringBuilder sb = new StringBuilder(); boolean containsTarget = false; EdmEntityType type = rootType; for (UriResourceNavigation nav : navigations) { String name = nav.getProperty().getName(); EdmNavigationProperty property = type.getNavigationProperty(name); if (property.containsTarget()) { containsTarget = true; } type = nav.getProperty().getType(); } if (containsTarget) { for (int i = 0; i < navigations.size(); i++) { UriResourceNavigation nav = navigations.get(i); if (i > 0) { sb.append("/"); } sb.append(nav.getProperty().getName()); boolean skipKeys = false; if (navigations.size() == i + 1 && !includeLastPredicates) { skipKeys = true; } if (!skipKeys && !nav.getKeyPredicates().isEmpty()) { sb.append("("); sb.append(helper.buildContextURLKeyPredicate(nav.getKeyPredicates())); sb.append(")"); } if (nav.getTypeFilterOnCollection() != null) { sb.append("/").append( nav.getTypeFilterOnCollection().getFullQualifiedName().getFullQualifiedNameAsString()); } else if (nav.getTypeFilterOnEntry() != null) { sb.append("/").append( nav.getTypeFilterOnEntry().getFullQualifiedName().getFullQualifiedNameAsString()); } } } return sb.toString(); }
From source file:org.kepler.configuration.SerializationComparisonTest.java
/** * test the yaml interface for reading properties *//* ww w . j a v a2 s. c o m*/ public void testYamlRead() { try { InputStream input = new FileInputStream( new File("configuration-manager/resources/configurations/config.yaml")); Yaml yaml = new Yaml(); LinkedHashMap config = (LinkedHashMap) yaml.load(input); //System.out.println("class: " + config.getClass().getName()); //System.out.println("data: " + config.toString()); /*Iterator keys = data.keySet().iterator(); while(keys.hasNext()) { String key = (String)keys.next(); System.out.println(key); }*/ //try to read viewPaneTabPanes/viewPane/viewPaneLocation/location LinkedList viewPaneTabPanes = (LinkedList) config.get("viewPaneTabPanes"); //System.out.println("viewPaneTabPanes: " + viewPaneTabPanes.toString()); LinkedHashMap viewPaneLHM = (LinkedHashMap) viewPaneTabPanes.get(0); //System.out.println("viewPaneLHM: " + viewPaneLHM.toString()); LinkedList viewPane = (LinkedList) viewPaneLHM.get("viewPane"); //System.out.println("viewPaneLocation: " + viewPane.toString()); LinkedHashMap viewPaneLocationLHM = (LinkedHashMap) viewPane.get(1); //System.out.println("viewPaneLocation: " + viewPaneLocationLHM.toString()); LinkedList viewPaneLocation = (LinkedList) viewPaneLocationLHM.get("viewPaneLocation"); //System.out.println("location: " + viewPaneLocation.toString()); LinkedHashMap locationLHM = (LinkedHashMap) viewPaneLocation.get(0); //System.out.println("location: " + locationLHM.toString()); String location = (String) locationLHM.get("location"); //System.out.println("location: " + location.toString()); assertTrue(location.equals("W")); } catch (Exception e) { e.printStackTrace(); fail("Threw yaml error: " + e.getMessage()); } System.out.println(); System.out.println(); }
From source file:org.apache.activemq.leveldb.test.ReplicatedLevelDBStoreTest.java
@Test(timeout = 1000 * 60 * 10) public void testSlowSlave() throws Exception { LinkedList<File> directories = new LinkedList<File>(); directories.add(new File("target/activemq-data/leveldb-node1")); directories.add(new File("target/activemq-data/leveldb-node2")); directories.add(new File("target/activemq-data/leveldb-node3")); resetDirectories(directories);//w w w. j a v a2 s . c o m File node1Dir = directories.get(0); File node2Dir = directories.get(1); File node3Dir = directories.get(2); ArrayList<String> expected_list = new ArrayList<String>(); MasterLevelDBStore node1 = createMaster(node1Dir); stores.add(node1); CountDownFuture masterStart = asyncStart(node1); // Lets create a 1 slow slave... SlaveLevelDBStore node2 = new SlaveLevelDBStore() { boolean hitOnce = false; @Override public TcpTransport create_transport() { if (hitOnce) { return super.create_transport(); } hitOnce = true; TcpTransport transport = super.create_transport(); transport.setMaxReadRate(64 * 1024); return transport; } }; stores.add(node2); configureSlave(node2, node1, node2Dir); SlaveLevelDBStore node3 = createSlave(node1, node3Dir); stores.add(node3); asyncStart(node2); asyncStart(node3); masterStart.await(); LOG.info("Adding messages..."); String playload = createPlayload(64 * 1024); MessageStore ms = node1.createQueueMessageStore(new ActiveMQQueue("TEST")); final int TOTAL = 10; for (int i = 0; i < TOTAL; i++) { if (i == 8) { // Stop the fast slave so that we wait for the slow slave to // catch up.. node3.stop(); } String msgid = "m:" + ":" + i; addMessage(ms, msgid, playload); expected_list.add(msgid); } LOG.info("Checking node1 state"); assertEquals(expected_list, getMessages(ms)); LOG.info("Stopping node1: " + node1.node_id()); node1.stop(); LOG.info("Stopping slave: " + node2.node_id()); node2.stop(); }