本文整理汇总了Java中com.google.common.annotations.GwtCompatible类的典型用法代码示例。如果您正苦于以下问题:Java GwtCompatible类的具体用法?Java GwtCompatible怎么用?Java GwtCompatible使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GwtCompatible类属于com.google.common.annotations包,在下文中一共展示了GwtCompatible类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: immutableEnumSet
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns an immutable set instance containing the given enum elements.
* Internally, the returned set will be backed by an {@link EnumSet}.
*
* <p>The iteration order of the returned set follows the enum's iteration
* order, not the order in which the elements appear in the given collection.
*
* @param elements the elements, all of the same {@code enum} type, that the
* set should contain
* @return an immutable set containing those elements, minus duplicates
*/
// http://code.google.com/p/google-web-toolkit/issues/detail?id=3028
@GwtCompatible(serializable = true)
public static <E extends Enum<E>> ImmutableSet<E> immutableEnumSet(Iterable<E> elements) {
if (elements instanceof ImmutableEnumSet) {
return (ImmutableEnumSet<E>) elements;
} else if (elements instanceof Collection) {
Collection<E> collection = (Collection<E>) elements;
if (collection.isEmpty()) {
return ImmutableSet.of();
} else {
return ImmutableEnumSet.asImmutable(EnumSet.copyOf(collection));
}
} else {
Iterator<E> itr = elements.iterator();
if (itr.hasNext()) {
EnumSet<E> enumSet = EnumSet.of(itr.next());
Iterators.addAll(enumSet, itr);
return ImmutableEnumSet.asImmutable(enumSet);
} else {
return ImmutableSet.of();
}
}
}
示例2: immutableEnumMap
import com.google.common.annotations.GwtCompatible; //导入依赖的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));
}
}
示例3: lexicographical
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns a new ordering which sorts iterables by comparing corresponding
* elements pairwise until a nonzero result is found; imposes "dictionary
* order". If the end of one iterable is reached, but not the other, the
* shorter iterable is considered to be less than the longer one. For example,
* a lexicographical natural ordering over integers considers {@code
* [] < [1] < [1, 1] < [1, 2] < [2]}.
*
* <p>Note that {@code ordering.lexicographical().reverse()} is not
* equivalent to {@code ordering.reverse().lexicographical()} (consider how
* each would order {@code [1]} and {@code [1, 1]}).
*
* @since 2.0
*/
@GwtCompatible(serializable = true)
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<Iterable<String>> o =
// Ordering.<String>natural().lexicographical();
public <S extends T> Ordering<Iterable<S>> lexicographical() {
/*
* Note that technically the returned ordering should be capable of
* handling not just {@code Iterable<S>} instances, but also any {@code
* Iterable<? extends S>}. However, the need for this comes up so rarely
* that it doesn't justify making everyone else deal with the very ugly
* wildcard.
*/
return new LexicographicalOrdering<S>(this);
}
示例4: immutableEnumSet
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns an immutable set instance containing the given enum elements.
* Internally, the returned set will be backed by an {@link EnumSet}.
*
* <p>The iteration order of the returned set follows the enum's iteration
* order, not the order in which the elements appear in the given collection.
*
* @param elements the elements, all of the same {@code enum} type, that the
* set should contain
* @return an immutable set containing those elements, minus duplicates
*/
// http://code.google.com/p/google-web-toolkit/issues/detail?id=3028
@GwtCompatible(serializable = true)
public static <E extends Enum<E>> ImmutableSet<E> immutableEnumSet(Iterable<E> elements) {
if (elements instanceof ImmutableEnumSet) {
return (ImmutableEnumSet<E>) elements;
} else if (elements instanceof Collection) {
Collection<E> collection = (Collection<E>) elements;
if (collection.isEmpty()) {
return ImmutableSet.of();
} else {
return ImmutableEnumSet.asImmutable(EnumSet.copyOf(collection));
}
} else {
Iterator<E> itr = elements.iterator();
if (itr.hasNext()) {
EnumSet<E> enumSet = EnumSet.of(itr.next());
Iterators.addAll(enumSet, itr);
return ImmutableEnumSet.asImmutable(enumSet);
} else {
return ImmutableSet.of();
}
}
}
示例5: immutableEnumMap
import com.google.common.annotations.GwtCompatible; //导入依赖的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));
}
}
示例6: reverse
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns the reverse of this ordering; the {@code Ordering} equivalent to {@link
* Collections#reverseOrder(Comparator)}.
*
* <p><b>Java 8 users:</b> Use {@code thisComparator.reversed()} instead.
*/
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<String> o = Ordering.<String>natural().reverse();
@GwtCompatible(serializable = true)
public <S extends T> Ordering<S> reverse() {
return new ReverseOrdering<S>(this);
}
示例7: nullsFirst
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns an ordering that treats {@code null} as less than all other values and uses {@code
* this} to compare non-null values.
*
* <p><b>Java 8 users:</b> Use {@code Comparator.nullsFirst(thisComparator)} instead.
*/
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<String> o = Ordering.<String>natural().nullsFirst();
@GwtCompatible(serializable = true)
public <S extends T> Ordering<S> nullsFirst() {
return new NullsFirstOrdering<S>(this);
}
示例8: nullsLast
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns an ordering that treats {@code null} as greater than all other values and uses this
* ordering to compare non-null values.
*
* <p><b>Java 8 users:</b> Use {@code Comparator.nullsLast(thisComparator)} instead.
*/
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<String> o = Ordering.<String>natural().nullsLast();
@GwtCompatible(serializable = true)
public <S extends T> Ordering<S> nullsLast() {
return new NullsLastOrdering<S>(this);
}
示例9: lexicographical
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns a new ordering which sorts iterables by comparing corresponding
* elements pairwise until a nonzero result is found; imposes "dictionary
* order". If the end of one iterable is reached, but not the other, the
* shorter iterable is considered to be less than the longer one. For example,
* a lexicographical natural ordering over integers considers {@code
* [] < [1] < [1, 1] < [1, 2] < [2]}.
*
* <p>Note that {@code ordering.lexicographical().reverse()} is not
* equivalent to {@code ordering.reverse().lexicographical()} (consider how
* each would order {@code [1]} and {@code [1, 1]}).
*
* @since 2.0
*/
@GwtCompatible(serializable = true)
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<Iterable<String>> o =
// Ordering.<String>natural().lexicographical();
public <S extends T> Ordering<Iterable<S>> lexicographical() {
/*
* Note that technically the returned ordering should be capable of
* handling not just {@code Iterable<S>} instances, but also any {@code
* Iterable<? extends S>}. However, the need for this comes up so rarely
* that it doesn't justify making everyone else deal with the very ugly
* wildcard.
*/
return new LexicographicalOrdering<S>(this);
}
示例10: nullsFirst
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns an ordering that treats {@code null} as less than all other values
* and uses {@code this} to compare non-null values.
*/
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<String> o = Ordering.<String>natural().nullsFirst();
@GwtCompatible(serializable = true)
public <S extends T> Ordering<S> nullsFirst() {
return new NullsFirstOrdering<S>(this);
}
示例11: nullsLast
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns an ordering that treats {@code null} as greater than all other
* values and uses this ordering to compare non-null values.
*/
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<String> o = Ordering.<String>natural().nullsLast();
@GwtCompatible(serializable = true)
public <S extends T> Ordering<S> nullsLast() {
return new NullsLastOrdering<S>(this);
}
示例12: TODO
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Creates a <i>mutable</i> {@code ArrayList} instance containing the given
* elements; a very thin shortcut for creating an empty list and then calling
* {@link Iterators#addAll}.
*
* <p><b>Note:</b> if mutability is not required and the elements are
* non-null, use {@link ImmutableList#copyOf(Iterator)} instead.
*/
@CanIgnoreReturnValue // TODO(kak): Remove this
@GwtCompatible(serializable = true)
public static <E> ArrayList<E> newArrayList(Iterator<? extends E> elements) {
ArrayList<E> list = newArrayList();
Iterators.addAll(list, elements);
return list;
}
示例13: nullsFirst
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns an ordering that treats {@code null} as less than all other values
* and uses {@code this} to compare non-null values.
*/
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<String> o = Ordering.<String>natural().nullsFirst();
@GwtCompatible(serializable = true)
public <S extends T> Ordering<S> nullsFirst() {
return new NullsFirstOrdering<S>(this);
}
示例14: from
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Simply returns its argument.
*
* @deprecated no need to use this
*/
@GwtCompatible(serializable = true)
@Deprecated
public static <T> Ordering<T> from(Ordering<T> ordering) {
return checkNotNull(ordering);
}
示例15: reverse
import com.google.common.annotations.GwtCompatible; //导入依赖的package包/类
/**
* Returns the reverse of this ordering; the {@code Ordering} equivalent to
* {@link Collections#reverseOrder(Comparator)}.
*/
// type parameter <S> lets us avoid the extra <String> in statements like:
// Ordering<String> o = Ordering.<String>natural().reverse();
@GwtCompatible(serializable = true)
public <S extends T> Ordering<S> reverse() {
return new ReverseOrdering<S>(this);
}