List of usage examples for java.util ListIterator nextIndex
int nextIndex();
From source file:RedundancyChecker.java
public boolean checkForRedundancy(List l) { ListIterator li1 = l.listIterator(); // Make a // general//from w ww .jav a 2 s . co m // ListIterator // on the list while (li1.hasNext()) { // Store the value of the actual first checked // element of the List, // it needs to be stored because it calls the // .next(), which we can call only once per loop // in order to sweep the whole list. int check1 = ((Integer) li1.next()).intValue(); // Make a second ListIterator that will start // with the element that is just after the // actual first checked one, // in order to avoid checking several times the // same elements. ListIterator li2 = l.listIterator(li1.nextIndex() + 1); while (li2.hasNext()) { // Store the following elements one by // one and check to see if they match // the actual one. int check2 = ((Integer) li2.next()).intValue(); if (check1 == check2) { System.out.println("Oh no! The value " + check1 + " is redundant."); return true; } } // The .next() method has already been called at // the beginning of the loop. } return false; }
From source file:org.openconcerto.openoffice.ODSingleXMLDocument.java
static private int[] getLastNulls(final Map<Tuple2<Namespace, String>, ContentPart> parts, final List<Content> content, final int contentSize) { // start from the end until we leave the epilogue (quicker than traversing the main part as // prologue and epilogue sizes are bounded and small) ContentPart contentPart = null;//from w w w . j av a 2 s . c om final ListIterator<Content> thisChildrenIter = content.listIterator(contentSize); int nullsStartIndex = -1; while ((contentPart == null || contentPart == ContentPart.EPILOGUE) && thisChildrenIter.hasPrevious()) { contentPart = getPart(parts, thisChildrenIter.previous()); if (contentPart != null) { nullsStartIndex = -1; } else if (nullsStartIndex < 0) { nullsStartIndex = thisChildrenIter.nextIndex(); } } final int lastNullsStart = contentPart == null || contentPart == ContentPart.EPILOGUE ? thisChildrenIter.nextIndex() : thisChildrenIter.nextIndex() + 1; final int lastNullsEnd = nullsStartIndex < 0 ? lastNullsStart : nullsStartIndex + 1; return new int[] { lastNullsStart, lastNullsEnd }; }
From source file:mp.teardrop.SongTimeline.java
/** * Remove the song with the given id from the timeline. * * @param id The MediaStore id of the song to remove. *//*from w w w.j av a2s .c o m*/ public void removeSong(long id) { synchronized (this) { saveActiveSongs(); ArrayList<Song> songs = mSongs; ListIterator<Song> it = songs.listIterator(); while (it.hasNext()) { int i = it.nextIndex(); if (Song.getId(it.next()) == id) { if (i < mCurrentPos) --mCurrentPos; it.remove(); } } broadcastChangedSongs(); } changed(); }
From source file:com.net2plan.cli.tools.CLITrafficDesign.java
@Override public void executeFromCommandLine(String[] args) throws ParseException { long init = System.nanoTime(); final CommandLineParser parser = new CommandLineParser(); final CommandLine cli = parser.parse(OPTIONS, args); int numNodes; NetPlan netPlan;/*from w w w .j a v a2 s. c o m*/ if (cli.hasOption("num-nodes") && cli.hasOption("input-file")) throw new ParseException("'num-nodes' and 'input-file' are mutually exclusive"); if (cli.hasOption("num-nodes")) { numNodes = ((Number) cli.getParsedOptionValue("num-nodes")).intValue(); if (numNodes < 2) throw new Net2PlanException("Traffic matrix requires at least 2 nodes"); netPlan = new NetPlan(); for (int n = 0; n < numNodes; n++) netPlan.addNode(0, 0, null, null); } else { netPlan = new NetPlan((File) cli.getParsedOptionValue("input-file")); numNodes = netPlan.getNumberOfNodes(); } int numMatrices = 1; String trafficPattern = null; DoubleMatrix2D[] trafficMatrices; if (cli.hasOption("variation-pattern")) { if (!cli.hasOption("num-matrices")) throw new Net2PlanException("'num-matrices' parameters must be specified"); numMatrices = ((Number) cli.getParsedOptionValue("num-matrices")).intValue(); if (numMatrices < 1) throw new Net2PlanException("Number of traffic matrices must be positive"); DoubleMatrix2D trafficMatrix = netPlan.getMatrixNode2NodeOfferedTraffic(); List<DoubleMatrix2D> newMatrices; String variationPattern = (String) cli.getParsedOptionValue("variation-pattern"); switch (variationPattern) { case "cagr": { double cagr = ((Number) cli.getParsedOptionValue("variation-pattern-cagr")).doubleValue(); if (cagr <= 0) throw new Net2PlanException("Compound annual growth rate must be greater than zero"); newMatrices = TrafficMatrixGenerationModels.computeMatricesCAGR(trafficMatrix, cagr, numMatrices); break; } case "randomGaussian": { double cv = ((Number) cli.getParsedOptionValue("variation-pattern-cv")).doubleValue(); double maxRelativeVariation = ((Number) cli .getParsedOptionValue("variation-pattern-maxRelativeVariation")).doubleValue(); if (cv <= 0) throw new Net2PlanException("Coefficient of variation must be greater than zero"); if (maxRelativeVariation <= 0) throw new Net2PlanException("Maximum relative variation must be greater than zero"); newMatrices = TrafficMatrixGenerationModels.computeMatricesRandomGaussianVariation(trafficMatrix, cv, maxRelativeVariation, numMatrices); break; } case "randomUniform": { double maxRelativeVariation = ((Number) cli .getParsedOptionValue("variation-pattern-maxRelativeVariation")).doubleValue(); if (maxRelativeVariation <= 0) throw new Net2PlanException("Maximum relative variation must be greater than zero"); newMatrices = TrafficMatrixGenerationModels.computeMatricesRandomUniformVariation(trafficMatrix, maxRelativeVariation, numMatrices); break; } default: throw new RuntimeException("Bad - Unknown variation pattern '" + variationPattern + "'"); } trafficMatrices = new DoubleMatrix2D[numMatrices]; int i = 0; for (DoubleMatrix2D trafficMatrix1 : newMatrices) trafficMatrices[i++] = trafficMatrix1; } else { if (cli.hasOption("traffic-pattern")) { trafficPattern = cli.getOptionValue("traffic-pattern"); if (!TRAFFIC_PATTERNS.containsKey(trafficPattern)) throw new Net2PlanException("Unknown traffic pattern"); if (cli.hasOption("num-matrices")) { numMatrices = ((Number) cli.getParsedOptionValue("num-matrices")).intValue(); if (numMatrices < 1) throw new Net2PlanException("Number of traffic matrices must be positive"); } } trafficMatrices = new DoubleMatrix2D[numMatrices]; if (trafficPattern != null) { switch (trafficPattern) { case "uniform-random-10": for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.uniformRandom(numNodes, 0, 10); break; case "uniform-random-100": for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.uniformRandom(numNodes, 0, 100); break; case "uniform-random-bimodal-50-50": for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.bimodalUniformRandom(numNodes, 0.5, 0, 100, 0, 10); break; case "uniform-random-bimodal-25-75": for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.bimodalUniformRandom(numNodes, 0.25, 0, 100, 0, 10); break; case "population-distance-model": double randomFactor = 0; double populationOffset = 0; double populationPower = 1; double distanceOffset = 0; double distancePower = 1; boolean normalizePopulation = true; boolean normalizeDistance = true; if (cli.hasOption("random-factor")) randomFactor = ((Number) cli.getParsedOptionValue("random-factor")).doubleValue(); if (cli.hasOption("population-offset")) populationOffset = ((Number) cli.getParsedOptionValue("population-offset")).doubleValue(); if (cli.hasOption("population-power")) populationPower = ((Number) cli.getParsedOptionValue("population-power")).doubleValue(); if (cli.hasOption("distance-offset")) distanceOffset = ((Number) cli.getParsedOptionValue("distance-offset")).doubleValue(); if (cli.hasOption("distance-power")) distancePower = ((Number) cli.getParsedOptionValue("distance-power")).doubleValue(); if (cli.hasOption("normalize-population")) normalizePopulation = Boolean.parseBoolean(cli.getOptionValue("normalize-population")); if (cli.hasOption("normalize-distance")) normalizeDistance = Boolean.parseBoolean(cli.getOptionValue("normalize-distance")); if (!cli.hasOption("level-matrix-file")) throw new Net2PlanException("The level-matrix file is required"); DoubleMatrix2D levelMatrix = DoubleUtils .read2DMatrixFromFile((File) cli.getParsedOptionValue("level-matrix-file")); DoubleMatrix2D distanceMatrix = netPlan.getMatrixNode2NodeEuclideanDistance(); int[] populationVector = StringUtils .toIntArray(netPlan.getAttributes(netPlan.getNodes(), "population").values(), 0); int[] levelVector = StringUtils .toIntArray(netPlan.getAttributes(netPlan.getNodes(), "level").values(), 1); for (int tmId = 0; tmId < numMatrices; tmId++) trafficMatrices[tmId] = TrafficMatrixGenerationModels.populationDistanceModel( distanceMatrix, populationVector, levelVector, levelMatrix, randomFactor, populationOffset, populationPower, distanceOffset, distancePower, normalizePopulation, normalizeDistance); break; case "gravity-model": if (cli.hasOption("gravity-model-file")) { File gravityModelFile = (File) cli.getParsedOptionValue("gravity-model-file"); DoubleMatrix2D gravityModelMatrix = DoubleUtils.read2DMatrixFromFile(gravityModelFile); if (gravityModelMatrix.rows() != numNodes || gravityModelMatrix.columns() != 2) throw new Net2PlanException( "'gravity-model-file' requires " + numNodes + " rows and two columns"); numMatrices = 1; trafficMatrices[0] = TrafficMatrixGenerationModels.gravityModel( gravityModelMatrix.viewColumn(0).toArray(), gravityModelMatrix.viewColumn(1).toArray()); } else { throw new Net2PlanException("Parameter 'gravity-model-file' should be specified"); } break; default: throw new RuntimeException("Bad - Unknown traffic pattern '" + trafficPattern + "'"); } } else { trafficMatrices[0] = netPlan.getMatrixNode2NodeOfferedTraffic(); } if (cli.hasOption("normalization-pattern")) { String normalizationPattern = (String) cli.getParsedOptionValue("normalization-pattern"); switch (normalizationPattern) { case "total-normalization": case "row-normalization": case "column-normalization": if (cli.hasOption("normalization-pattern-file")) { double[] normalizationPatternVector; int patternId; File normalizationPatternFile = (File) cli .getParsedOptionValue("normalization-pattern-file"); DoubleMatrix2D normalizationPatternMatrix = DoubleUtils .read2DMatrixFromFile(normalizationPatternFile); if (normalizationPatternMatrix.rows() == 1 && normalizationPatternMatrix.columns() == 1) { patternId = 0; normalizationPatternVector = new double[] { normalizationPatternMatrix.getQuick(0, 0) }; } else if (normalizationPatternMatrix.rows() == 1 && normalizationPatternMatrix.columns() > 1) { patternId = 1; normalizationPatternVector = normalizationPatternMatrix.viewRow(0).toArray(); } else if (normalizationPatternMatrix.rows() > 1 && normalizationPatternMatrix.columns() == 1) { patternId = 2; normalizationPatternVector = normalizationPatternMatrix.viewColumn(0).toArray(); } else { throw new Net2PlanException( "Bad normalization pattern - Neither a scalar (for total normalization), nor row vector (for row normalization) nor a column vector (for column normalization) was provided"); } for (int tmId = 0; tmId < numMatrices; tmId++) { switch (patternId) { case 0: trafficMatrices[tmId] = TrafficMatrixGenerationModels .normalizationPattern_totalTraffic(trafficMatrices[tmId], normalizationPatternVector[0]); break; case 1: trafficMatrices[tmId] = TrafficMatrixGenerationModels .normalizationPattern_incomingTraffic(trafficMatrices[tmId], normalizationPatternVector); break; case 2: trafficMatrices[tmId] = TrafficMatrixGenerationModels .normalizationPattern_outgoingTraffic(trafficMatrices[tmId], normalizationPatternVector); break; default: throw new RuntimeException("Bad"); } } } else { throw new Net2PlanException("Parameter 'normalization-pattern-file' should be specified"); } break; case "max-traffic-estimated-minHop": for (int tmId = 0; tmId < numMatrices; tmId++) { netPlan.setTrafficMatrix(trafficMatrices[tmId]); netPlan.setVectorDemandOfferedTraffic( TrafficMatrixGenerationModels.normalizeTraffic_networkCapacity(netPlan)); trafficMatrices[tmId] = netPlan.getMatrixNode2NodeOfferedTraffic(); } break; case "max-traffic-exact": String solverName = Configuration.getOption("defaultILPSolver"); String solverLibraryName = Configuration.getDefaultSolverLibraryName(solverName); // if (solverName.equalsIgnoreCase("glpk")) solverLibraryName = Configuration.getOption("glpkSolverLibraryName"); // else if (solverName.equalsIgnoreCase("ipopt")) solverLibraryName = Configuration.getOption("ipoptSolverLibraryName"); // else if (solverName.equalsIgnoreCase("cplex")) solverLibraryName = Configuration.getOption("cplexSolverLibraryName"); // else if (solverName.equalsIgnoreCase("xpress")) solverLibraryName = Configuration.getOption("xpressSolverLicenseFileName"); // for (int tmId = 0; tmId < numMatrices; tmId++) { netPlan.setTrafficMatrix(trafficMatrices[tmId]); netPlan.setVectorDemandOfferedTraffic(TrafficMatrixGenerationModels .normalizeTraffic_linkCapacity_xde(netPlan, solverName, solverLibraryName)); trafficMatrices[tmId] = netPlan.getMatrixNode2NodeOfferedTraffic(); } break; default: throw new RuntimeException( "Bad - Unknown normalization pattern '" + normalizationPattern + "'"); } } } List<NetPlan> outputDemandSets = new LinkedList<NetPlan>(); for (int tmId = 0; tmId < numMatrices; tmId++) { NetPlan aux = new NetPlan(); aux.setTrafficMatrix(trafficMatrices[tmId]); outputDemandSets.add(aux); trafficMatrices[tmId] = null; } File outputFile = (File) cli.getParsedOptionValue("output-file"); if (outputDemandSets.size() == 1) { outputDemandSets.get(0).saveToFile(outputFile); } else { String templateFileName = outputFile.getAbsoluteFile().toString(); if (templateFileName.endsWith(".n2p")) templateFileName = templateFileName.substring(0, templateFileName.lastIndexOf('.')); ListIterator<NetPlan> netPlanIt = outputDemandSets.listIterator(); while (netPlanIt.hasNext()) netPlanIt.next().saveToFile(new File(templateFileName + "_tm" + netPlanIt.nextIndex() + ".n2p")); } long end = System.nanoTime(); System.out.println(String.format("%n%nTraffic matrix generation finished successfully in %f seconds", (end - init) / 1e9)); }
From source file:com.offbynull.peernetic.playground.chorddht.model.FingerTable.java
/** * Searches the finger table for the left-most occurrence of {@code ptr}. * @param ptr pointer to search for/*from w w w . j a v a 2 s .com*/ * @return index of occurrence, or -1 if not found * @throws NullPointerException if any arguments are {@code null} * @throws IllegalArgumentException if {@code ptr}'s id has a different limit bit size than the base pointer's id */ public int getMinimumIndex(Pointer ptr) { Validate.notNull(ptr); Validate.isTrue(IdUtils.getBitLength(ptr.getId()) == bitCount); Id id = ptr.getId(); Validate.isTrue(IdUtils.getBitLength(id) == bitCount); ListIterator<InternalEntry> lit = table.listIterator(); while (lit.hasNext()) { InternalEntry ie = lit.next(); if (ie.pointer.equals(ptr)) { return lit.nextIndex() - 1; } } return -1; }
From source file:org.squale.squalecommon.enterpriselayer.facade.quality.QualityResultFacade.java
/** * Permet de rcuprer les notes associs a une pratique ainsi que le tableau de rpartition * /*from ww w . java2s . c o m*/ * @param pAudits liste des AuditDTOs * @param pProject ComponentDTO relatif a un projet * @param pPratice pratique * @return ResultsDTO avec les deux Map renseignes * @throws JrafEnterpriseException exception Jraf */ public static ResultsDTO getRepartition(List pAudits, ComponentDTO pProject, PracticeRuleDTO pPratice) throws JrafEnterpriseException { // Initialisation ISession session = null; // session Hibernate pAudits.remove(null); List auditIds = initAuditIds(pAudits); // liste des identifiants des AuditDTO Long projectId = new Long(pProject.getID()); ResultsDTO results = null; // retour de la methode Map intRepartitionMap = new HashMap(); // Map de la repartition de composants sur une pratique pour des // intervalles de pas = 1 Map floatRepartitionMap = new HashMap(); // Map de la repartition de composants sur une pratique pour des // intervalles de pas = 0.1 List practiceBOs = null; // Initialisation des Daos QualityResultDAOImpl qualityResultDao = QualityResultDAOImpl.getInstance(); try { session = PERSISTENTPROVIDER.getSession(); Long treKey = new Long(pPratice.getId()); results = getQResultsByAudit(pAudits, treKey, pProject); // Chargement des pratiques pour recuperer les repartitions practiceBOs = qualityResultDao.findWhere(session, projectId, auditIds, treKey); // Mise des valeurs dans la Map repartitionMap if (practiceBOs != null) { ListIterator practiceIterator = practiceBOs.listIterator(); PracticeResultBO practiceResult = null; while (practiceIterator.hasNext()) { Object objTemp = practiceIterator.next(); if (objTemp != null) { practiceResult = (PracticeResultBO) objTemp; intRepartitionMap.put(pAudits.get(practiceIterator.nextIndex() - 1), practiceResult.getIntRepartition()); floatRepartitionMap.put(pAudits.get(practiceIterator.nextIndex() - 1), practiceResult.getFloatRepartition()); } else { intRepartitionMap.put(pAudits.get(practiceIterator.nextIndex() - 1), objTemp); floatRepartitionMap.put(pAudits.get(practiceIterator.nextIndex() - 1), objTemp); } } } // affectation de la map au ResultsDTO if (results != null) { if (intRepartitionMap.keySet().size() > 0) { results.setIntRepartitionPracticeMap(intRepartitionMap); } if (floatRepartitionMap.keySet().size() > 0) { results.setFloatRepartitionPracticeMap(floatRepartitionMap); } } else { results = null; } } catch (JrafDaoException e) { LOG.error(QualityResultFacade.class.getName() + ".getRepartiton", e); } finally { FacadeHelper.closeSession(session, QualityResultFacade.class.getName() + ".getRepartition"); } return results; }
From source file:org.apache.fop.layoutmgr.table.ActiveCell.java
/** * Modifies the cell's element list by putting filler elements, so that the cell's or * row's explicit height is always reached. * * TODO this will work properly only for the first break. Then the limitation * explained on http://wiki.apache.org/xmlgraphics-fop/TableLayout/KnownProblems * occurs. The list of elements needs to be re-adjusted after each break. */// ww w .ja v a 2 s.co m private void handleExplicitHeight(MinOptMax cellBPD, MinOptMax rowBPD) { int minBPD = Math.max(cellBPD.getMin(), rowBPD.getMin()); if (minBPD > 0) { ListIterator iter = elementList.listIterator(); int cumulateLength = 0; boolean prevIsBox = false; while (iter.hasNext() && cumulateLength < minBPD) { KnuthElement el = (KnuthElement) iter.next(); if (el.isBox()) { prevIsBox = true; cumulateLength += el.getWidth(); } else if (el.isGlue()) { if (prevIsBox) { elementList.add(iter.nextIndex() - 1, new FillerPenalty(minBPD - cumulateLength)); } prevIsBox = false; cumulateLength += el.getWidth(); } else { prevIsBox = false; if (cumulateLength + el.getWidth() < minBPD) { iter.set(new FillerPenalty((KnuthPenalty) el, minBPD - cumulateLength)); } } } } int optBPD = Math.max(minBPD, Math.max(cellBPD.getOpt(), rowBPD.getOpt())); if (pgu.getContentLength() < optBPD) { elementList.add(new FillerBox(optBPD - pgu.getContentLength())); } }
From source file:eu.scidipes.toolkits.pawebapp.web.ItemsController.java
public String editItemHelper(final List<Form> formSubset, final Form form, final Model model, final RedirectAttributes redirectAttrs) { final ListIterator<Form> formIterator = formSubset.listIterator(); while (formIterator.hasNext()) { final Form theForm = formIterator.next(); if (theForm.equals(form)) { /* Jump back: */ formIterator.previous();// ww w. ja v a2 s . com if (formIterator.hasPrevious()) { model.addAttribute("previous", Integer.valueOf(formSubset.get(formIterator.previousIndex()).getFormID().intValue())); } /* Jump forward: */ formIterator.next(); if (formIterator.hasNext()) { model.addAttribute("next", Integer.valueOf(formSubset.get(formIterator.nextIndex()).getFormID().intValue())); } } } model.addAttribute("saveAction", EDIT); final CurationPersistentIdentifier manifestCPID = form.getManifestCPID(); final Map<DatasetRIL, Set<CoreRIType>> rilMembership = new HashMap<>(); /* Fetch the current RIL membership for this form instance: */ for (final DatasetRIL dsRIL : form.getParentBundle().getRils()) { final RepresentationInformation[] repInfo = dsRIL.getRil().getRepresentationInformationChildren(); for (final RepresentationInformation coreRI : repInfo) { if (coreRI.getRepresentationInformation() instanceof RepInfoGroup) { final RepInfoGroup repInfoGroup = (RepInfoGroup) coreRI.getRepresentationInformation(); for (final RepresentationInformation ri : repInfoGroup.getRepresentationInformationChildren()) { if (ri.getCpid().equals(manifestCPID)) { if (!rilMembership.containsKey(dsRIL)) { rilMembership.put(dsRIL, new HashSet<CoreRIType>()); } rilMembership.get(dsRIL).add(CoreRIType.fromClass(coreRI.getClass())); } } } } } model.addAttribute("rilMembership", rilMembership); model.addAttribute("form", form); return "datasets/items/edit"; }
From source file:org.openconcerto.openoffice.ODSingleXMLDocument.java
/** * Slice the body into parts. Since some content have no part (e.g. comment), they can be added * to the previous or next range. If <code>overlapping</code> is <code>true</code> they will be * added to both, else only to the next range. * //from w w w .j av a 2 s . c o m * @param parts parts definition. * @param body the element to slice. * @param overlapping <code>true</code> if ranges can overlap. * @return the start (inclusive, {@link Point#x}) and end (exclusive, {@link Point#y}) for each * {@link ContentPart}. */ static private Point[] getBounds(final Map<Tuple2<Namespace, String>, ContentPart> parts, final Element body, final boolean overlapping) { @SuppressWarnings("unchecked") final List<Content> content = body.getContent(); final int contentSize = content.size(); if (contentSize == 0) return new Point[] { new Point(0, 0), new Point(0, 0), new Point(0, 0) }; // start from the beginning until we leave the prologue ContentPart contentPart = null; ListIterator<Content> thisChildrenIter = content.listIterator(0); final int prologueStart = 0; int nullsStartIndex = -1; while ((contentPart == null || contentPart == ContentPart.PROLOGUE) && thisChildrenIter.hasNext()) { contentPart = getPart(parts, thisChildrenIter.next()); if (contentPart != null) { nullsStartIndex = -1; } else if (nullsStartIndex < 0) { nullsStartIndex = thisChildrenIter.previousIndex(); } } final int nullsEnd = contentPart == null || contentPart == ContentPart.PROLOGUE ? thisChildrenIter.nextIndex() : thisChildrenIter.previousIndex(); final int nullsStart = nullsStartIndex < 0 ? nullsEnd : nullsStartIndex; assert nullsStart >= 0 && nullsStart <= nullsEnd; final int mainStart = nullsStart; final int prologueStop = overlapping ? nullsEnd : nullsStart; final int epilogueEnd = contentSize; final int[] lastNulls = getLastNulls(parts, content, contentSize); final int lastNullsStart = lastNulls[0]; final int lastNullsEnd = lastNulls[1]; assert lastNullsStart >= mainStart && lastNullsStart <= lastNullsEnd; final int epilogueStart = lastNullsStart; final int mainEnd = overlapping ? lastNullsEnd : lastNullsStart; final Point[] res = new Point[] { new Point(prologueStart, prologueStop), new Point(mainStart, mainEnd), new Point(epilogueStart, epilogueEnd) }; assert res.length == ContentPart.values().length; return res; }
From source file:com.offbynull.peernetic.playground.chorddht.model.FingerTable.java
/** * Removes all fingers after {@code id} (does not remove {@code id} itself). * @param id id of which all fingers after it will be removed * @return number of fingers that were cleared * @throws NullPointerException if any arguments are {@code null} * @throws IllegalArgumentException if {@code id} has a different limit bit size than base pointer's id *//*from w w w .ja v a 2 s . c o m*/ public int clearAfter(Id id) { Validate.notNull(id); Validate.isTrue(IdUtils.getBitLength(id) == bitCount); Id baseId = basePtr.getId(); ListIterator<InternalEntry> lit = table.listIterator(); while (lit.hasNext()) { InternalEntry ie = lit.next(); Pointer testPtr = ie.pointer; Id testId = testPtr.getId(); if (Id.comparePosition(baseId, id, testId) < 0) { int position = lit.nextIndex() - 1; clearAfter(position); return bitCount - position; } } return 0; }