Refine search
/** * Returns {@code true} if every element in {@code values} is {@linkplain #contains contained} in * this range. */ public boolean containsAll(Iterable<? extends C> values) { if (Iterables.isEmpty(values)) { return true; } // this optimizes testing equality of two range-backed sets if (values instanceof SortedSet) { SortedSet<? extends C> set = cast(values); Comparator<?> comparator = set.comparator(); if (Ordering.natural().equals(comparator) || comparator == null) { return contains(set.first()) && contains(set.last()); } } for (C value : values) { if (!contains(value)) { return false; } } return true; }
@Override protected SortedSet<Integer> create(Integer[] elements) { SortedSet<Integer> set = nullCheckedTreeSet(elements); if (set.isEmpty()) { /* * The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be * greater than tooHigh. */ return ContiguousSet.create(Range.openClosed(0, 1), DiscreteDomain.integers()).subSet(0, 1); } int tooHigh = set.last() + 1; int tooLow = set.first() - 1; set.add(tooHigh); set.add(tooLow); return checkedCreate(set).subSet(tooLow + 1, tooHigh); } }
/** * Returns the minimal range that {@linkplain Range#contains(Comparable) contains} all of the * given values. The returned range is {@linkplain BoundType#CLOSED closed} on both ends. * * @throws ClassCastException if the values are not mutually comparable * @throws NoSuchElementException if {@code values} is empty * @throws NullPointerException if any of {@code values} is null * @since 14.0 */ public static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> values) { checkNotNull(values); if (values instanceof SortedSet) { SortedSet<? extends C> set = cast(values); Comparator<?> comparator = set.comparator(); if (Ordering.natural().equals(comparator) || comparator == null) { return closed(set.first(), set.last()); } } Iterator<C> valueIterator = values.iterator(); C min = checkNotNull(valueIterator.next()); C max = min; while (valueIterator.hasNext()) { C value = checkNotNull(valueIterator.next()); min = Ordering.natural().min(min, value); max = Ordering.natural().max(max, value); } return closed(min, max); }
public Configuration(Set<Pipeline> pipelines) { if (pipelines.isEmpty()) { initialStage = extent[0] = extent[1] = 0; return; } pipelines.forEach(pipeline -> { // skip pipelines without any stages, they don't contribute any rules to run final SortedSet<Stage> stages = pipeline.stages(); if (stages.isEmpty()) { return; } extent[0] = Math.min(extent[0], stages.first().stage()); extent[1] = Math.max(extent[1], stages.last().stage()); stages.forEach(stage -> stageMultimap.put(stage.stage(), stage)); }); if (extent[0] == Integer.MIN_VALUE) { throw new IllegalArgumentException("First stage cannot be at " + Integer.MIN_VALUE); } // the stage before the first stage. initialStage = extent[0] - 1; }
public static void main(String[] args) { SortedSet<Integer> set=new TreeSet<>(); for(int i=0; i < args.length; i++) { set.add(Integer.parseInt(args[i])); } int low=set.first(), high=set.last(); System.out.println("input has " + set.size() + " numbers, low=" + low + ", high=" + high); Set<Integer> correct_set=new HashSet<>(); for(int i=low; i < high; i++) { correct_set.add(i); } correct_set.removeAll(set); System.out.println("missing seqnos: " + correct_set); } }
/** * Returns {@code true} if every element in {@code values} is {@linkplain #contains contained} in * this range. */ public boolean containsAll(Iterable<? extends C> values) { if (Iterables.isEmpty(values)) { return true; } // this optimizes testing equality of two range-backed sets if (values instanceof SortedSet) { SortedSet<? extends C> set = cast(values); Comparator<?> comparator = set.comparator(); if (Ordering.natural().equals(comparator) || comparator == null) { return contains(set.first()) && contains(set.last()); } } for (C value : values) { if (!contains(value)) { return false; } } return true; }
@VisibleForTesting protected DefaultSdkPicker(@Nonnull SdkCollection sdkCollection, String enabledSdks) { this.sdkCollection = sdkCollection; this.enabledSdks = enumerateEnabledSdks(sdkCollection, enabledSdks); SortedSet<Sdk> sdks = this.sdkCollection.getKnownSdks(); try { minKnownSdk = sdks.first(); maxKnownSdk = sdks.last(); } catch (NoSuchElementException e) { throw new RuntimeException("no SDKs are supported among " + sdkCollection.getKnownSdks(), e); } }
/** * Returns {@code true} if every element in {@code values} is {@linkplain #contains contained} in * this range. */ public boolean containsAll(Iterable<? extends C> values) { if (Iterables.isEmpty(values)) { return true; } // this optimizes testing equality of two range-backed sets if (values instanceof SortedSet) { SortedSet<? extends C> set = cast(values); Comparator<?> comparator = set.comparator(); if (Ordering.natural().equals(comparator) || comparator == null) { return contains(set.first()) && contains(set.last()); } } for (C value : values) { if (!contains(value)) { return false; } } return true; }
double minComplete = 2; double bestComplete = -100000; //approximating -infinity/0 in ln domain while (odh.size() > 0 && (completeParses.size() < M || (odh.first()).getProb() < minComplete) && derivationStage < maxDerivationLength) { ndh = new TreeSet<>(); nd = advanceChunks(tp,(ndh.last()).getProb()); return new Parse[] {completeParses.first()}; while (!completeParses.isEmpty() && topParses.size() < numParses) { Parse tp = completeParses.last(); completeParses.remove(tp); topParses.add(tp);
/** * Returns the minimal range that {@linkplain Range#contains(Comparable) contains} all of the * given values. The returned range is {@linkplain BoundType#CLOSED closed} on both ends. * * @throws ClassCastException if the parameters are not <i>mutually comparable</i> * @throws NoSuchElementException if {@code values} is empty * @throws NullPointerException if any of {@code values} is null * @since 14.0 */ public static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> values) { checkNotNull(values); if (values instanceof SortedSet) { SortedSet<? extends C> set = cast(values); Comparator<?> comparator = set.comparator(); if (Ordering.natural().equals(comparator) || comparator == null) { return closed(set.first(), set.last()); } } Iterator<C> valueIterator = values.iterator(); C min = checkNotNull(valueIterator.next()); C max = min; while (valueIterator.hasNext()) { C value = checkNotNull(valueIterator.next()); min = Ordering.natural().min(min, value); max = Ordering.natural().max(max, value); } return closed(min, max); }
private static String getFileName(String homePath, Pattern pattern) { File home = new File(homePath); SortedSet<String> files = Sets.newTreeSet(); if (home.exists() && home.isDirectory()) { File[] listFiles = home.listFiles(); if (listFiles != null) { for (File file : listFiles) { final Matcher matcher = pattern.matcher(file.getName()); if (matcher.matches()) { files.add(file.getAbsolutePath()); } } } } if (files.isEmpty()) { throw new RuntimeException("cannot find " + pattern.toString() + " in " + homePath); } else { return files.last(); } }