List of usage examples for com.google.common.collect ImmutableSortedSet first
public E first()
From source file:edu.mit.streamjit.impl.compiler2.PeekableBufferConcreteStorage.java
public static StorageFactory factory(final Map<Token, PeekableBuffer> buffers) { return (Storage storage) -> { assert buffers.containsKey(storage.id()) : storage.id() + " not in " + buffers; //Hack: we don't have the throughput when making init storage, //but we don't need it either. int throughput1; try {//from ww w. j a va2s . c o m throughput1 = storage.throughput(); } catch (IllegalStateException ignored) { throughput1 = Integer.MIN_VALUE; } ImmutableSet<ActorGroup> relevantGroups = ImmutableSet.<ActorGroup>builder() .addAll(storage.upstreamGroups()).addAll(storage.downstreamGroups()).build(); ImmutableSortedSet<Integer> readIndices = storage.readIndices(Maps.asMap(relevantGroups, i -> 1)); int minReadIndex1 = readIndices.isEmpty() ? Integer.MIN_VALUE : readIndices.first(); return new PeekableBufferConcreteStorage(storage.type(), throughput1, minReadIndex1, buffers.get(storage.id())); }; }
From source file:com.ibm.common.geojson.BoundingBox.java
private static BoundingBox buildBoundingBox(ImmutableSortedSet<Float> xs, ImmutableSortedSet<Float> ys, ImmutableSortedSet<Float> zs) { BoundingBox.Builder bbox = new BoundingBox.Builder().add(xs.first()).add(ys.first()); if (!zs.isEmpty()) bbox.add(zs.first());//from ww w .ja va 2 s . co m bbox.add(xs.last()); bbox.add(ys.last()); if (!zs.isEmpty()) bbox.add(zs.last()); return bbox.get(); }
From source file:com.coroptis.coidi.rp.base.DiscoveryResult.java
public XrdService getPreferedService() { UnmodifiableIterator<XrdService> openId20Services = Iterators.filter(services.iterator(), new Predicate<XrdService>() { @Override/*from w ww .j a va2 s . c om*/ public boolean apply(XrdService xrdService) { return xrdService.idPresent(OpenIdNs.TYPE_CLAIMED_IDENTIFIER_ELEMENT_2_0) || xrdService.idPresent(OpenIdNs.TYPE_OPENID_2_0); } }); ImmutableSortedSet<XrdService> out = sortedServicesBuilder.addAll(openId20Services).build(); return out.size() == 0 ? null : out.first(); }
From source file:org.voltcore.utils.COWNavigableSet.java
@Override public E pollFirst() { while (true) { ImmutableSortedSet<E> snapshot = m_set.get(); E first = null;/*from w w w.j a v a2s . com*/ if (snapshot.size() > 0) { first = snapshot.first(); } else { return null; } ImmutableSortedSet.Builder<E> builder = ImmutableSortedSet.naturalOrder(); builder.addAll(snapshot.tailSet(first, false)); if (m_set.compareAndSet(snapshot, builder.build())) { return first; } } }
From source file:edu.mit.streamjit.impl.compiler2.Storage.java
/** * Returns a range spanning the indices written in this storage during an * execution of the given schedule. (Note that, as a span, not every * contained index will be written.) The returned range will be * {@link Range#canonical(com.google.common.collect.DiscreteDomain) canonical}. * The range is not cached so as to be responsive to changes in output index * functions./*from w ww . j a va 2 s. c o m*/ * @param externalSchedule the schedule * @return a range spanning the indices written during the given schedule * under the current index functions * @see #writeIndices(java.util.Map) */ public Range<Integer> writeIndexSpan(Map<ActorGroup, Integer> externalSchedule) { Range<Integer> range = null; for (Actor a : upstream()) { //just the first and last iteration int maxIteration = a.group().schedule().get(a) * externalSchedule.get(a.group()) - 1; if (maxIteration >= 0) for (int iteration : new int[] { 0, maxIteration }) { ImmutableSortedSet<Integer> writes = a.writes(this, iteration); Range<Integer> writeRange = writes.isEmpty() ? range : Range.closed(writes.first(), writes.last()); range = range == null ? writeRange : range.span(writeRange); } } range = (range != null ? range : Range.closedOpen(0, 0)); return range.canonical(DiscreteDomain.integers()); }
From source file:org.apache.james.imap.processor.GetAnnotationProcessor.java
private Optional<Integer> getMaxSizeOfOversizedItems(List<MailboxAnnotation> mailboxAnnotations, final Integer maxsize) { Predicate<MailboxAnnotation> filterOverSizedAnnotation = new Predicate<MailboxAnnotation>() { @Override/*w w w . j av a 2s. c o m*/ public boolean apply(MailboxAnnotation input) { return (input.size() > maxsize); } }; Function<MailboxAnnotation, Integer> transformToSize = new Function<MailboxAnnotation, Integer>() { public Integer apply(MailboxAnnotation input) { return input.size(); } }; ImmutableSortedSet<Integer> overLimitSizes = FluentIterable.from(mailboxAnnotations) .filter(filterOverSizedAnnotation).transform(transformToSize) .toSortedSet(new Comparator<Integer>() { @Override public int compare(Integer annotationSize1, Integer annotationSize2) { return annotationSize2.compareTo(annotationSize1); } }); if (overLimitSizes.isEmpty()) { return Optional.absent(); } return Optional.of(overLimitSizes.first()); }
From source file:com.google.devtools.build.lib.bazel.rules.android.AndroidSdkRepositoryFunction.java
@Override public RepositoryDirectoryValue.Builder fetch(Rule rule, Path outputDirectory, BlazeDirectories directories, Environment env, Map<String, String> markerData) throws SkyFunctionException, InterruptedException { prepareLocalRepositorySymlinkTree(rule, outputDirectory); WorkspaceAttributeMapper attributes = WorkspaceAttributeMapper.of(rule); FileSystem fs = directories.getOutputBase().getFileSystem(); Path androidSdkPath;//from w ww .j a v a 2s.c om if (attributes.isAttributeValueExplicitlySpecified("path")) { androidSdkPath = fs.getPath(getTargetPath(rule, directories.getWorkspace())); } else if (clientEnvironment.containsKey(PATH_ENV_VAR)) { androidSdkPath = fs .getPath(getAndroidHomeEnvironmentVar(directories.getWorkspace(), clientEnvironment)); } else { throw new RepositoryFunctionException(new EvalException(rule.getLocation(), "Either the path attribute of android_sdk_repository or the ANDROID_HOME environment " + " variable must be set."), Transience.PERSISTENT); } if (!symlinkLocalRepositoryContents(outputDirectory, androidSdkPath)) { return null; } DirectoryListingValue platformsDirectoryValue = getDirectoryListing(fs, androidSdkPath.getChild(PLATFORMS_DIR_NAME), env); if (platformsDirectoryValue == null) { return null; } ImmutableSortedSet<Integer> apiLevels = getApiLevels(platformsDirectoryValue.getDirents()); if (apiLevels.isEmpty()) { throw new RepositoryFunctionException(new EvalException(rule.getLocation(), "android_sdk_repository requires that at least one Android SDK Platform is installed " + "in the Android SDK. Please install an Android SDK Platform through the " + "Android SDK manager."), Transience.PERSISTENT); } String defaultApiLevel; if (attributes.isAttributeValueExplicitlySpecified("api_level")) { try { defaultApiLevel = attributes.get("api_level", Type.INTEGER).toString(); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } } else { // If the api_level attribute is not explicitly set, we select the highest api level that is // available in the SDK. defaultApiLevel = String.valueOf(apiLevels.first()); } String buildToolsDirectory; if (attributes.isAttributeValueExplicitlySpecified("build_tools_version")) { try { buildToolsDirectory = attributes.get("build_tools_version", Type.STRING); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } } else { // If the build_tools_version attribute is not explicitly set, we select the highest version // installed in the SDK. DirectoryListingValue directoryValue = getDirectoryListing(fs, androidSdkPath.getChild(BUILD_TOOLS_DIR_NAME), env); if (directoryValue == null) { return null; } buildToolsDirectory = getNewestBuildToolsDirectory(rule, directoryValue.getDirents()); } // android_sdk_repository.build_tools_version is technically actually the name of the // directory in $sdk/build-tools. Most of the time this is just the actual build tools // version, but for preview build tools, the directory is something like 24.0.0-preview, and // the actual version is something like "24 rc3". The android_sdk rule in the template needs // the real version. String buildToolsVersion; if (buildToolsDirectory.contains("-preview")) { Properties sourceProperties = getBuildToolsSourceProperties(outputDirectory, buildToolsDirectory, env); if (env.valuesMissing()) { return null; } buildToolsVersion = sourceProperties.getProperty("Pkg.Revision"); } else { buildToolsVersion = buildToolsDirectory; } try { assertValidBuildToolsVersion(rule, buildToolsVersion); } catch (EvalException e) { throw new RepositoryFunctionException(e, Transience.PERSISTENT); } String template = getStringResource("android_sdk_repository_template.txt"); String buildFile = template.replace("%repository_name%", rule.getName()) .replace("%build_tools_version%", buildToolsVersion) .replace("%build_tools_directory%", buildToolsDirectory) .replace("%api_levels%", Iterables.toString(apiLevels)) .replace("%default_api_level%", defaultApiLevel); // All local maven repositories that are shipped in the Android SDK. // TODO(ajmichael): Create SkyKeys so that if the SDK changes, this function will get rerun. Iterable<Path> localMavenRepositories = ImmutableList.of( outputDirectory.getRelative("extras/android/m2repository"), outputDirectory.getRelative("extras/google/m2repository")); try { SdkMavenRepository sdkExtrasRepository = SdkMavenRepository .create(Iterables.filter(localMavenRepositories, new Predicate<Path>() { @Override public boolean apply(@Nullable Path path) { return path.isDirectory(); } })); sdkExtrasRepository.writeBuildFiles(outputDirectory); buildFile = buildFile.replace("%exported_files%", sdkExtrasRepository.getExportsFiles(outputDirectory)); } catch (IOException e) { throw new RepositoryFunctionException(e, Transience.TRANSIENT); } writeBuildFile(outputDirectory, buildFile); return RepositoryDirectoryValue.builder().setPath(outputDirectory); }
From source file:com.zulily.omicron.sla.TimeSinceLastSuccess.java
@Override protected Alert generateAlert(final Job job) { // The task has never been evaluated to run because it's new or it's not considered to be runnable to begin with // We cannot logically evaluate this alert if (!job.isRunnable() || !job.isActive()) { return createNotApplicableAlert(job); }/* w w w. j a va 2 s. co m*/ final ImmutableSortedSet<TaskLogEntry> logView = job.filterLog(STATUS_FILTER); // No observable status changes in the task log - still nothing to do if (logView.isEmpty()) { return createNotApplicableAlert(job); } // Just succeed if the last log status is complete // This also avoids false alerts during schedule gaps if (logView.last().getTaskStatus() == TaskStatus.Complete) { return createAlert(job, logView.last(), AlertStatus.Success); } // Avoid spamming alerts during gaps in the schedule if (alertedOnceSinceLastActive(logView.last().getTimestamp(), job.getJobId())) { return createNotApplicableAlert(job); } // The last status is either error or failed start // so find that last time there was a complete, if any final Optional<TaskLogEntry> latestComplete = logView.descendingSet().stream() .filter(entry -> entry.getTaskStatus() == TaskStatus.Complete).findFirst(); // If we've seen at least one success in recent history and a task is running, // do not alert until a final status is achieved to avoid noise before potential recovery if (logView.last().getTaskStatus() == TaskStatus.Started && latestComplete.isPresent()) { return createNotApplicableAlert(job); } final int minutesBetweenSuccessThreshold = job.getConfiguration().getInt(ConfigKey.SLAMinutesSinceSuccess); final long currentTimestamp = Clock.systemUTC().millis(); final TaskLogEntry baselineTaskLogEntry = latestComplete.isPresent() ? latestComplete.get() : logView.first(); final long minutesIncomplete = TimeUnit.MILLISECONDS .toMinutes(currentTimestamp - baselineTaskLogEntry.getTimestamp()); if (minutesIncomplete <= minutesBetweenSuccessThreshold) { return createAlert(job, baselineTaskLogEntry, AlertStatus.Success); } else { return createAlert(job, baselineTaskLogEntry, AlertStatus.Failure); } }