List of usage examples for com.google.common.collect Iterables getLast
public static <T> T getLast(Iterable<T> iterable)
From source file:com.eucalyptus.reporting.Counter.java
private long started(final List<CountPeriod<C>> periodList) { final long periodLengthLong = periodLength; return periodList.isEmpty() ? (clock.millis() / periodLengthLong) * periodLengthLong : Iterables.getLast(periodList).key.start; }
From source file:org.sosy_lab.cpachecker.cpa.value.symbolic.refiner.ARGTreePrecisionUpdater.java
private ConstraintsPrecision mergeConstraintsPrecisionsForSubgraph(final ARGState pRefinementRoot, final ARGReachedSet pReached) { // get all unique precisions from the subtree Set<ConstraintsPrecision> uniquePrecisions = Sets.newIdentityHashSet(); for (ARGState descendant : getNonCoveredStatesInSubgraph(pRefinementRoot)) { uniquePrecisions.add(extractConstraintsPrecision(pReached, descendant)); }/* w w w. j a va 2 s. c o m*/ // join all unique precisions into a single precision ConstraintsPrecision mergedPrecision = Iterables.getLast(uniquePrecisions); for (ConstraintsPrecision precision : uniquePrecisions) { mergedPrecision = mergedPrecision.join(precision); } return mergedPrecision; }
From source file:de.cismet.cids.jsonpatch.operation.cidsbean.AddOperation.java
/** * DOCUMENT ME!// w w w . j a v a2s.c om * * @param parentList DOCUMENT ME! * * @throws JsonPatchException DOCUMENT ME! */ protected void addToArray(final List parentList) throws JsonPatchException { final TokenResolver<JsonNode> token = Iterables.getLast(path); if (token.getToken().equals(LAST_ARRAY_ELEMENT)) { if (UTILS.isCidsBeanArray(value)) { final List<CidsBean> beanList = (List<CidsBean>) UTILS.deserializeAndVerifyCidsBean(this.value); if (this.overwrite) { final ListIterator<CidsBean> listIterator = parentList.listIterator(); while (listIterator.hasNext()) { final CidsBean listCidsBean = listIterator.next(); for (final CidsBean replacmentBean : beanList) { if (replacmentBean.getCidsBeanInfo().getJsonObjectKey() .equals(listCidsBean.getCidsBeanInfo().getJsonObjectKey())) { listIterator.set(replacmentBean); } } } } else { parentList.addAll(beanList); } } else if (UTILS.isCidsBean(value)) { final CidsBean cidsBean = (CidsBean) UTILS.deserializeAndVerifyCidsBean(this.value); if (this.overwrite) { final ListIterator<CidsBean> listIterator = parentList.listIterator(); while (listIterator.hasNext()) { final CidsBean listCidsBean = listIterator.next(); if (cidsBean.getCidsBeanInfo().getJsonObjectKey() .equals(listCidsBean.getCidsBeanInfo().getJsonObjectKey())) { listIterator.set(cidsBean); } } } else { parentList.add(cidsBean); } } else { throw new JsonPatchException(RESOURCE_BUNDLE.getString("jsonPatch.invalidValueForArray")); } } else { final int size = parentList.size(); final int index; try { index = Integer.parseInt(token.toString()); } catch (NumberFormatException ex) { LOGGER.error(RESOURCE_BUNDLE.getString("jsonPatch.notAnIndex") + ": " + ex.getMessage(), ex); throw new JsonPatchException(RESOURCE_BUNDLE.getString("jsonPatch.notAnIndex"), ex); } if ((index < 0) || (index > size)) { LOGGER.error(RESOURCE_BUNDLE.getString("jsonPatch.notAnIndex") + ": " + index + " (array size: " + size + ")"); throw new JsonPatchException(RESOURCE_BUNDLE.getString("jsonPatch.noSuchIndex")); } if (UTILS.isCidsBean(value)) { final CidsBean cidsBean = (CidsBean) UTILS.deserializeAndVerifyCidsBean(this.value); if (this.overwrite) { parentList.set(index, cidsBean); } else { parentList.add(index, cidsBean); } } else if (UTILS.isCidsBeanArray(value)) { LOGGER.error(RESOURCE_BUNDLE.getString("jsonPatch.invalidValueForArrayIndex") + ": arrays cannot be used as value in conjunction with an array index"); throw new JsonPatchException(RESOURCE_BUNDLE.getString("jsonPatch.invalidValueForArrayIndex")); } else { LOGGER.error(RESOURCE_BUNDLE.getString("jsonPatch.invalidValueForArrayIndex") + ": " + value); throw new JsonPatchException(RESOURCE_BUNDLE.getString("jsonPatch.invalidValueForArrayIndex")); } } }
From source file:org.kiji.schema.zookeeper.UsersTracker.java
/** * Retrieve a multimap of the current users to their respective value (either table layout version * if tracking table users, or system version if tracking instance users). * * @return a multimap of the current table users to their respective value. * @throws IOException on failure./*from w w w .j av a 2 s . c om*/ */ public Multimap<String, String> getUsers() throws IOException { ImmutableMultimap.Builder<String, String> users = ImmutableSetMultimap.builder(); for (ChildData child : mCache.getCurrentData()) { String nodeName = Iterables.getLast(Splitter.on('/').split(child.getPath())); String[] split = nodeName.split(ZooKeeperUtils.ZK_NODE_NAME_SEPARATOR); if (split.length != 2) { LOG.error("Ignoring invalid ZooKeeper table user node: {}.", nodeName); continue; } final String userID = URLDecoder.decode(split[0], Charsets.UTF_8.displayName()); final String layoutID = URLDecoder.decode(split[1], Charsets.UTF_8.displayName()); users.put(userID, layoutID); } return users.build(); }
From source file:org.glowroot.ui.TransactionJsonService.java
@GET(path = "/backend/transaction/average", permission = "agent:transaction:overview") String getOverview(@BindAgentRollupId String agentRollupId, @BindRequest TransactionDataRequest request, @BindAutoRefresh boolean autoRefresh) throws Exception { AggregateQuery query = toChartQuery(request, DataKind.GENERAL); long liveCaptureTime = clock.currentTimeMillis(); List<OverviewAggregate> overviewAggregates = transactionCommonService.getOverviewAggregates(agentRollupId, query, autoRefresh);//from www. j a v a 2 s .co m if (overviewAggregates.isEmpty() && fallBackToLargestAggregates(query)) { // fall back to largest aggregates in case expiration settings have recently changed query = withLargestRollupLevel(query); overviewAggregates = transactionCommonService.getOverviewAggregates(agentRollupId, query, autoRefresh); if (!overviewAggregates.isEmpty() && ignoreFallBackData(query, Iterables.getLast(overviewAggregates).captureTime())) { // this is probably data from before the requested time period overviewAggregates = ImmutableList.of(); } } long dataPointIntervalMillis = configRepository.getRollupConfigs().get(query.rollupLevel()) .intervalMillis(); List<DataSeries> dataSeriesList = getDataSeriesForTimerChart(request, overviewAggregates, dataPointIntervalMillis, liveCaptureTime); Map<Long, Long> transactionCounts = getTransactionCounts(overviewAggregates); // TODO more precise aggregate when from/to not on rollup grid List<OverviewAggregate> overviewAggregatesForMerging = Lists.newArrayList(); for (OverviewAggregate overviewAggregate : overviewAggregates) { long captureTime = overviewAggregate.captureTime(); if (captureTime > request.from() && captureTime <= request.to()) { overviewAggregatesForMerging.add(overviewAggregate); } } MergedAggregate mergedAggregate = AggregateMerging.getMergedAggregate(overviewAggregatesForMerging); StringBuilder sb = new StringBuilder(); JsonGenerator jg = mapper.getFactory().createGenerator(CharStreams.asWriter(sb)); try { jg.writeStartObject(); jg.writeObjectField("dataSeries", dataSeriesList); jg.writeNumberField("dataPointIntervalMillis", dataPointIntervalMillis); jg.writeObjectField("transactionCounts", transactionCounts); jg.writeObjectField("mergedAggregate", mergedAggregate); jg.writeEndObject(); } finally { jg.close(); } return sb.toString(); }
From source file:org.opendaylight.controller.configpusherfeature.internal.FeatureConfigSnapshotHolder.java
public Feature getCauseFeature() { return Iterables.getLast(featureChain); }
From source file:org.sonar.plsqlopen.checks.verifier.PlSqlCheckVerifier.java
private static void validateIssue(Multimap<Integer, Map<IssueAttribute, String>> expected, List<Integer> unexpectedLines, AnalyzerMessage issue) { int line = issue.getLine(); if (expected.containsKey(line)) { Map<IssueAttribute, String> attrs = Iterables.getLast(expected.get(line)); assertEquals(issue.getText(Locale.ENGLISH), attrs, IssueAttribute.MESSAGE); validateAnalyzerMessage(attrs, issue); expected.remove(line, attrs);//from w w w.ja va 2s . co m } else { unexpectedLines.add(line); } }
From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils.java
public static List<RangeConstraint> parseRangeListFromString(final StmtContext<?, ?, ?> ctx, final String rangeArgument) { final Optional<String> description = Optional.absent(); final Optional<String> reference = Optional.absent(); final List<RangeConstraint> rangeConstraints = new ArrayList<>(); for (final String singleRange : PIPE_SPLITTER.split(rangeArgument)) { final Iterator<String> boundaries = TWO_DOTS_SPLITTER.splitToList(singleRange).iterator(); final Number min = parseDecimalConstraintValue(ctx, boundaries.next()); final Number max; if (boundaries.hasNext()) { max = parseDecimalConstraintValue(ctx, boundaries.next()); // if min larger than max then error InferenceException.throwIf(compareNumbers(min, max) == 1, ctx.getStatementSourceReference(), "Range constraint %s has descending order of boundaries; should be ascending", singleRange); SourceException.throwIf(boundaries.hasNext(), ctx.getStatementSourceReference(), "Wrong number of boundaries in range constraint %s", singleRange); } else {//from w w w . ja v a 2 s .c o m max = min; } // some of intervals overlapping if (rangeConstraints.size() > 1 && compareNumbers(min, Iterables.getLast(rangeConstraints).getMax()) != 1) { throw new InferenceException(ctx.getStatementSourceReference(), "Some of the ranges in %s are not disjoint", rangeArgument); } rangeConstraints.add(new RangeConstraintEffectiveImpl(min, max, description, reference)); } return rangeConstraints; }
From source file:com.eucalyptus.cluster.callback.DescribeSensorCallback.java
private void processReportingStats(final DescribeSensorsResponse msg) throws Exception { final Iterable<String> uuidList = Iterables.transform(VmInstances.list(VmState.RUNNING), VmInstances.toInstanceUuid()); for (final SensorsResourceType sensorData : msg.getSensorsResources()) { if (!RESOURCE_TYPE_INSTANCE.equals(sensorData.getResourceType()) || !Iterables.contains(uuidList, sensorData.getResourceUuid())) continue; for (final MetricsResourceType metricType : sensorData.getMetrics()) { for (final MetricCounterType counterType : metricType.getCounters()) { for (final MetricDimensionsType dimensionType : counterType.getDimensions()) { // find and fire most recent value for metric/dimension final List<MetricDimensionsValuesType> values = Lists .newArrayList(dimensionType.getValues()); //Reporting use case of metric data from the cc Collections.sort(values, Ordering.natural().onResultOf(GetTimestamp.INSTANCE)); if (!values.isEmpty()) { final MetricDimensionsValuesType latestValue = Iterables.getLast(values); final Double usageValue = latestValue.getValue(); if (usageValue == null) { LOG.debug("Event received with null 'value', skipping for reporting"); continue; }/* www. j a va 2 s. com*/ final Long usageTimestamp = latestValue.getTimestamp().getTime(); final long sequenceNumber = dimensionType.getSequenceNum() + (values.size() - 1); fireUsageEvent(new Supplier<InstanceUsageEvent>() { @Override public InstanceUsageEvent get() { return new InstanceUsageEvent(sensorData.getResourceUuid(), sensorData.getResourceName(), metricType.getMetricName(), sequenceNumber, dimensionType.getDimensionName(), usageValue, usageTimestamp); } }); } } } } } }
From source file:org.gradle.internal.resource.transport.http.HttpClientHelper.java
@SuppressWarnings("unchecked") private URI getLastRedirectLocation(HttpContext httpContext) { List<URI> redirectLocations = (List<URI>) httpContext.getAttribute(REDIRECT_LOCATIONS); return (redirectLocations == null || redirectLocations.isEmpty()) ? null : Iterables.getLast(redirectLocations); }