org.apache.lucene.util
Class BytesRef

java.lang.Object
  extended by org.apache.lucene.util.BytesRef
All Implemented Interfaces:
Comparable<BytesRef>

public final class BytesRef
extends Object
implements Comparable<BytesRef>

Represents byte[], as a slice (offset + length) into an existing byte[].

WARNING: This API is experimental and might change in incompatible ways in the next release.

Field Summary
 byte[] bytes
          The contents of the BytesRef.
static byte[] EMPTY_BYTES
           
 int length
          Length of used bytes.
 int offset
          Offset of first valid byte.
 
Constructor Summary
BytesRef()
           
BytesRef(byte[] bytes)
          This instance will directly reference bytes w/o making a copy.
BytesRef(byte[] bytes, int offset, int length)
          This instance will directly reference bytes w/o making a copy.
BytesRef(BytesRef other)
           
BytesRef(char[] text, int offset, int length)
           
BytesRef(CharSequence text)
           
BytesRef(int capacity)
           
 
Method Summary
 void append(BytesRef other)
           
 boolean bytesEquals(BytesRef other)
           
 Object clone()
           
 int compareTo(BytesRef other)
          Unsigned byte order comparison
 void copy(BytesRef other)
           
 void copy(char[] text, int offset, int length)
          Copies the UTF8 bytes for this string.
 void copy(CharSequence text)
          Copies the UTF8 bytes for this string.
 boolean endsWith(BytesRef other)
           
 boolean equals(Object other)
           
static Comparator<BytesRef> getUTF8SortedAsUnicodeComparator()
           
static Comparator<BytesRef> getUTF8SortedAsUTF16Comparator()
           
 void grow(int newLength)
           
 int hashCode()
          Calculates the hash code as required by TermsHash during indexing.
 boolean startsWith(BytesRef other)
           
 String toString()
          Returns hex encoded bytes, eg [0x6c 0x75 0x63 0x65 0x6e 0x65]
 String utf8ToString()
          Interprets stored bytes as UTF8 bytes, returning the resulting string
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EMPTY_BYTES

public static final byte[] EMPTY_BYTES

bytes

public byte[] bytes
The contents of the BytesRef. Should never be null.


offset

public int offset
Offset of first valid byte.


length

public int length
Length of used bytes.

Constructor Detail

BytesRef

public BytesRef()

BytesRef

public BytesRef(byte[] bytes,
                int offset,
                int length)
This instance will directly reference bytes w/o making a copy. bytes should not be null.


BytesRef

public BytesRef(byte[] bytes)
This instance will directly reference bytes w/o making a copy. bytes should not be null


BytesRef

public BytesRef(int capacity)

BytesRef

public BytesRef(CharSequence text)
Parameters:
text - Initialize the byte[] from the UTF8 bytes for the provided Sring. This must be well-formed unicode text, with no unpaired surrogates or U+FFFF.

BytesRef

public BytesRef(char[] text,
                int offset,
                int length)
Parameters:
text - Initialize the byte[] from the UTF8 bytes for the provided array. This must be well-formed unicode text, with no unpaired surrogates or U+FFFF.

BytesRef

public BytesRef(BytesRef other)
Method Detail

copy

public void copy(CharSequence text)
Copies the UTF8 bytes for this string.

Parameters:
text - Must be well-formed unicode text, with no unpaired surrogates or invalid UTF16 code units.

copy

public void copy(char[] text,
                 int offset,
                 int length)
Copies the UTF8 bytes for this string.

Parameters:
text - Must be well-formed unicode text, with no unpaired surrogates or invalid UTF16 code units.

bytesEquals

public boolean bytesEquals(BytesRef other)

clone

public Object clone()
Overrides:
clone in class Object

startsWith

public boolean startsWith(BytesRef other)

endsWith

public boolean endsWith(BytesRef other)

hashCode

public int hashCode()
Calculates the hash code as required by TermsHash during indexing.

It is defined as:

  int hash = 0;
  for (int i = offset; i < offset + length; i++) {
    hash = 31*hash + bytes[i];
  }
 

Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object

utf8ToString

public String utf8ToString()
Interprets stored bytes as UTF8 bytes, returning the resulting string


toString

public String toString()
Returns hex encoded bytes, eg [0x6c 0x75 0x63 0x65 0x6e 0x65]

Overrides:
toString in class Object

copy

public void copy(BytesRef other)

append

public void append(BytesRef other)

grow

public void grow(int newLength)

compareTo

public int compareTo(BytesRef other)
Unsigned byte order comparison

Specified by:
compareTo in interface Comparable<BytesRef>

getUTF8SortedAsUnicodeComparator

public static Comparator<BytesRef> getUTF8SortedAsUnicodeComparator()

getUTF8SortedAsUTF16Comparator

public static Comparator<BytesRef> getUTF8SortedAsUTF16Comparator()


Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.