List of usage examples for java.util List indexOf
int indexOf(Object o);
From source file:edu.ksu.cis.indus.tools.slicer.criteria.specification.SliceCriterionSpec.java
/** * Retrieves the specification for the given criterion relative to <code>scene</code>. * * @param criterion for which the specification should be generated. * * @return the specification./* ww w. j av a 2 s. c om*/ * * @throws IllegalStateException when an error occurs while creating the criterion. * * @pre criterion != null and scene != null * @post result != null */ static Collection<SliceCriterionSpec> getCriterionSpec(final ISliceCriterion criterion) { final SootMethod _method = criterion.getOccurringMethod(); final SootClass _declaringClass = _method.getDeclaringClass(); final String _prefix = _declaringClass.getPackageName(); final String _shortJavaStyleName = _declaringClass.getShortJavaStyleName(); final String _className; if (_prefix.length() != 0) { _className = _prefix + "." + _shortJavaStyleName; } else { _className = _shortJavaStyleName; } final String _methodName = _method.getName(); final Collection<SliceCriterionSpec> _result; if (!_method.isAbstract() && !_method.isNative()) { final Body _body = _method.retrieveActiveBody(); if (_body == null) { final String _msg = _method.getSignature() + " does not have a body."; LOGGER.error(_msg); throw new IllegalStateException(_msg); } final List<Stmt> _stmts = Collections.list(Collections.<Stmt>enumeration(_body.getUnits())); final Stmt _occurringStmt = CriteriaSpecHelper.getOccurringStmt(criterion); final int _stmtIndex = _stmts.indexOf(_occurringStmt); final boolean _considerExecution = CriteriaSpecHelper.isConsiderExecution(criterion); final SliceCriterionSpec _spec = new SliceCriterionSpec(); _spec.className = _className; _spec.methodName = _methodName; _spec.parameterTypeNames = getNamesOfTypes(_method.getParameterTypes()); _spec.returnTypeName = _method.getReturnType().toString(); _spec.stmtIndex = _stmtIndex; _spec.exprIndex = -1; _spec.considerExecution = _considerExecution; _spec.considerEntireStmt = false; _result = new ArrayList<SliceCriterionSpec>(); final ValueBox _occurringExprBox = CriteriaSpecHelper.getOccurringExpr(criterion); if (_occurringExprBox != null) { final Value _expr = _occurringExprBox.getValue(); final int _size = _expr.getUseBoxes().size(); if (_size == 0) { _spec.exprIndex = _occurringStmt.getUseAndDefBoxes().indexOf(_occurringExprBox); _result.add(_spec); } else { for (int _i = _size - 1; _i >= 0; _i--) { try { final SliceCriterionSpec _temp = (SliceCriterionSpec) _spec.clone(); _temp.exprIndex = _i; _result.add(_temp); } catch (final CloneNotSupportedException _e) { final String _msg = "Low level Error while creating criterion specification."; LOGGER.error(_msg); throw new IllegalStateException(_msg); } } } } else { _result.add(_spec); } } else { _result = Collections.emptySet(); } return _result; }
From source file:com.jetbrains.pluginUtils.xml.JDOMXIncluder.java
public static Document resolve(@NotNull Document original, @Nullable String base) throws XIncludeException { Document result = (Document) original.clone(); Element root = result.getRootElement(); List<Content> resolved = resolve(root, base); // check that the list returned contains // exactly one root element Element newRoot = null;//from w w w. j a v a2s .com Iterator<Content> iterator = resolved.iterator(); while (iterator.hasNext()) { Content o = iterator.next(); if (o instanceof Element) { if (newRoot != null) { throw new XIncludeException("Tried to include multiple roots"); } newRoot = (Element) o; } else if (o instanceof Comment || o instanceof ProcessingInstruction) { // do nothing } else if (o instanceof Text) { throw new XIncludeException("Tried to include text node outside of root element"); } else if (o instanceof EntityRef) { throw new XIncludeException("Tried to include a general entity reference outside of root element"); } else { throw new XIncludeException("Unexpected type " + o.getClass()); } } if (newRoot == null) { throw new XIncludeException("No root element"); } // Could probably combine two loops List<Content> newContent = result.getContent(); // resolved contains list of new content // use it to replace old root element iterator = resolved.iterator(); // put in nodes before root element int rootPosition = newContent.indexOf(result.getRootElement()); while (iterator.hasNext()) { Content o = iterator.next(); if (o instanceof Comment || o instanceof ProcessingInstruction) { newContent.add(rootPosition, o); rootPosition++; } else if (o instanceof Element) { // the root break; } else { // throw exception???? } } // put in root element result.setRootElement(newRoot); int addPosition = rootPosition + 1; // put in nodes after root element while (iterator.hasNext()) { Content o = iterator.next(); if (o instanceof Comment || o instanceof ProcessingInstruction) { newContent.add(addPosition, o); addPosition++; } else { // throw exception???? } } return result; }
From source file:de.tudarmstadt.ukp.dkpro.tc.core.util.ReportUtils.java
/** * Converts a map containing a matrix into a matrix * /*from w w w .j a v a 2 s. c o m*/ * @param aggregateMap * a map created with {@link ReportUtils#updateAggregateMatrix(Map, File)} * @see ReportUtils#updateAggregateMatrix(Map, File) * @return a table with the matrix */ public static FlexTable<String> createOverallConfusionMatrix(Map<List<String>, Double> aggregateMap) { FlexTable<String> cMTable = FlexTable.forClass(String.class); cMTable.setSortRows(false); Set<String> labelsPred = new TreeSet<String>(); Set<String> labelsAct = new TreeSet<String>(); // sorting rows/columns for (List<String> key : aggregateMap.keySet()) { labelsPred.add(key.get(0).substring(0, key.get(0).indexOf(Constants.CM_PREDICTED))); labelsAct.add(key.get(1).substring(0, key.get(1).indexOf(Constants.CM_ACTUAL))); } List<String> labelsPredL = new ArrayList<String>(labelsPred); List<String> labelsActL = new ArrayList<String>(labelsAct); // create temporary matrix double[][] tempM = new double[labelsAct.size()][labelsPred.size()]; for (List<String> key : aggregateMap.keySet()) { int c = labelsPredL.indexOf(key.get(0).substring(0, key.get(0).indexOf(Constants.CM_PREDICTED))); int r = labelsActL.indexOf(key.get(1).substring(0, key.get(1).indexOf(Constants.CM_ACTUAL))); tempM[r][c] = aggregateMap.get(key); } // convert to FlexTable for (int i = 0; i < tempM.length; i++) { LinkedHashMap<String, String> row = new LinkedHashMap<String, String>(); for (int r = 0; r < tempM[0].length; r++) { row.put(labelsPredL.get(r) + " " + Constants.CM_PREDICTED, String.valueOf(tempM[i][r])); } cMTable.addRow(labelsActL.get(i) + " " + Constants.CM_ACTUAL, row); } return cMTable; }
From source file:io.github.moosbusch.lumpi.util.LumpiUtil.java
public static int indexOf(org.apache.pivot.collections.List<?> listData, Object value) { if (listData != null) { org.apache.pivot.collections.List<Object> data = (org.apache.pivot.collections.List<Object>) listData; return data.indexOf(value); }// w w w .j a v a 2s .co m return -1; }
From source file:edu.cmu.tetrad.search.IndTestFisherZ3.java
/** * Returns the submatrix of m with variables in the order of the x variables. *///from w w w. j a va 2 s .c o m public static TetradMatrix subMatrix(ICovarianceMatrix m, List<Node> x, List<Node> y) { List<Node> variables = m.getVariables(); TetradMatrix _covMatrix = m.getMatrix(); int[] indicesx = new int[x.size()]; int count = 0; for (Node node : x) { indicesx[count++] = variables.indexOf(node); } int[] indicesy = new int[y.size()]; count = 0; for (Node node : y) { indicesy[count++] = variables.indexOf(node); } return _covMatrix.getSelection(indicesx, indicesy); }
From source file:Main.java
/** * Return the priority (0 is the preferred, -1 is not supported) of the rdf MIME type for the REST content negotiation * //w w w . java 2s . c o m * * {talendTypes} String * * {Category} User Defined * * {param} string("mimeString") * * {example} getAcceptableMime("application/rdf+xml") */ public static int getMimePriority(String mimeString) { List<String> acceptableMime = new ArrayList<String>(); acceptableMime.add("application/rdf+xml"); acceptableMime.add("text/rdf+n3"); acceptableMime.add("text/turtle"); acceptableMime.add("text/plain"); acceptableMime.add("text/html"); acceptableMime.add("application/x-json+ld"); acceptableMime.add("application/json"); acceptableMime.add("application/ld+json"); acceptableMime.add("application/trig"); acceptableMime.add("application/x-trig"); acceptableMime.add("application/rdf+json"); // Add mime type here if you want to parse them return (acceptableMime.indexOf(mimeString)); }
From source file:dk.netarkivet.harvester.datamodel.HeritrixTemplate.java
/** * Method to add a list of crawler traps with a given element name. It is * used both to add per-domain traps and global traps. * @param elementName The name of the added element. * @param crawlerTraps A list of crawler trap regular expressions to add * to this job.//from w w w . j a v a 2 s. co m */ @SuppressWarnings("unchecked") public static void editOrderXMLAddCrawlerTraps(Document orderXMLdoc, String elementName, List<String> crawlerTraps) { if (crawlerTraps.size() == 0) { return; } // Get the node to update // If there is an acceptIfPrerequisite decideRule in the template, crawler traps should be // placed before (cf. issue NAS-2205) // If no such rule exists then we append the crawler traps as to the existing decideRuleds. Node rulesMapNode = orderXMLdoc.selectSingleNode(HeritrixTemplate.DECIDERULES_MAP_XPATH); if (rulesMapNode == null || !(rulesMapNode instanceof Element)) { throw new IllegalState("Unable to update order.xml document." + "It does not have the right form to add" + "crawler trap deciderules."); } Element rulesMap = (Element) rulesMapNode; // Create the root node and append it top existing rules Element decideRule = rulesMap.addElement("newObject"); // If an acceptiIfPrerequisite node exists, detach and insert before it Node acceptIfPrerequisiteNode = orderXMLdoc .selectSingleNode(HeritrixTemplate.DECIDERULES_ACCEPT_IF_PREREQUISITE_XPATH); if (acceptIfPrerequisiteNode != null) { List<Node> elements = rulesMap.elements(); int insertPosition = elements.indexOf(acceptIfPrerequisiteNode); decideRule.detach(); elements.add(insertPosition, decideRule); } else { rulesMap.elements().size(); } // Add all regexps in the list to a single MatchesListRegExpDecideRule decideRule.addAttribute("name", elementName); decideRule.addAttribute("class", MatchesListRegExpDecideRule.class.getName()); Element decision = decideRule.addElement("string"); decision.addAttribute("name", "decision"); decision.addText("REJECT"); Element listlogic = decideRule.addElement("string"); listlogic.addAttribute("name", "list-logic"); listlogic.addText("OR"); Element regexpList = decideRule.addElement("stringList"); regexpList.addAttribute("name", "regexp-list"); for (String trap : crawlerTraps) { regexpList.addElement("string").addText(trap); } }
From source file:org.apache.taverna.databundle.DataBundles.java
public static ErrorDocument getError(Path path) throws IOException { if (path == null) return null; Path errorPath = withExtension(path, DOT_ERR); List<String> errorList = readAllLines(errorPath, UTF8); int split = errorList.indexOf(""); if (split == -1 || errorList.size() <= split) throw new IOException("Invalid error document: " + errorPath); ErrorDocument errorDoc = new ErrorDocument(); for (String cause : errorList.subList(0, split)) errorDoc.getCausedBy().add(path.resolveSibling(cause)); errorDoc.setMessage(errorList.get(split + 1)); StringBuilder errorTrace = new StringBuilder(); for (String line : errorList.subList(split + 2, errorList.size())) { errorTrace.append(line);/*w ww. jav a 2 s .c om*/ errorTrace.append("\n"); } if (errorTrace.length() > 0) // Delete last \n errorTrace.deleteCharAt(errorTrace.length() - 1); errorDoc.setTrace(errorTrace.toString()); return errorDoc; }
From source file:de.tynne.benchmarksuite.Main.java
private static void runBenchmarks(Args args, BenchmarkProducer benchmarkProducer) throws IOException { BackupHelper.backupIfNeeded(args.getOutput()); // this looks like NOT comma seperated values, but excel and libreoffice load this automatically final CSVFormat format = CSVFormat.EXCEL.withDelimiter(';').withHeader("#", "ID", "Name", "Min [ns]", "Avg [ns]", "Max [ns]", "Chart Pos", "Best Increase [%]", "Iterations"); try (CSVPrinter printer = new CSVPrinter( new OutputStreamWriter(new FileOutputStream(args.getOutput()), Charset.forName(args.getCharset())), format)) {//from ww w.ja v a 2s .com List<Benchmark> benchmarks = benchmarkProducer.get(); List<Benchmark> matching = benchmarks.stream() .filter(b -> args.getExecute().matcher(b.getId()).matches()).collect(Collectors.toList()); BenchmarkRunner benchmarkRunner = new BenchmarkRunner(matching, BenchmarkRunner.SEC_IN_NANOS * args.getWarumUpTime(), BenchmarkRunner.SEC_IN_NANOS * args.getRunTime()); benchmarkRunner.run(); Chart chart = Chart.of(matching); for (Benchmark b : matching) { try { StatRecord statRecord = chart.getStats().get(b); printer.print(matching.indexOf(b)); printer.print(b.getId()); printer.print(b.getName()); printer.print(format(args, statRecord.getMin())); printer.print(format(args, statRecord.getAverage())); printer.print(format(args, statRecord.getMax())); printer.print(chart.getChart().get(b).chartPosition); double bestAvg = chart.getStats().get(chart.getPerformanceChart().get(0)).getAverage(); double thisAvg = statRecord.getAverage(); printer.print(format(args, 100. * (thisAvg - bestAvg) / bestAvg)); printer.print(statRecord.getCount()); printer.println(); } catch (IOException ex) { ex.printStackTrace(); } } } }
From source file:com.aliyun.openservices.odps.console.utils.CommandParserUtils.java
public static void removeHook(List<String> optionList, ExecutionContext sessionContext) { // hook?command??optioncontext if (optionList.contains("--enablehook")) { if (optionList.indexOf("--enablehook") + 1 < optionList.size()) { int index = optionList.indexOf("--enablehook"); // command String hook = optionList.get(index + 1); // --enablehook ?? optionList.remove(optionList.indexOf("--enablehook")); optionList.remove(optionList.indexOf(hook)); if (!Boolean.valueOf(hook)) { sessionContext.setOdpsHooks(null); }//from w w w. j av a2s.c o m } } }