鍍金池/ 教程/ Java/ Guava Range類
Guava原語工具
Guava集合工具
Guava Chars類
Guava Shorts類
Guava CharMatcher類
Guava BigIntegerMath類
Guava Range類
Guava Bimap接口
Guava緩存工具
Guava Longs類
Guava Multiset接口
Guava Table接口
Guava Optional類
Guava LongMath類
Guava Spiltter類
Guava Preconditions類
Guava數(shù)學(xué)工具
Guava Ints類
Guava Ordering類
Guava Throwables類
Guava字符串工具
Guava Objects類
Guava Booleans類
Guava教程
Guava Bytes類
Guava CaseFormat類
Guava環(huán)境設(shè)置
Guava Doubles類
Guava Joiner類
Guava Multimap類
Guava Floats類
Guava IntMath類

Guava Range類

Range 表示一個間隔或一個序列。它被用于獲取一組數(shù)字/串在一個特定范圍之內(nèi)。

類聲明

以下是com.google.common.collect.Range<C>類的聲明:

@GwtCompatible
public final class Range<C extends Comparable>
   extends Object
      implements Predicate<C>, Serializable

方法

S.N. 方法及說明
1 static <C extends Comparable<?>> Range<C> all()
返回包含C型的每一個值范圍
2 boolean apply(C input)Deprecated. 
只有提供滿足謂詞接口;使用包含(C)來代替。
3 static <C extends Comparable<?>> Range<C> atLeast(C endpoint)
返回包含大于或等于終點(endpoint)的所有值的范圍內(nèi)。
4 static <C extends Comparable<?>> Range<C> atMost(C endpoint)
返回包含的所有值小于或等于終點的范圍內(nèi)。
5 Range<C> canonical(DiscreteDomain<C> domain)
返回此范圍內(nèi),在給定域中的規(guī)范形式。
6 static <C extends Comparable<?>> Range<C> closed(C lower, C upper)
返回包含大于所有值或等于降低且小于或等于上限的范圍內(nèi)。
7 static <C extends Comparable<?>> Range<C> closedOpen(C lower, C upper)
返回包含大于或等于下限和所有值嚴(yán)格大于上限以下的范圍內(nèi)。
8 boolean contains(C value)
返回true,如果值是這個范圍的范圍之內(nèi)。
9 boolean containsAll(Iterable<? extends C> values)
如果值每一個元素都包含在這個范圍內(nèi),則返回 true。
10 static <C extends Comparable<?>> Range<C> downTo(C endpoint, BoundType boundType)
返回的范圍內(nèi)的給定的端點,它可以是包容性(閉合)或?qū)S茫ㄩ_),沒有上限。
11 static <C extends Comparable<?>> Range<C> encloseAll(Iterable<C> values)
返回包含所有給定值的最小范圍內(nèi)。
12 boolean encloses(Range<C> other)
返回true,如果其他的邊界不在該范圍的邊界之外延伸。
13 boolean equals(Object object)
返回true,如果對象是具有相同端點和綁定類型,這個范圍內(nèi)的范圍。
14 static <C extends Comparable<?>> Range<C> greaterThan(C endpoint)
返回一個包含所有值嚴(yán)格大于端點的范圍內(nèi)。
15 int hashCode()
返回此范圍內(nèi)的哈希碼。
16 boolean hasLowerBound()
如果此范圍內(nèi)具有更低的終點返回true。
17 boolean hasUpperBound()
如果此范圍內(nèi)有上端點返回true。
18 Range<C> intersection(Range<C> connectedRange)
返回由兩者范圍和connectedRange封閉,如果這樣的范圍存在的最大范圍。
19 boolean isConnected(Range<C> other)
如果存在這是由兩者此范圍和其他封閉(可能為空)的范圍,則返回true。
20 boolean isEmpty()
返回true,如果這個范圍是形式 [v..v)  或 (v..v].
21 static <C extends Comparable<?>> Range<C> lessThan(C endpoint)
返回一個包含所有值嚴(yán)格小于端點的范圍內(nèi)。
22 BoundType lowerBoundType()
返回類型這個范圍的下限:如果范圍包括它的下端點BoundType.CLOSED,如果沒有BoundType.OPEN。
23 C lowerEndpoint()
返回該范圍的較低端點。
24 static <C extends Comparable<?>> Range<C> open(C lower, C upper)
返回一個包含所有值嚴(yán)格大于下限和嚴(yán)格比上端更小一個范圍。
25 static <C extends Comparable<?>> Range<C> openClosed(C lower, C upper)
返回包含所有值嚴(yán)格低于更大且小于或等于上限的范圍內(nèi)。
26 static <C extends Comparable<?>> Range<C> range(C lower, BoundType lowerType, C upper, BoundType upperType)
返回包含任何值由下到上,每個端點可以是包容性(關(guān)閉)或?qū)S茫ㄩ_)的范圍。
27 static <C extends Comparable<?>> Range<C> singleton(C value)
返回包含只在給定范圍內(nèi)。
28 Range<C> span(Range<C> other)
返回最小的范圍包圍兩者這個范圍和other等。
29 String toString()
返回該范圍內(nèi)的字符串表示,如“[3..5)”(其他實例列在類文檔)。
30 BoundType upperBoundType()
返回類型此范圍的上限:如果范圍包括其上的端點返回BoundType.CLOSED,如果沒有返回BoundType.OPEN。
31 C upperEndpoint()
返回此范圍的上限端點。
32 static <C extends Comparable<?>> Range<C> upTo(C endpoint, BoundType boundType)
返回一個范圍,沒有下限到給定的端點,它可以是包容性(閉合)或?qū)S茫ㄩ_)。

方法繼承

這個類從以下類繼承的方法:

  • java.lang.Object

Range 例子

選擇使用任何編輯器創(chuàng)建以下java程序在 C:/> Guava

GuavaTester.java

import com.google.common.collect.ContiguousSet;
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.Range;
import com.google.common.primitives.Ints;

public class GuavaTester {

   public static void main(String args[]){
      GuavaTester tester = new GuavaTester();
      tester.testRange();
   }

   private void testRange(){

      //create a range [a,b] = { x | a <= x <= b}
      Range<Integer> range1 = Range.closed(0, 9);	
      System.out.print("[0,9] : ");
      printRange(range1);		
      System.out.println("5 is present: " + range1.contains(5));
      System.out.println("(1,2,3) is present: " + range1.containsAll(
            
上一篇:Guava教程下一篇:Guava Longs類