/** * Returns results from parsing a {@link java.net.URI} with this pattern. If the URI doesn't match * the pattern, this will return null. * * @param uri A URI to match against this URIPattern * @return A Map of the pattern's variable names to values from the parsed URI */ public Map<String, String> getMatch(URI uri) { // verify that the schemes match if (pattern.isAbsolute()) { // if there should be a scheme, make sure it matches if (!pattern.getScheme().equalsIgnoreCase(uri.getScheme())) { return null; } } else if (uri.getScheme() != null) { return null; } Map<String, String> result = Maps.newLinkedHashMap(defaults); if (pattern.isOpaque()) { if (!uri.isOpaque()) { return null; } Iterator<String> pathQuery = PATH_QUERY_SPLITTER.split(uri.getRawSchemeSpecificPart()).iterator(); if (!addPath(patternPath, Iterators.getNext(pathQuery, null), result)) { return null; } addQuery(Iterators.getNext(pathQuery, null), result); } else if (!uri.isOpaque()) { addAuthority(uri, result); if (patternPath.isEmpty() && !uri.getRawPath().isEmpty()) { return null; } if (!addPath(patternPath, uri.getRawPath(), result)) { return null; } addQuery(uri.getRawQuery(), result); } else { return null; } if (!addComplexMatch(pattern.getFragment(), uri.getFragment(), result)) { return null; } // save this match this.lastMatch = result; // return the new result, so that this is thread-safe return result; }
public URIPattern(URI uri) { this.pattern = uri; Map<String, String> accumulator = Maps.newHashMap(); if (pattern.isOpaque()) { Iterator<String> pathQuery = PATH_QUERY_SPLITTER.split(pattern.getSchemeSpecificPart()).iterator(); this.patternPath = Iterators.getNext(pathQuery, null); addQuery(Iterators.getNext(pathQuery, null), accumulator); } else { patternPath = pattern.getRawPath(); addQuery(pattern.getRawQuery(), accumulator); addAuthority(pattern, accumulator); } if (pattern.getScheme() != null) { accumulator.put(SCHEME, pattern.getScheme()); } this.defaults = ImmutableMap.copyOf(accumulator); }
@Override public int run() throws IOException { if (datasets == null || datasets.size() != 1) { throw new IllegalArgumentException("Exactly one dataset name must be specified."); } String dataset = datasets.remove(0); Dataset<GenericRecord> currentDataset = load(dataset).getDataset(); DatasetDescriptor.Builder descriptorBuilder = new DatasetDescriptor.Builder(currentDataset.getDescriptor()); if (avroSchemaFile != null) { descriptorBuilder.schemaUri(qualifiedURI(avroSchemaFile)); } if (partitionStrategyFile != null) { descriptorBuilder.partitionStrategyUri(qualifiedURI(partitionStrategyFile)); } if (properties != null) { for (String propValue : properties) { Iterator<String> parts = PROP_VALUE_SEP.split(propValue).iterator(); descriptorBuilder.property(Iterators.getNext(parts, null), Iterators.getNext(parts, null)); } } DatasetDescriptor descriptor = descriptorBuilder.build(); if (isDatasetOrViewUri(dataset)) { Datasets.<GenericData.Record, Dataset<GenericData.Record>>update( dataset, descriptor, GenericData.Record.class); } else { getDatasetRepository().update(namespace, dataset, descriptor); } console.debug("Updated {}", dataset); return 0; }
/** * Returns the element at the specified position in an iterable or a default value otherwise. * * @param position position of the element to return * @param defaultValue the default value to return if {@code position} is greater than or equal to * the size of the iterable * @return the element at the specified position in {@code iterable} or {@code defaultValue} if * {@code iterable} contains fewer than {@code position + 1} elements. * @throws IndexOutOfBoundsException if {@code position} is negative * @since 4.0 */ @Nullable public static <T> T get(Iterable<? extends T> iterable, int position, @Nullable T defaultValue) { checkNotNull(iterable); Iterators.checkNonnegative(position); if (iterable instanceof List) { List<? extends T> list = Lists.cast(iterable); return (position < list.size()) ? list.get(position) : defaultValue; } else { Iterator<? extends T> iterator = iterable.iterator(); Iterators.advance(iterator, position); return Iterators.getNext(iterator, defaultValue); } }
@GwtIncompatible("NavigableSet") public Object floor(Object paramObject) { return Iterators.getNext(headSet(paramObject, true).descendingIterator(), null); }
/** * A sensible definition of {@link #ceiling} in terms of the {@code iterator} method of {@link * #tailSet(Object, boolean)}. If you override {@link #tailSet(Object, boolean)}, you may wish to * override {@link #ceiling} to forward to this implementation. */ protected E standardCeiling(E e) { return Iterators.getNext(tailSet(e, true).iterator(), null); }
/** * A sensible definition of {@link #floor} in terms of the {@code descendingIterator} method of * {@link #headSet(Object, boolean)}. If you override {@link #headSet(Object, boolean)}, you may * wish to override {@link #floor} to forward to this implementation. */ protected E standardFloor(E e) { return Iterators.getNext(headSet(e, true).descendingIterator(), null); }
/** * A sensible definition of {@link #lower} in terms of the {@code descendingIterator} method of * {@link #headSet(Object, boolean)}. If you override {@link #headSet(Object, boolean)}, you may * wish to override {@link #lower} to forward to this implementation. */ protected E standardLower(E e) { return Iterators.getNext(headSet(e, false).descendingIterator(), null); }
/** * A sensible definition of {@link #higher} in terms of the {@code iterator} method of {@link * #tailSet(Object, boolean)}. If you override {@link #tailSet(Object, boolean)}, you may wish to * override {@link #higher} to forward to this implementation. */ protected E standardHigher(E e) { return Iterators.getNext(tailSet(e, false).iterator(), null); }
/** * Remove a resource request and return it. * * @return The {@link Resource} and {@link Collection} of {@link RuntimeSpecification} or {@code * null} if there is no more request. */ Map.Entry<Resource, ? extends Collection<RuntimeSpecification>> takeRequest() { Map.Entry<Resource, Collection<RuntimeSpecification>> next = Iterators.getNext(requests, null); return next == null ? null : Maps.immutableEntry(next.getKey(), ImmutableList.copyOf(next.getValue())); }
/** * Returns the first element in {@code iterable} or {@code defaultValue} if the iterable is empty. * The {@link Iterators} analog to this method is {@link Iterators#getNext}. * * <p>If no default value is desired (and the caller instead wants a {@link * NoSuchElementException} to be thrown), it is recommended that {@code * iterable.iterator().next()} is used instead. * * @param defaultValue the default value to return if the iterable is empty * @return the first element of {@code iterable} or the default value * @since 7.0 */ @Nullable public static <T> T getFirst(Iterable<? extends T> iterable, @Nullable T defaultValue) { return Iterators.getNext(iterable.iterator(), defaultValue); }