List of usage examples for java.util List set
E set(int index, E element);
From source file:com.redhat.lightblue.crud.mongo.MongoCRUDController.java
private void validateIndexFields(EntityInfo ei) { for (Index ix : ei.getIndexes().getIndexes()) { List<SortKey> fields = ix.getFields(); List<SortKey> newFields = null; boolean copied = false; int i = 0; for (SortKey key : fields) { Path p = key.getField(); Path newPath = translateIndexPath(p); if (!p.equals(newPath)) { SortKey newKey = new SortKey(newPath, key.isDesc()); if (!copied) { newFields = new ArrayList<>(); newFields.addAll(fields); copied = true;/* w w w . j ava2s . c o m*/ } newFields.set(i, newKey); } } if (copied) { ix.setFields(newFields); LOGGER.debug("Index rewritten as {}", ix); } } }
From source file:com.liferay.ide.server.core.portal.PortalServerBehavior.java
private void _replaceJREConatiner(List<IRuntimeClasspathEntry> oldCp, IRuntimeClasspathEntry newJRECp) { int size = oldCp.size(); for (int i = 0; i < size; i++) { IRuntimeClasspathEntry entry2 = oldCp.get(i); IPath entry2Path = entry2.getPath(); IPath entry2PathSeg2 = entry2Path.uptoSegment(2); if (entry2PathSeg2.isPrefixOf(newJRECp.getPath())) { oldCp.set(i, newJRECp); return; }/*from www . j av a 2 s . com*/ } oldCp.add(0, newJRECp); }
From source file:com.google.gwt.emultest.java.util.ListTestBase.java
public void testSubList() { List<Integer> wrappedList = createListWithContent(new int[] { 1, 2, 3, 4, 5 }); List<Integer> testList = wrappedList.subList(1, 4); assertEquals(3, testList.size());/* ww w. j a va 2 s .co m*/ assertEquals(testList, Arrays.asList(2, 3, 4)); checkListSizeAndContent(testList, 2, 3, 4); testList.add(1, 6); assertEquals(testList, Arrays.asList(2, 6, 3, 4)); checkListSizeAndContent(testList, 2, 6, 3, 4); assertEquals(wrappedList, Arrays.asList(1, 2, 6, 3, 4, 5)); checkListSizeAndContent(wrappedList, 1, 2, 6, 3, 4, 5); testList.remove(2); assertEquals(testList, Arrays.asList(2, 6, 4)); checkListSizeAndContent(testList, 2, 6, 4); try { testList.remove(3); fail("Expected remove to fail"); } catch (IndexOutOfBoundsException e) { } checkListSizeAndContent(wrappedList, 1, 2, 6, 4, 5); testList.set(0, 7); checkListSizeAndContent(testList, 7, 6, 4); checkListSizeAndContent(wrappedList, 1, 7, 6, 4, 5); try { wrappedList.subList(-1, 5); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 15); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(5, 1); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { } try { wrappedList.subList(0, 1).add(2, 5); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).add(-1, 5); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).get(1); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).get(-1); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).set(2, 2); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } try { wrappedList.subList(0, 1).set(-1, 5); fail("expected IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { } }
From source file:com.act.lcms.v2.TraceIndexExtractor.java
private void writeTracesToDB(RocksDBAndHandles<COLUMN_FAMILIES> dbAndHandles, List<Double> times, List<List<Double>> allTraces) throws RocksDBException, IOException { LOGGER.info("Writing timepoints to on-disk index (%d points)", times.size()); dbAndHandles.put(COLUMN_FAMILIES.TIMEPOINTS, TIMEPOINTS_KEY, serializeDoubleList(times)); for (int i = 0; i < allTraces.size(); i++) { byte[] keyBytes = serializeObject(i); byte[] valBytes = serializeDoubleList(allTraces.get(i)); dbAndHandles.put(COLUMN_FAMILIES.ID_TO_TRACE, keyBytes, valBytes); if (i % 1000 == 0) { LOGGER.info("Finished writing %d traces", i); }//from ww w . java 2 s . co m // Drop this trace as soon as it's written so the GC can pick it up and hopefully reduce memory pressure. allTraces.set(i, Collections.emptyList()); } dbAndHandles.getDb().flush(new FlushOptions()); LOGGER.info("Done writing trace data to index"); }
From source file:org.wallerlab.yoink.cube.service.VoronoiCalculator.java
private void getTwoClosestNeighbours(List<Atom> twoNeighbours, List<Double> neighbourDistances, Atom atom, double distance, List<Molecule> twoMolecules, Molecule molecule) { int size = neighbourDistances.size(); switch (size) { case 0://from ww w .ja v a 2 s. c om // add one neighbour neighbourDistances.add(0, distance); twoNeighbours.add(0, atom); twoMolecules.add(0, molecule); break; case 1: // add one more neighbour.the first neighbour is the closer one neighbourDistances.add(1, distance); twoNeighbours.add(1, atom); twoMolecules.add(1, molecule); if (neighbourDistances.get(0) >= neighbourDistances.get(1)) { Collections.reverse(neighbourDistances); Collections.reverse(twoNeighbours); Collections.reverse(twoMolecules); } break; case 2:// compare current distance with the distance of second // neighbour, if true, replace second neighbor and compare with // the first neighbour if (neighbourDistances.get(1) >= distance) { neighbourDistances.set(1, distance); twoNeighbours.set(1, atom); twoMolecules.set(1, molecule); if (neighbourDistances.get(0) >= neighbourDistances.get(1)) { Collections.reverse(neighbourDistances); Collections.reverse(twoNeighbours); Collections.reverse(twoMolecules); } } break; default: throw new IllegalArgumentException("Invalid type of size: " + size); } }
From source file:com.gnadenheimer.mg.utils.Utils.java
public List<CuotaModel> getCuotas(TblEventoCuotas eventoCuotas, Integer monto) { List<LocalDate> fechas = getCuotasFechas(eventoCuotas); List<CuotaModel> listCuotas = new ArrayList<>(); float divi = monto * 1.0F / fechas.size(); Integer montoCuota = Math.round(divi); for (LocalDate fecha : fechas) { CuotaModel cuota = new CuotaModel(); cuota.setFecha(fecha);/*from w ww .j a v a 2 s .com*/ cuota.setMonto(montoCuota); listCuotas.add(cuota); } if (montoCuota * fechas.size() > monto) { CuotaModel cuota = new CuotaModel(); cuota.setFecha(listCuotas.get(listCuotas.size() - 1).getFecha()); cuota.setMonto(montoCuota - 1); listCuotas.set(listCuotas.size() - 1, cuota); } else if (montoCuota * fechas.size() < monto) { CuotaModel cuota = new CuotaModel(); cuota.setFecha(listCuotas.get(listCuotas.size() - 1).getFecha()); cuota.setMonto(montoCuota + 1); listCuotas.set(listCuotas.size() - 1, cuota); } return listCuotas; }
From source file:com.streamsets.pipeline.lib.salesforce.SobjectRecordCreator.java
private void getAllReferences(PartnerConnection partnerConnection, Map<String, ObjectMetadata> metadataMap, List<List<Pair<String, String>>> references, String[] allTypes, int depth) throws ConnectionException { if (depth < 0) { return;//from ww w . ja v a 2 s.c om } List<String> next = new ArrayList<>(); for (int typeIndex = 0; typeIndex < allTypes.length; typeIndex += MAX_METADATA_TYPES) { int copyTo = Math.min(typeIndex + MAX_METADATA_TYPES, allTypes.length); String[] types = Arrays.copyOfRange(allTypes, typeIndex, copyTo); // Special case - we prepopulate the cache with the root sobject type - don't repeat // ourselves if (types.length > 1 || !metadataMap.containsKey(types[0])) { for (DescribeSObjectResult result : partnerConnection.describeSObjects(types)) { Map<String, Field> fieldMap = new LinkedHashMap<>(); Map<String, Field> relationshipMap = new LinkedHashMap<>(); for (Field field : result.getFields()) { fieldMap.put(field.getName().toLowerCase(), field); String relationshipName = field.getRelationshipName(); if (relationshipName != null) { relationshipMap.put(relationshipName.toLowerCase(), field); } } Map<String, String> childRelationships = new LinkedHashMap<>(); for (ChildRelationship child : result.getChildRelationships()) { if (child.getRelationshipName() != null) { childRelationships.put(child.getRelationshipName().toLowerCase(), child.getChildSObject().toLowerCase()); } } metadataMap.put(result.getName().toLowerCase(), new ObjectMetadata(fieldMap, relationshipMap, childRelationships)); } } if (references != null) { for (List<Pair<String, String>> path : references) { // Top field name in the path should be in the metadata now if (!path.isEmpty()) { Pair<String, String> top = path.get(0); Field field = metadataMap.get(top.getLeft()).getFieldFromRelationship(top.getRight()); Set<String> sobjectNames = metadataMap.keySet(); for (String ref : field.getReferenceTo()) { ref = ref.toLowerCase(); if (!sobjectNames.contains(ref) && !next.contains(ref)) { next.add(ref); } if (path.size() > 1) { path.set(1, Pair.of(ref, path.get(1).getRight())); } } // SDC-10422 Polymorphic references have an implicit reference to the Name object type if (field.isPolymorphicForeignKey()) { next.add(NAME); } path.remove(0); } } } } if (!next.isEmpty()) { getAllReferences(partnerConnection, metadataMap, references, next.toArray(new String[0]), depth - 1); } }
From source file:org.openmrs.module.pmtct.web.view.chart.InfantPCRPieChartView.java
/** * @see org.openmrs.module.pmtct.web.view.chart.AbstractChartView#createChart(java.util.Map, * javax.servlet.http.HttpServletRequest) *///from ww w.j a v a 2 s .co m @Override protected JFreeChart createChart(Map<String, Object> model, HttpServletRequest request) { UserContext userContext = Context.getUserContext(); ApplicationContext appContext = ContextProvider.getApplicationContext(); PMTCTModuleTag tag = new PMTCTModuleTag(); List<Object> res = new ArrayList<Object>(); DefaultPieDataset pieDataset = new DefaultPieDataset(); String title = "", descriptionTitle = "", dateInterval = ""; Concept concept = null; SimpleDateFormat df = Context.getDateFormat(); // Date myDate1 = new Date("1/1/" + ((new Date()).getYear() + 1900)); // String startDate1 = df.format(myDate1); Date today = new Date(); Date oneYearFromNow = new Date(new Date().getTime() - PMTCTConstants.YEAR_IN_MILLISECONDS); String endDate1 = df.format(today); String startDate1 = df.format(oneYearFromNow); dateInterval = "(" + new SimpleDateFormat("dd-MMM-yyyy").format(oneYearFromNow) + " - " + new SimpleDateFormat("dd-MMM-yyyy").format(today) + ")"; try { PmtctService pmtct; pmtct = Context.getService(PmtctService.class); try { res = pmtct.getGeneralStatForInfantTests_Charting_PCR(startDate1, endDate1); } catch (SQLException ex) { ex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } List<String> hivTestResultOptions = new ArrayList<String>(); List<Integer> pcr_hivTestResultValues = new ArrayList<Integer>(); Collection<ConceptAnswer> answers = Context.getConceptService() .getConcept(PMTCTConstants.RESULT_OF_HIV_TEST).getAnswers(); for (ConceptAnswer str : answers) { hivTestResultOptions.add(str.getAnswerConcept().getName().getName()); pcr_hivTestResultValues.add(0); } hivTestResultOptions.add("Others"); pcr_hivTestResultValues.add(0); for (Object ob : res) { int val = 0; String temp = "", pcr_hivTestResult = ""; temp = "" + ((Object[]) ob)[2]; val = (temp.compareTo("") == 0) ? 0 : Integer.parseInt(temp); if (val > 0) pcr_hivTestResult = tag.getConceptNameById(temp); int i = 0; boolean pcr_found = false; for (String s : hivTestResultOptions) { if ((s.compareToIgnoreCase(pcr_hivTestResult)) == 0) { pcr_hivTestResultValues.set(i, pcr_hivTestResultValues.get(i) + 1); pcr_found = true; } i++; } if (!pcr_found) { pcr_hivTestResultValues.set(pcr_hivTestResultValues.size() - 1, pcr_hivTestResultValues.get(pcr_hivTestResultValues.size() - 1) + 1); } } int i = 0; for (String s : hivTestResultOptions) { if (pcr_hivTestResultValues.get(i) > 0) { Float percentage = new Float(100 * pcr_hivTestResultValues.get(i) / res.size()); pieDataset.setValue(s + " (" + pcr_hivTestResultValues.get(i) + " , " + percentage + "%)", percentage); } i++; } title = appContext.getMessage("pmtct.menu.infantTest", null, userContext.getLocale()); concept = null; descriptionTitle = Context.getEncounterService() .getEncounterType(PMTCTConfigurationUtils.getPCRTestEncounterTypeId()).getName(); descriptionTitle += dateInterval; } catch (Exception ex) { ex.printStackTrace(); } JFreeChart chart = ChartFactory.createPieChart(title + " : " + ((null != concept) ? concept.getPreferredName(userContext.getLocale()) : descriptionTitle), pieDataset, true, true, false); return chart; }
From source file:de.tudarmstadt.ukp.clarin.webanno.tsv.WebannoTsv3Writer.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { OutputStream docOS = null;//from ww w . j av a 2s. c o m try { docOS = getOutputStream(aJCas, filenameSuffix); setSlotLinkTypes(); setLinkMaps(aJCas); setTokenSentenceAddress(aJCas); setAmbiguity(aJCas); setSpanAnnotation(aJCas); setChainAnnotation(aJCas); setRelationAnnotation(aJCas); writeHeader(docOS); for (AnnotationUnit unit : units) { if (sentenceUnits.containsKey(unit)) { String[] sentWithNl = sentenceUnits.get(unit).split("\n"); IOUtils.write(LF + "#Text=" + sentWithNl[0] + LF, docOS, encoding); // if sentence contains new line character // GITHUB ISSUE 318: New line in sentence should be exported as is if (sentWithNl.length > 1) { for (int i = 0; i < sentWithNl.length - 1; i++) { IOUtils.write("#Text=" + sentWithNl[i + 1] + LF, docOS, encoding); } } } if (unit.isSubtoken) { IOUtils.write( unitsLineNumber.get(unit) + TAB + unit.begin + "-" + unit.end + TAB + unit.token + TAB, docOS, encoding); } else { IOUtils.write( unitsLineNumber.get(unit) + TAB + unit.begin + "-" + unit.end + TAB + unit.token + TAB, docOS, encoding); } for (String type : featurePerLayer.keySet()) { List<List<String>> annos = annotationsPerPostion.getOrDefault(type, new HashMap<>()) .getOrDefault(unit, new ArrayList<>()); List<String> merged = null; for (List<String> annofs : annos) { if (merged == null) { merged = annofs; } else { for (int i = 0; i < annofs.size(); i++) { merged.set(i, merged.get(i) + "|" + annofs.get(i)); } } } if (merged != null) { for (String anno : merged) { IOUtils.write(anno + TAB, docOS, encoding); } } // No annotation of this type in this layer else { // if type do not have a feature, if (featurePerLayer.get(type).size() == 0) { IOUtils.write("_" + TAB, docOS, encoding); } else { for (String feature : featurePerLayer.get(type)) { IOUtils.write("_" + TAB, docOS, encoding); } } } } IOUtils.write(LF, docOS, encoding); } } catch (Exception e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(docOS); } }