List of usage examples for com.google.common.collect Range upperEndpoint
public C upperEndpoint()
From source file:org.sonatype.nexus.repository.http.PartialFetchHandler.java
/** * Mutate the response into one that returns part of the payload. */// w ww .ja va 2s . c o m private Response partialResponse(final Response response, final Payload payload, final Range<Long> requestedRange) { Response.Builder builder = new Response.Builder().copy(response) .status(Status.success(HttpStatus.PARTIAL_CONTENT)); Payload partialPayload = new PartialPayload(payload, requestedRange); builder.payload(partialPayload); // ResponseSender takes care of Content-Length header, via payload.size builder.header(HttpHeaders.CONTENT_RANGE, requestedRange.lowerEndpoint() + "-" + requestedRange.upperEndpoint() + "/" + payload.getSize()); return builder.build(); }
From source file:org.apache.drill.exec.record.RecordIterator.java
public void forward(long delta) { if (!enableMarkAndReset) { throw new UnsupportedOperationException("mark and reset disabled for this RecordIterator"); }/*from w ww . jav a 2 s . c o m*/ assert delta >= 0; assert (delta + outerPosition) < totalRecordCount; final long nextOuterPosition = delta + outerPosition; final RecordBatchData rbdNew = batches.get(nextOuterPosition); final RecordBatchData rbdOld = batches.get(outerPosition); assert rbdNew != null; assert rbdOld != null; container.transferOut(rbdOld.getContainer()); // Get vectors from new position. container.transferIn(rbdNew.getContainer()); outerPosition = nextOuterPosition; final Range<Long> markedBatchRange = batches.getEntry(outerPosition).getKey(); startBatchPosition = markedBatchRange.lowerEndpoint(); innerPosition = (int) (outerPosition - startBatchPosition); innerRecordCount = (int) (markedBatchRange.upperEndpoint() - startBatchPosition); }
From source file:it.units.malelab.ege.ge.mapper.HierarchicalMapper.java
public Node<T> mapRecursively(T symbol, Range<Integer> range, BitsGenotype genotype, int[] bitUsages) throws MappingException { Node<T> node = new Node<>(symbol); if (grammar.getRules().keySet().contains(symbol)) { //a non-terminal node //update usage for (int i = range.lowerEndpoint(); i < range.upperEndpoint(); i++) { bitUsages[i] = bitUsages[i] + 1; }/*w w w .ja v a 2 s . c om*/ List<List<T>> options = grammar.getRules().get(symbol); //get option List<T> symbols; if ((range.upperEndpoint() - range.lowerEndpoint()) < options.size()) { int count = (range.upperEndpoint() - range.lowerEndpoint() > 0) ? genotype.slice(range).count() : genotype.count(); int index = shortestOptionIndexesMap.get(symbol) .get(count % shortestOptionIndexesMap.get(symbol).size()); symbols = options.get(index); } else { symbols = chooseOption(genotype, range, options); for (int i = range.lowerEndpoint(); i < range.upperEndpoint(); i++) { bitUsages[i] = bitUsages[i] + 1; } } //add children List<Range<Integer>> childRanges = getChildrenSlices(range, symbols); for (int i = 0; i < symbols.size(); i++) { Range<Integer> childRange = childRanges.get(i); if (childRanges.get(i).equals(range) && (childRange.upperEndpoint() - childRange.lowerEndpoint() > 0)) { childRange = Range.closedOpen(range.lowerEndpoint(), range.upperEndpoint() - 1); childRanges.set(i, childRange); } } for (int i = 0; i < symbols.size(); i++) { node.getChildren().add(mapRecursively(symbols.get(i), childRanges.get(i), genotype, bitUsages)); } } return node; }
From source file:io.github.mzmine.modules.plots.msspectrum.datasets.MsSpectrumDataSet.java
public String getDescription() { StringBuilder sb = new StringBuilder(); if (spectrum instanceof MsScan) { MsScan scan = (MsScan) spectrum; String scanDesc = MsScanUtils.createFullMsScanDescription(scan); sb.append(scanDesc);/*from w ww . ja va 2 s . c o m*/ } NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat(); NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat(); sb.append("Spectrum type: "); sb.append(spectrum.getSpectrumType()); sb.append("\n"); sb.append("Number of data points: "); sb.append(numOfDataPoints); sb.append("\n"); Range<Double> mzRange = spectrum.getMzRange(); if (mzRange != null) { sb.append("m/z range: "); sb.append(mzFormat.format(mzRange.lowerEndpoint())); sb.append(" - "); sb.append(mzFormat.format(mzRange.upperEndpoint())); sb.append(" m/z\n"); } sb.append("Base peak intensity: "); sb.append(intensityFormat.format(topIndensity)); sb.append("\n"); sb.append("SPLASH ID: "); String splash = SplashCalculationAlgorithm.calculateSplash(spectrum); sb.append(splash); return sb.toString(); }
From source file:com.wealdtech.utils.RangeFormatter.java
/** * Format the date and time of a date/time range. * * @param range the range to format// ww w . j a va 2 s . c om * @return a formatted range, or {@code null} if the input is {@code null} */ @Nullable public String formatDateTime(@Nullable final Range<DateTime> range) { if (range == null) { return null; } final DateTime curDateTime = DateTime.now(); final StringBuilder sb = new StringBuilder(96); final DateTime lower = range.lowerEndpoint(); final DateTime upper = range.upperEndpoint(); if (upper.isBefore(lower)) { throw new DataError.Bad("Upper part of range must be after lower part of range"); } // Lower date final Details lowerDetails = new Details(); lowerDetails.showTime = true; if (!isSameDay(lower, curDateTime)) { lowerDetails.showDayOfWeek = true; lowerDetails.showDayOfMonth = true; lowerDetails.showMonthOfYear = true; } if ((!isSameYear(lower, upper)) || (!isSameYear(lower, curDateTime))) { lowerDetails.showYear = true; } sb.append(doFormat(lower, lowerDetails)); if (!isSameMinute(lower, upper)) { sb.append(" - "); final Details upperDetails = new Details(); upperDetails.showTime = true; if (!isSameDay(lower, upper)) { upperDetails.showDayOfWeek = true; upperDetails.showDayOfMonth = true; upperDetails.showMonthOfYear = true; if ((!isSameYear(lower, upper)) || (!isSameYear(upper, curDateTime))) { upperDetails.showYear = true; } } sb.append(doFormat(upper, upperDetails)); } return sb.toString(); }
From source file:com.nimbits.server.io.BlobStoreImpl.java
@Override public List<ValueBlobStore> createBlobStoreEntity(final Entity entity, final ValueDayHolder holder) throws IOException { PersistenceManager pm = persistenceManagerFactory.getPersistenceManager(); PrintWriter out = null;//w ww .j av a 2s.co m try { logger.info("Creating Blobstore for " + holder.getValues().size()); final String json = gson.toJson(holder.getValues()); String fn = entity.getName().getValue() + "_" + UUID.randomUUID().toString(); out = new PrintWriter(getFolder() + fn); out.println(json); out.close(); Range<Date> range = holder.getTimeRange(); final Date mostRecentTimeForDay = range.upperEndpoint(); final Date earliestForDay = range.lowerEndpoint(); final ValueBlobStoreEntity currentStoreEntity = new ValueBlobStoreEntity(entity.getKey(), holder.getStartOfDay(), mostRecentTimeForDay, earliestForDay, fn, json.length(), BlobStore.storageVersion, entity.getUUID() ); currentStoreEntity.validate(); pm.makePersistent(currentStoreEntity); pm.flush(); return ValueBlobStoreFactory.createValueBlobStore(currentStoreEntity); } finally { if (out != null) { out.close(); } pm.close(); } }
From source file:com.cubeia.games.poker.handler.ActionTransformer.java
public RequestAction transform(ActionRequest request, int sequenceNumber) { RequestAction packet = new RequestAction(); packet.timeToAct = (int) request.getTimeToAct(); packet.player = request.getPlayerId(); packet.seq = sequenceNumber;//from w w w .j a v a 2s .c o m packet.currentPotSize = request.getTotalPotSize().toPlainString(); List<PlayerAction> allowed = new LinkedList<PlayerAction>(); for (PossibleAction option : request.getOptions()) { if (option instanceof DiscardRequest) { DiscardRequest discardRequest = (DiscardRequest) option; PlayerAction playerOption = createPlayerAction(PokerActionType.DISCARD); Range<Integer> cardsToDiscard = discardRequest.getCardsToDiscard(); // TODO: Consider if this is an ugly hack or if it's OK. (Using minAmount and maxAmount to describe the range of number of cards to discard) playerOption.minAmount = cardsToDiscard.lowerEndpoint().toString(); playerOption.maxAmount = cardsToDiscard.upperEndpoint().toString(); allowed.add(playerOption); } else { PlayerAction playerOption = createPlayerAction(option.getActionType()); // FIXME: Casting to integer here since Flash does not support long values! playerOption.minAmount = option.getMinAmount().toPlainString(); playerOption.maxAmount = option.getMaxAmount().toPlainString(); allowed.add(playerOption); } } packet.allowedActions = allowed; return packet; }
From source file:li.klass.fhem.activities.graph.ChartingActivity.java
private void setRangeFor(Optional<Range<Double>> axisRange, com.github.mikephil.charting.components.YAxis axis) { if (axisRange.isPresent()) { Range<Double> range = axisRange.get(); if (range.hasLowerBound()) { axis.setAxisMinValue(range.lowerEndpoint().floatValue()); }//from ww w.ja v a2s. co m if (range.hasUpperBound()) { axis.setAxisMinValue(range.upperEndpoint().floatValue()); } } }
From source file:net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.databases.PubChemGateway.java
/** * Searches for CIDs of PubChem compounds based on their exact * (monoisotopic) mass. Returns maximum numOfResults results sorted by the * CID. If chargedOnly parameter is set, returns only molecules with * non-zero charge.//from w ww . ja va2 s.c o m */ public String[] findCompounds(double mass, MZTolerance mzTolerance, int numOfResults, ParameterSet parameters) throws IOException { Range<Double> toleranceRange = mzTolerance.getToleranceRange(mass); StringBuilder pubchemUrl = new StringBuilder(); pubchemUrl.append( "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?usehistory=n&db=pccompound&sort=cida&retmax="); pubchemUrl.append(numOfResults); pubchemUrl.append("&term="); pubchemUrl.append(toleranceRange.lowerEndpoint()); pubchemUrl.append(":"); pubchemUrl.append(toleranceRange.upperEndpoint()); pubchemUrl.append("[MonoisotopicMass]"); NodeList cidElements; try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dbf.newDocumentBuilder(); Document parsedResult = builder.parse(pubchemUrl.toString()); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile("//eSearchResult/IdList/Id"); cidElements = (NodeList) expr.evaluate(parsedResult, XPathConstants.NODESET); } catch (Exception e) { throw (new IOException(e)); } String cidArray[] = new String[cidElements.getLength()]; for (int i = 0; i < cidElements.getLength(); i++) { Element cidElement = (Element) cidElements.item(i); cidArray[i] = cidElement.getTextContent(); } return cidArray; }
From source file:radsoft.syntaxhighlighter.view.SyntaxHighlighterPane.java
/** * Apply the list of style to the script text pane. See * {@link syntaxhighlighter.parser.Parser#parse(syntaxhighlighter.brush.Brush, boolean, char[], int, int)}. *///from w ww.j a va 2 s. c o m protected void applyStyle() { if (theme == null || styleList == null) { return; } DefaultStyledDocument document = (DefaultStyledDocument) getDocument(); // clear all the existing style document.setCharacterAttributes(0, document.getLength(), theme.getPlain().getAttributeSet(), true); // apply style according to the style list for (String key : styleList.keySet()) { List<Range<Integer>> posList = styleList.get(key); SimpleAttributeSet attributeSet = theme.getStyle(key).getAttributeSet(); for (Range<Integer> pos : posList) { int start = pos.lowerEndpoint(); int end = pos.upperEndpoint(); document.setCharacterAttributes(start, end - start, attributeSet, true); } } repaint(); }