List of usage examples for java.util List set
E set(int index, E element);
From source file:org.callimachusproject.auth.DetachedRealm.java
private List<String> getDistinctRealm(String domains) { List<String> realms = new ArrayList<String>(); if (domains.contains(" ")) { loop: for (String url : domains.split("\\s+")) { if (url.length() > 0) { for (int i = 0, n = realms.size(); i < n; i++) { String pre = realms.get(i); if (pre == null || pre.startsWith(url)) { realms.set(i, url); continue loop; } else if (url.startsWith(pre)) { continue loop; }/*from ww w . j a v a 2s . c o m*/ } realms.add(url); } } return realms; } else { return Collections.singletonList(domains); } }
From source file:com.t_oster.liblasercut.drivers.LaosCutter.java
/** * This Method takes a raster-line represented by a list of bytes, * where: byte0 ist the left-most byte, in one byte, the MSB is the * left-most bit, 0 representing laser off, 1 representing laser on. * The Output List of longs, where each value is the unsigned dword * of 4 bytes of the input each, where the first dword is the leftmost * dword and the LSB is the leftmost bit. If outputLeftToRight is false, * the first dword is the rightmost dword and the LSB of each dword is the * the Output is padded with zeroes on the right side, if leftToRight is true, * on the left-side otherwise// w w w .ja va2 s.c o m * rightmost bit * @param line * @param outputLeftToRight * @return */ public List<Long> byteLineToDwords(List<Byte> line, boolean outputLeftToRight) { List<Long> result = new ArrayList<Long>(); int s = line.size(); for (int i = 0; i < s; i++) { line.set(i, (byte) (Integer.reverse(0xFF & line.get(i)) >>> 24)); } for (int i = 0; i < s; i += 4) { result.add((((long) (i + 3 < s ? 0xFF & line.get(i + 3) : 0)) << 24) + (((long) (i + 2 < s ? 0xFF & line.get(i + 2) : 0)) << 16) + (((long) (i + 1 < s ? 0xFF & line.get(i + 1) : 0)) << 8) + ((long) (0xFF & line.get(i)))); } if (!outputLeftToRight) { Collections.reverse(result); for (int i = 0; i < result.size(); i++) { result.set(i, Long.reverse(result.get(i)) >>> 32); } } return result; }
From source file:com.xpn.xwiki.objects.classes.DBTreeListClass.java
private void mergeItems(List<ListItem> itemPath, List<List<ListItem>> resList) { if (itemPath == null || itemPath.size() == 0) { return;//from w ww . j av a 2 s . c om } for (int i = 0; i < resList.size(); i++) { List<ListItem> items = resList.get(i); if (items.size() < itemPath.size()) { ListItem item1 = items.get(items.size() - 1); ListItem item2 = itemPath.get(items.size() - 1); if (item1.equals(item2)) { resList.set(i, itemPath); return; } } else { ListItem item1 = items.get(itemPath.size() - 1); ListItem item2 = itemPath.get(itemPath.size() - 1); if (item1.equals(item2)) { return; } } } resList.add(itemPath); }
From source file:io.hops.experiments.results.compiler.RawBMResultAggregator.java
CompiledResults processAllRecords() { CompiledResults cr = new CompiledResults(); System.out.println("Generating compiled results for RAW Benchmarks"); if (allResults.isEmpty()) { return cr; }/*from w w w .j a va 2 s . co m*/ SortedSet<Integer> sorted = new TreeSet<Integer>(); // Sort my number of NN sorted.addAll(allResults.keySet()); for (Integer key : sorted) { cr.nnCounts.add(key); Map<BenchmarkOperations, RawAggregate> map = allResults.get(key); for (BenchmarkOperations op : map.keySet()) { RawAggregate agg = map.get(op); List<Double> vals = cr.valsMap.get(op); if (vals == null) { vals = new ArrayList<Double>(); cr.valsMap.put(op, vals); } vals.add(agg.getSpeed()); } } //create histogram for (BenchmarkOperations op : cr.valsMap.keySet()) { List<Double> vals = cr.valsMap.get(op); Double max = new Double(0); for (int i = 0; i < vals.size(); i++) { if (i > 0) { if (vals.get(i) < max) { vals.set(i, max); } } max = vals.get(i); } } //create histogram for (BenchmarkOperations op : cr.valsMap.keySet()) { List<Double> vals = cr.valsMap.get(op); List<Double> histo = cr.histoMap.get(op); if (histo == null) { histo = new ArrayList<Double>(); cr.histoMap.put(op, histo); } Double previousVal = null; for (Double val : vals) { double diff = 0; if (previousVal == null) { previousVal = val; diff = val; } else { diff = (val - previousVal); if (diff < 0) { diff = 0; } previousVal = val; } histo.add(diff); } } return cr; }
From source file:edu.scripps.fl.pubchem.PubChemXMLParserFactory.java
protected void populateAssayResultsFromXML(PCAssay assay, Node assayDescriptionNode) throws Exception { List<PCAssayResult> results = null; List<Node> assayResultNodes = assayDescriptionNode .selectNodes("../../../PC-AssaySubmit_data/PC-AssayResults"); if (assayResultNodes.size() == 0) return;// w w w. j a v a 2 s .c om else results = new ArrayList<PCAssayResult>(assayResultNodes.size()); List<PCAssayColumn> testedCols = assay.getTestedColumns(); PCAssayColumn activeColumn = assay.getActiveColumn(); for (Node resultNode : assayResultNodes) { PCAssayResult result = new PCAssayResult(); String val = resultNode.selectSingleNode("PC-AssayResults_sid").valueOf("text()"); result.setSID(Long.parseLong(val)); val = resultNode.selectSingleNode("PC-AssayResults_outcome").valueOf("@value"); val = val.substring(0, 1).toUpperCase() + val.substring(1); result.setOutcome(val); val = resultNode.selectSingleNode("PC-AssayResults_rank").valueOf("text()"); result.setRankScore(Integer.parseInt(val)); List<Node> assayDataNodes = resultNode.selectNodes("PC-AssayResults_data/PC-AssayData"); List<String> all = GrowthList.decorate(new ArrayList(assay.getColumns().size() - 2)); result.setAllValues(all); for (Node node : assayDataNodes) { val = node.valueOf("PC-AssayData_tid/text()"); int index = Integer.parseInt(val) - 1; val = node.selectSingleNode(".//*[starts-with(name(),'PC-AssayData_value_')]").getText(); all.set(index, val); } // if a dose response assay with a marked activeConcentration if ("confirmatory".equals(assay.getActivityOutcomeMethod()) && activeColumn != null) { String actConc = all.get(activeColumn.getTID() - 1); if (null != actConc && !"".equals(actConc)) { result.setPrimaryValue(Double.valueOf(actConc)); result.setPrimaryColumn(activeColumn); PCAssayColumn qualCol = assay.getQualifierColumn(); if (qualCol != null) { String qual = all.get(qualCol.getTID() - 1); if (!"".equals(qual)) result.setQualifier(qual); } } } else if ("screening".equals(assay.getActivityOutcomeMethod()) && testedCols.size() > 0) { PCAssayColumn testedCol = testedCols.get(0); String value = all.get(testedCol.getTID() - 1); result.setPrimaryColumn(testedCol); if (null != value && !"".equals(value)) if ("float".equals(testedCol.getType()) || "int".equals(testedCol.getType())) result.setPrimaryValue(Double.parseDouble(value)); else result.setPrimaryValueAsString(value); } // put all testedConcentration columns into an ordered array. Interested in numbers here only. result.getTestedValues().clear(); for (int ii = 0; ii < testedCols.size(); ii++) { PCAssayColumn testedCol = testedCols.get(ii); String value = all.get(testedCol.getTID() - 1); if (null != value && !"".equals(value)) { try { Double dbl = Double.parseDouble(value); result.getTestedValues().set(ii, dbl); } catch (NumberFormatException ex) { // if not a number then don't worry about it. } } } assay.getResults().add(result); } }
From source file:hoot.services.controllers.job.ReviewResourceMarkTest.java
@Test @Category(UnitTest.class) public void testMarkItemReviewedAgainstInvalidReviewAgainstItem() throws Exception { //If an item is marked as reviewed against something it wasn't supposed to be reviewed against //in the services database, we don't fail. A warning is logged only. ReviewTestUtils.createPreparedData(resource()); //add an additional reviewed item that is invalid b/c its review against item is incorrect ReviewedItems reviewedItems = ReviewTestUtils.createReviewedItems(); ReviewedItem[] reviewedItemsArr = reviewedItems.getReviewedItems(); List<ReviewedItem> reviewedItemsList = new ArrayList<ReviewedItem>(Arrays.asList(reviewedItemsArr)); ReviewedItem invalidReviewedItem = reviewedItemsList.get(0); //set item to be reviewed against itself invalidReviewedItem.setReviewedAgainstId(ReviewTestUtils.nodeIds.get((long) -64)); invalidReviewedItem.setReviewedAgainstType(ElementType.Node.toString().toLowerCase()); reviewedItemsList.set(0, invalidReviewedItem); reviewedItemsArr = reviewedItemsList.toArray(new ReviewedItem[] {}); reviewedItems.setReviewedItems(reviewedItemsArr); MarkItemsReviewedRequest markItemsReviewedRequest = new MarkItemsReviewedRequest(); markItemsReviewedRequest.setReviewedItems(ReviewTestUtils.createReviewedItems()); markItemsReviewedRequest.setReviewedItemsChangeset( XmlDocumentBuilder.toString(ReviewTestUtils.createReviewedItemsChangeset())); //the request should fail and nothing should be written try {//from w w w. j av a 2s.com execMark(String.valueOf(mapId), String.valueOf(false), markItemsReviewedRequest); } catch (UniformInterfaceException e) { Assert.assertEquals(Status.BAD_REQUEST.getStatusCode(), e.getResponse().getStatus()); Assert.assertTrue(e.getResponse().getEntity(String.class).contains("Error parsing unique ID tag")); ReviewTestUtils.verifyDataNotMarkedAsReviewed(); throw e; } }
From source file:com.constellio.app.services.appManagement.AppManagementService.java
private void updateWrapperConf(File deployFolder) { LOGGER.info("New webapp path is '" + deployFolder.getAbsolutePath() + "'"); File wrapperConf = foldersLocator.getWrapperConf(); if (foldersLocator.getFoldersLocatorMode().equals(FoldersLocatorMode.PROJECT) && !wrapperConf.exists()) { return;/*from w ww .ja v a2s .co m*/ } List<String> lines = fileService.readFileToLinesWithoutExpectableIOException(wrapperConf); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (line.startsWith("wrapper.java.classpath.2=")) { lines.set(i, "wrapper.java.classpath.2=" + deployFolder.getAbsolutePath() + "/WEB-INF/lib/*.jar"); } if (line.startsWith("wrapper.java.classpath.3=")) { lines.set(i, "wrapper.java.classpath.3=" + deployFolder.getAbsolutePath() + "/WEB-INF/classes"); } if (line.startsWith("wrapper.commandfile=")) { lines.set(i, "wrapper.commandfile=" + deployFolder.getAbsolutePath() + "/WEB-INF/command/cmd"); } } fileService.writeLinesToFile(wrapperConf, lines); }
From source file:org.shredzone.cilla.admin.page.gallery.GalleryBean.java
/** * Moves a picture within the picture list. * * @param picture//from w w w . j av a2 s. c o m * {@link PictureDto} to be moved * @param relative * Relative new position of the picture */ public void moveImage(PictureDto picture, int relative) { synchronized (this) { List<PictureDto> list = section.getPictures(); int current = list.indexOf(picture); if (current < 0) { return; } int target = current + relative; if (target < 0) { // Item moved out from the left, wrap around PictureDto wrap = list.remove(current); list.add(list.size() + 1 + target, wrap); } else if (target >= list.size()) { // Item moved out from the right, wrap around PictureDto wrap = list.remove(current); list.add(target - list.size() - 1, wrap); } else { // No wrap-around: just swap the items PictureDto swap = list.get(target); list.set(target, picture); list.set(current, swap); } } }
From source file:edu.utah.further.core.query.domain.SearchCriterionTo.java
/** * @param parameters/*w w w . j a va 2s. co m*/ * @return */ private SearchCriterionTo setParameters(final List<?> parameters) { if (parameters == null) { this.parameters = null; } else { //Would like to have used XMLTypeAdapter on parameters but can't //http://java.net/jira/browse/JAXB-359 //http://www.java.net/node/665119 final List<Object> params = newList(parameters); for (int i = 0; i < params.size(); i++) { if (ReflectionUtil.instanceOf(params.get(i), XMLGregorianCalendar.class)) { final Date date = ((XMLGregorianCalendar) params.get(i)).toGregorianCalendar().getTime(); params.set(i, date); } } this.parameters = params; } return this; }
From source file:org.wallerlab.yoink.cube.service.CubeBuilderImpl.java
private List<Coord> getAllCoordinates(Cube cube) { Coord[] initialValues = new SimpleCoord[cube.getSize()]; List<Coord> coordinates = Collections.synchronizedList(Arrays.asList(initialValues)); IntStream.range(0, cube.getNumberOfXYZSteps()[0]).parallel().forEach(nXStep -> { for (int nYStep = 0; nYStep < cube.getNumberOfXYZSteps()[1]; nYStep++) { for (int nZStep = 0; nZStep < cube.getNumberOfXYZSteps()[2]; nZStep++) { // get the coordinate in cube int[] xyzCurrentStep = new int[] { nXStep, nYStep, nZStep }; Coord currentCoord = coordInCubeCalculator.calculate(xyzCurrentStep, cube); // get the index of a grid point in cube int indexInCube = nXStep * cube.getNumberOfXYZSteps()[1] * cube.getNumberOfXYZSteps()[2] + nYStep * cube.getNumberOfXYZSteps()[2] + nZStep; coordinates.set(indexInCube, currentCoord); }/*from w w w . j a v a2 s.c o m*/ } }); return coordinates; }