List of usage examples for java.util LinkedList get
public E get(int index)
From source file:com.abuabdul.notedovn.util.NoteDovnUtil.java
public static ScratchNote when(int actual, LinkedList<ScratchNote> notes) { if (actual >= 0 && actual < notes.size()) { return notes.get(actual); }// w w w . j a v a2s .c o m return new ScratchNote(); }
From source file:Main.java
/** * Sorts a collection using a comparator and returns it as a {@link List} * * @param c Collection to be sorted * @param k Comparator to sort by/*from www. j a v a 2 s .c o m*/ * @param reverse Whether to reverse the sort order * @return a {@link List} of the sorted elements * @throws IllegalAccessException when unable to access the comparator class * @throws InstantiationException when unable to instantiate to comparator class */ public static <E> List<E> sortByCompare(Collection<E> c, Class<? extends Comparator<E>> k, boolean reverse) throws IllegalAccessException, InstantiationException { Comparator<E> comp = k.newInstance(); int moves = 0; boolean firstRun = true; LinkedList<E> l = new LinkedList<>(c); while (moves > 0 || firstRun) { firstRun = false; moves = 0; for (int i = 1; i < l.size(); i++) { E a = l.get(i - 1); E b = l.get(i); if (reverse ? comp.compare(a, b) < 0 : comp.compare(a, b) > 0) { l.set(i - 1, b); l.set(i, a); moves++; } } } return l; }
From source file:org.ppwcode.vernacular.persistence.IV.PersistentBeanHelpers.java
/** * All upstream {@link PersistentBean PersistentBeans} starting from {@code pb}. * These are the beans that are simple properties of {@code pb}. Upstream means * in most cases (this is all that is implemented at this time) the beans * reachable via a to-one association. This is applied recursively. * {@code pb} itself is also part of the set. *///w w w . ja v a 2 s .c om /* @MethodContract( pre = @Expression("_pb != null"), post = { @Expression("result != null"), @Expression("{_pb} U directUpstreamPersistentBeans(_pb) U " + "union (PersistentBean pbr : directUpstreamPersistentBeans(_pb)) {upstreamPersistentBeans(pbr)}") } ) */ public static Set<PersistentBean<?>> upstreamPersistentBeans(PersistentBean<?> pb) { assert preArgumentNotNull(pb, "pb"); LinkedList<PersistentBean<?>> agenda = new LinkedList<>(); agenda.add(pb); int i = 0; while (i < agenda.size()) { PersistentBean<?> current = agenda.get(i); directUpstreamPersistentBeans(current).stream().filter(pbr -> !agenda.contains(pbr)) .forEach(agenda::add); i++; } return new HashSet<>(agenda); }
From source file:gov.nih.nci.ncicb.tcga.dcc.common.webservice.WebServiceUtilFastTest.java
/** * Check that the given {@link WebApplicationException} is a <code>ValidationErrors</code> response with the expected values. * * @param response the {@link Response} to check * @param expectedStatusCode the expected status code * @param expectedInvalidValue the expected invalid value * @param expectedErrorMessage the expected error message * @param expectedMediaType the expected media type *//*from w w w. j a v a2 s . co m*/ public static void checkValidationErrorsResponse(final Response response, final int expectedStatusCode, final String expectedInvalidValue, final String expectedErrorMessage, final String expectedMediaType) { Assert.assertEquals(expectedStatusCode, response.getStatus()); final Object entity = response.getEntity(); Assert.assertEquals(ValidationErrors.class, entity.getClass()); final ValidationErrors validationErrors = (ValidationErrors) entity; Assert.assertNotNull(validationErrors); final List<ValidationErrors.ValidationError> validationErrorList = validationErrors.getValidationError(); Assert.assertNotNull(validationErrorList); Assert.assertEquals(1, validationErrorList.size()); final ValidationErrors.ValidationError validationError = validationErrorList.get(0); Assert.assertNotNull(validationError); Assert.assertEquals(expectedInvalidValue, validationError.getInvalidValue()); Assert.assertEquals(expectedErrorMessage, validationError.getErrorMessage()); final MultivaluedMap<String, Object> multivaluedMap = response.getMetadata(); Assert.assertNotNull(multivaluedMap); final Object contentType = multivaluedMap.get("Content-Type"); Assert.assertNotNull(contentType); assertTrue(contentType instanceof LinkedList); final LinkedList linkedList = (LinkedList) contentType; Assert.assertEquals(1, linkedList.size()); Assert.assertEquals(expectedMediaType, linkedList.get(0).toString()); }
From source file:fi.smaa.libror.MaximalVectorComputation.java
private static RealMatrix listOfRowsToMatrix(LinkedList<RealVector> results) { RealMatrix res = new Array2DRowRealMatrix(results.size(), results.getFirst().getDimension()); for (int i = 0; i < results.size(); i++) { res.setRowVector(i, results.get(i)); }/*w w w . j a v a 2 s . com*/ return res; }
From source file:org.eclipse.wb.internal.swing.model.layout.gbl.GridBagLayoutConverter.java
/** * Removes {@link DimensionInfo}'s without components, and small size. *///from w w w . j a v a2 s .c o m private static <T extends DimensionInfo> void removeEmptyDimensions(DimensionOperations<T> operations, Set<Integer> filledDimensions) throws Exception { LinkedList<T> dimensions = operations.getDimensions(); for (int i = dimensions.size() - 1; i >= 0; i--) { T dimension = dimensions.get(i); if (!filledDimensions.contains(i) && dimension.getSize() < 30) { operations.delete(i); } } }
From source file:org.samjoey.graphing.GraphUtility.java
public static HashMap<String, ChartPanel> getGraphs(LinkedList<Game> games) { HashMap<String, XYSeriesCollection> datasets = new HashMap<>(); for (int j = 0; j < games.size(); j++) { Game game = games.get(j); if (game == null) { continue; }//from www .j a v a 2 s. c o m for (String key : game.getVarData().keySet()) { if (datasets.containsKey(key)) { try { datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } catch (Exception e) { } } else { datasets.put(key, new XYSeriesCollection()); datasets.get(key).addSeries(createSeries(game.getVar(key), "" + game.getId())); } } } HashMap<String, ChartPanel> chartPanels = new HashMap<>(); for (String key : datasets.keySet()) { JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title "X", // x axis label "Y", // y axis label datasets.get(key), // data PlotOrientation.VERTICAL, false, // include legend true, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); XYItemRenderer rend = plot.getRenderer(); for (int i = 0; i < games.size(); i++) { Game g = games.get(i); if (g.getWinner() == 1) { rend.setSeriesPaint(i, Color.RED); } if (g.getWinner() == 2) { rend.setSeriesPaint(i, Color.BLACK); } if (g.getWinner() == 0) { rend.setSeriesPaint(i, Color.PINK); } } ChartPanel chartPanel = new ChartPanel(chart); chartPanels.put(key, chartPanel); } return chartPanels; }
From source file:fr.inria.oak.paxquery.common.xml.navigation.NavigationTreePatternUtils.java
/** * /* www. jav a 2 s . c o m*/ */ public static String getParsableStringFromTreePattern(NavigationTreePattern p) { String nodes = ""; String edges = ""; String file = ""; LinkedList<NavigationTreePatternNode> nodesList = p.getNodes(); try { for (int j = 0; j < p.getNodesNo(); j++) { NavigationTreePatternNode dummy = nodesList.get(j); if (dummy.isAttribute()) { nodes += "A: "; } else nodes += "E: "; nodes += dummy.getNodeCode(); if (dummy.storesID()) { nodes += " ID "; if (dummy.isIdentityIDType()) nodes += "i"; else if (dummy.isOrderIDType()) nodes += "o"; else if (dummy.isStructIDType()) nodes += "s"; else if (dummy.isUpdateIDType()) nodes += "u"; } if (dummy.requiresID()) { nodes += " R "; } if (dummy.selectsTag()) { if (dummy.getNamespace().compareTo("") != 0) nodes += " [Tag=\"" + START_NAMESPACE_DELIMITER + dummy.getNamespace() + END_NAMESPACE_DELIMITER + dummy.getTag() + "\"]"; else nodes += " [Tag=\"" + dummy.getTag() + "\"]"; } if (dummy.storesTag()) { nodes += " Tag"; } if (dummy.requiresTag()) { nodes += " R "; } if (dummy.selectsValue()) { nodes += " [Val" + dummy.getSelectOnValuePredicate().toString() + (dummy.getStringValue() != null ? "\"" + dummy.getStringValue() + "\"" : (int) dummy.getDoubleValue()) + "]"; } if (dummy.storesValue()) { nodes += " Val"; } if (dummy.requiresVal()) { nodes += " R "; } if (dummy.storesContent()) { nodes += " Cont"; } nodes += "\n"; for (int k = 0; k < dummy.getEdges().size(); k++) { NavigationTreePatternEdge edge = dummy.getEdges().get(k); edges += edge.n1.getNodeCode() + "," + edge.n2.getNodeCode(); edges += (edge.isParent()) ? " / " : " // "; edges += edge.isNested() ? "n" : ""; edges += edge.isOptional() ? "o" : "j"; edges += "\n"; } } } catch (Exception e) { logger.error("Exception: ", e); } file = (p.isOrdered() ? "o " : " ") + (p.getRoot().getEdges().get(0).isParent() ? "/\n" : "\n") + nodes + ";\n" + edges; return file; }
From source file:br.edu.ufcg.supervisor.engine.Simulation.java
public static void executeModel(JSONObject r, Automaton model, HashMap<String, Float> map1, HashMap<Integer, Float> map2, String currentState, String recommendation, String logString) throws Exception { ArrayList<String> names = LoadedModel.getNomesVariaveisMonitoradas(); ArrayList<String> arrayMensagens = new ArrayList<String>(); for (int i = 0; i < map1.size(); i++) { currentState = currentState + "- " + names.get(i) + ": " + map1.get(names.get(i)) + ".<br>"; }//from w w w. ja va2 s . c o m logString = logString + currentState + " - "; r.put("cur", currentState); State estado = model.buscaEstadoCorrespondente(map2); if (!(estado.getClassificacao() == State.INT_CL_ACEITACAO)) { Search alg = new Search(model); alg.execute(estado); for (State estadoAceito : model.getArrayEstadosAceitos()) { LinkedList<State> caminho = alg.getPath(estadoAceito); if (caminho != null) { for (int j = 0; j < caminho.size() - 1; j++) recommendation += "." + model.getMensagemDasTransicoesEntreDoisEstadosQuaisquer( caminho.get(j), caminho.get(j + 1));//elthon arrayMensagens.add(recommendation); } } recommendation = getShortestPath(arrayMensagens); recommendation = eliminateReplicatedRecommendations(recommendation); if (recommendation.equals(".")) recommendation = "Some variable has not been measured!"; logString = logString + recommendation + "\n"; } else { recommendation = "Keep going!"; logString = logString + "(" + recommendation + ")\n"; } r.put("rec", recommendation); }
From source file:org.dswarm.common.model.util.AttributePathUtil.java
public static String generateAttributePath(final LinkedList<Attribute> attributes) { if (attributes == null || attributes.isEmpty()) { return null; }// w w w . j av a 2 s . c om final StringBuilder sb = new StringBuilder(); for (int i = 0; i < attributes.size(); i++) { sb.append(attributes.get(i)); if (i < (attributes.size() - 1)) { sb.append(DMPStatics.ATTRIBUTE_DELIMITER); } } return sb.toString(); }