本文整理汇总了Java中com.google.common.annotations.Beta类的典型用法代码示例。如果您正苦于以下问题:Java Beta类的具体用法?Java Beta怎么用?Java Beta使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Beta类属于com.google.common.annotations包,在下文中一共展示了Beta类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: appendTo
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Appends the string representation of each entry in {@code entries}, using the previously
* configured separator and key-value separator, to {@code appendable}.
*
* @since 11.0
*/
@Beta
@CanIgnoreReturnValue
public <A extends Appendable> A appendTo(A appendable, Iterator<? extends Entry<?, ?>> parts)
throws IOException {
checkNotNull(appendable);
if (parts.hasNext()) {
Entry<?, ?> entry = parts.next();
appendable.append(joiner.toString(entry.getKey()));
appendable.append(keyValueSeparator);
appendable.append(joiner.toString(entry.getValue()));
while (parts.hasNext()) {
appendable.append(joiner.separator);
Entry<?, ?> e = parts.next();
appendable.append(joiner.toString(e.getKey()));
appendable.append(keyValueSeparator);
appendable.append(joiner.toString(e.getValue()));
}
}
return appendable;
}
示例2: toImmutableEnumMap
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns a {@link Collector} that accumulates elements into an {@code ImmutableMap} whose keys
* and values are the result of applying the provided mapping functions to the input elements. The
* resulting implementation is specialized for enum key types. The returned map and its views will
* iterate over keys in their enum definition order, not encounter order.
*
* <p>If the mapped keys contain duplicates, the values are merged using the specified merging
* function.
*
* @since 21.0
*/
@Beta
public static <T, K extends Enum<K>, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableEnumMap(
java.util.function.Function<? super T, ? extends K> keyFunction,
java.util.function.Function<? super T, ? extends V> valueFunction,
BinaryOperator<V> mergeFunction) {
checkNotNull(keyFunction);
checkNotNull(valueFunction);
checkNotNull(mergeFunction);
// not UNORDERED because we don't know if mergeFunction is commutative
return Collector.of(
() -> new Accumulator<K, V>(mergeFunction),
(accum, t) -> {
K key = checkNotNull(keyFunction.apply(t), "Null key for input %s", t);
V newValue = checkNotNull(valueFunction.apply(t), "Null value for input %s", t);
accum.put(key, newValue);
},
Accumulator::combine,
Accumulator::toImmutableMap);
}
示例3: tryParse
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Parses the specified string as a double-precision floating point value. The ASCII character
* {@code '-'} (<code>'\u002D'</code>) is recognized as the minus sign.
*
* <p>Unlike {@link Double#parseDouble(String)}, this method returns {@code null} instead of
* throwing an exception if parsing fails. Valid inputs are exactly those accepted by
* {@link Double#valueOf(String)}, except that leading and trailing whitespace is not permitted.
*
* <p>This implementation is likely to be faster than {@code
* Double.parseDouble} if many failures are expected.
*
* @param string the string representation of a {@code double} value
* @return the floating point value represented by {@code string}, or {@code null} if
* {@code string} has a length of zero or cannot be parsed as a {@code double} value
* @since 14.0
*/
@Beta
@Nullable
@CheckForNull
@GwtIncompatible // regular expressions
public static Double tryParse(String string) {
if (FLOATING_POINT_PATTERN.matcher(string).matches()) {
// TODO(lowasser): could be potentially optimized, but only with
// extensive testing
try {
return Double.parseDouble(string);
} catch (NumberFormatException e) {
// Double.parseDouble has changed specs several times, so fall through
// gracefully
}
}
return null;
}
示例4: fields
import com.google.common.annotations.Beta; //导入依赖的package包/类
private static void fields() {
Fields fs1 = Scanner.paths("/io/ytcode/reflect/").scan().classes().fields();
Fields fs2 =
fs1.annotatedWith(Beta.class)
.filter(
new Predicate<Field>() {
@Override
public boolean apply(Field f) {
return Modifier.isStatic(f.getModifiers());
}
});
System.out.println(fs2);
Fields fs3 = fs1.modifiers(Modifier.PUBLIC, Modifier.STATIC);
System.out.println(fs3);
}
示例5: readLines
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Reads lines of text from this source, processing each line as it is read using the given
* {@link LineProcessor processor}. Stops when all lines have been processed or the processor
* returns {@code false} and returns the result produced by the processor.
*
* <p>Like {@link BufferedReader}, this method breaks lines on any of {@code \n}, {@code \r} or
* {@code \r\n}, does not include the line separator in the lines passed to the {@code processor}
* and does not consider there to be an extra empty line at the end if the content is terminated
* with a line separator.
*
* @throws IOException if an I/O error occurs in the process of reading from this source or if
* {@code processor} throws an {@code IOException}
* @since 16.0
*/
@Beta
@CanIgnoreReturnValue // some processors won't return a useful result
public <T> T readLines(LineProcessor<T> processor) throws IOException {
checkNotNull(processor);
Closer closer = Closer.create();
try {
Reader reader = closer.register(openStream());
return CharStreams.readLines(reader, processor);
} catch (Throwable e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
示例6: immutableEnumMap
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns an immutable map instance containing the given entries.
* Internally, the returned map will be backed by an {@link EnumMap}.
*
* <p>The iteration order of the returned map follows the enum's iteration
* order, not the order in which the elements appear in the given map.
*
* @param map the map to make an immutable copy of
* @return an immutable map containing those entries
* @since 14.0
*/
@GwtCompatible(serializable = true)
@Beta
public static <K extends Enum<K>, V> ImmutableMap<K, V> immutableEnumMap(
Map<K, ? extends V> map) {
if (map instanceof ImmutableEnumMap) {
@SuppressWarnings("unchecked") // safe covariant cast
ImmutableEnumMap<K, V> result = (ImmutableEnumMap<K, V>) map;
return result;
} else if (map.isEmpty()) {
return ImmutableMap.of();
} else {
for (Map.Entry<K, ? extends V> entry : map.entrySet()) {
checkNotNull(entry.getKey());
checkNotNull(entry.getValue());
}
return ImmutableEnumMap.asImmutable(new EnumMap<K, V>(map));
}
}
示例7: subMap
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns a view of the portion of {@code map} whose keys are contained by {@code range}.
*
* <p>This method delegates to the appropriate methods of {@link NavigableMap} (namely
* {@link NavigableMap#subMap(Object, boolean, Object, boolean) subMap()},
* {@link NavigableMap#tailMap(Object, boolean) tailMap()}, and
* {@link NavigableMap#headMap(Object, boolean) headMap()}) to actually construct the view.
* Consult these methods for a full description of the returned view's behavior.
*
* <p><b>Warning:</b> {@code Range}s always represent a range of values using the values' natural
* ordering. {@code NavigableMap} on the other hand can specify a custom ordering via a
* {@link Comparator}, which can violate the natural ordering. Using this method (or in general
* using {@code Range}) with unnaturally-ordered maps can lead to unexpected and undefined
* behavior.
*
* @since 20.0
*/
@Beta
@GwtIncompatible // NavigableMap
public static <K extends Comparable<? super K>, V> NavigableMap<K, V> subMap(
NavigableMap<K, V> map, Range<K> range) {
if (map.comparator() != null
&& map.comparator() != Ordering.natural()
&& range.hasLowerBound()
&& range.hasUpperBound()) {
checkArgument(
map.comparator().compare(range.lowerEndpoint(), range.upperEndpoint()) <= 0,
"map is using a custom comparator which is inconsistent with the natural ordering.");
}
if (range.hasLowerBound() && range.hasUpperBound()) {
return map.subMap(
range.lowerEndpoint(),
range.lowerBoundType() == BoundType.CLOSED,
range.upperEndpoint(),
range.upperBoundType() == BoundType.CLOSED);
} else if (range.hasLowerBound()) {
return map.tailMap(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED);
} else if (range.hasUpperBound()) {
return map.headMap(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED);
}
return checkNotNull(map);
}
示例8: toImmutableTable
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns a {@code Collector} that accumulates elements into an {@code ImmutableTable}. Each
* input element is mapped to one cell in the returned table, with the rows, columns, and values
* generated by applying the specified functions.
*
* <p>The returned {@code Collector} will throw a {@code NullPointerException} at collection time
* if the row, column, or value functions return null on any input.
*
* @since 21.0
*/
@Beta
public static <T, R, C, V> Collector<T, ?, ImmutableTable<R, C, V>> toImmutableTable(
Function<? super T, ? extends R> rowFunction,
Function<? super T, ? extends C> columnFunction,
Function<? super T, ? extends V> valueFunction) {
checkNotNull(rowFunction);
checkNotNull(columnFunction);
checkNotNull(valueFunction);
return Collector.of(
() -> new ImmutableTable.Builder<R, C, V>(),
(builder, t) ->
builder.put(rowFunction.apply(t), columnFunction.apply(t), valueFunction.apply(t)),
(b1, b2) -> b1.combine(b2),
b -> b.build());
}
示例9: copyOf
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns an immutable map containing the specified entries. The returned
* map iterates over entries in the same order as the original iterable.
*
* @throws NullPointerException if any key, value, or entry is null
* @throws IllegalArgumentException if two entries have the same key
* @since 19.0
*/
@Beta
public static <K, V> ImmutableMap<K, V> copyOf(
Iterable<? extends Entry<? extends K, ? extends V>> entries) {
@SuppressWarnings("unchecked") // we'll only be using getKey and getValue, which are covariant
Entry<K, V>[] entryArray = (Entry<K, V>[]) Iterables.toArray(entries, EMPTY_ENTRY_ARRAY);
switch (entryArray.length) {
case 0:
return of();
case 1:
Entry<K, V> onlyEntry = entryArray[0];
return of(onlyEntry.getKey(), onlyEntry.getValue());
default:
/*
* The current implementation will end up using entryArray directly, though it will write
* over the (arbitrary, potentially mutable) Entry objects actually stored in entryArray.
*/
return RegularImmutableMap.fromEntries(entryArray);
}
}
示例10: toImmutableMap
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns a {@link Collector} that accumulates elements into an {@code ImmutableMap} whose keys
* and values are the result of applying the provided mapping functions to the input elements.
*
* <p>If the mapped keys contain duplicates (according to {@link Object#equals(Object)}), the
* values are merged using the specified merging function. Entries will appear in the encounter
* order of the first occurrence of the key.
*
* @since 21.0
*/
@Beta
public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
Function<? super T, ? extends K> keyFunction,
Function<? super T, ? extends V> valueFunction,
BinaryOperator<V> mergeFunction) {
checkNotNull(keyFunction);
checkNotNull(valueFunction);
checkNotNull(mergeFunction);
return Collectors.collectingAndThen(
Collectors.toMap(keyFunction, valueFunction, mergeFunction, LinkedHashMap::new),
ImmutableMap::copyOf);
}
示例11: copyHighestCountFirst
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns a copy of {@code multiset} as an {@link ImmutableMultiset} whose iteration order is
* highest count first, with ties broken by the iteration order of the original multiset.
*
* @since 11.0
*/
@Beta
public static <E> ImmutableMultiset<E> copyHighestCountFirst(Multiset<E> multiset) {
List<Entry<E>> sortedEntries =
Multisets.DECREASING_COUNT_ORDERING.immutableSortedCopy(multiset.entrySet());
return ImmutableMultiset.copyFromEntries(sortedEntries);
}
示例12: toImmutableSortedMap
import com.google.common.annotations.Beta; //导入依赖的package包/类
@Beta
public static <T, K, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
Comparator<? super K> comparator,
Function<? super T, ? extends K> keyFunction,
Function<? super T, ? extends V> valueFunction,
BinaryOperator<V> mergeFunction) {
checkNotNull(comparator);
checkNotNull(keyFunction);
checkNotNull(valueFunction);
checkNotNull(mergeFunction);
return Collectors.collectingAndThen(
Collectors.toMap(
keyFunction, valueFunction, mergeFunction, () -> new TreeMap<K, V>(comparator)),
ImmutableSortedMap::copyOfSorted);
}
示例13: floorPowerOfTwo
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns the largest power of two less than or equal to {@code x}. This is equivalent to
* {@code checkedPow(2, log2(x, FLOOR))}.
*
* @throws IllegalArgumentException if {@code x <= 0}
* @since 20.0
*/
@Beta
public static long floorPowerOfTwo(long x) {
checkPositive("x", x);
// Long.highestOneBit was buggy on GWT. We've fixed it, but I'm not certain when the fix will
// be released.
return 1L << ((Long.SIZE - 1) - Long.numberOfLeadingZeros(x));
}
示例14: saturatedAdd
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns the sum of {@code a} and {@code b} unless it would overflow or underflow in which case
* {@code Long.MAX_VALUE} or {@code Long.MIN_VALUE} is returned, respectively.
*
* @since 20.0
*/
@Beta
public static long saturatedAdd(long a, long b) {
long naiveSum = a + b;
if ((a ^ b) < 0 | (a ^ naiveSum) >= 0) {
// If a and b have different signs or a has the same sign as the result then there was no
// overflow, return.
return naiveSum;
}
// we did over/under flow, if the sign is negative we should return MAX otherwise MIN
return Long.MAX_VALUE + ((naiveSum >>> (Long.SIZE - 1)) ^ 1);
}
示例15: run
import com.google.common.annotations.Beta; //导入依赖的package包/类
/**
* Returns a list of delegate futures that correspond to the futures received in the order that
* they complete. Delegate futures return the same value or throw the same exception as the
* corresponding input future returns/throws.
*
* <p>Cancelling a delegate future has no effect on any input future, since the delegate future
* does not correspond to a specific input future until the appropriate number of input futures
* have completed. At that point, it is too late to cancel the input future. The input future's
* result, which cannot be stored into the cancelled delegate future, is ignored.
*
* @since 17.0
*/
@Beta
@GwtIncompatible // TODO
public static <T> ImmutableList<ListenableFuture<T>> inCompletionOrder(
Iterable<? extends ListenableFuture<? extends T>> futures) {
// A CLQ may be overkill here. We could save some pointers/memory by synchronizing on an
// ArrayDeque
final ConcurrentLinkedQueue<SettableFuture<T>> delegates = Queues.newConcurrentLinkedQueue();
ImmutableList.Builder<ListenableFuture<T>> listBuilder = ImmutableList.builder();
// Using SerializingExecutor here will ensure that each CompletionOrderListener executes
// atomically and therefore that each returned future is guaranteed to be in completion order.
// N.B. there are some cases where the use of this executor could have possibly surprising
// effects when input futures finish at approximately the same time _and_ the output futures
// have directExecutor listeners. In this situation, the listeners may end up running on a
// different thread than if they were attached to the corresponding input future. We believe
// this to be a negligible cost since:
// 1. Using the directExecutor implies that your callback is safe to run on any thread.
// 2. This would likely only be noticeable if you were doing something expensive or blocking on
// a directExecutor listener on one of the output futures which is an antipattern anyway.
SerializingExecutor executor = new SerializingExecutor(directExecutor());
for (final ListenableFuture<? extends T> future : futures) {
SettableFuture<T> delegate = SettableFuture.create();
// Must make sure to add the delegate to the queue first in case the future is already done
delegates.add(delegate);
future.addListener(
new Runnable() {
@Override
public void run() {
delegates.remove().setFuture(future);
}
},
executor);
listBuilder.add(delegate);
}
return listBuilder.build();
}