com.sun.portal.search.soif
Class AVPair

java.lang.Object
  |
  +--com.sun.portal.search.soif.AVPair

public class AVPair
extends Object

AVPair - a class used to represent a SOIF attribute-value pair.

SOIF AVPairs may be text or binary. Other types should be encoded by convention.
SOIF AVPairs may be multivalued.

This implementation will save data as either strings or byte arrays. If data is saved as a byte array, but requested as a string, an implicit conversion from binary to text is performed using the current character encoding. A conversion is also performed when an attribute is written in one encoding, but read in another.

NB: byte array entries are stored by reference and shared with caller. String entries are never shared.

See Also:
SOIF

Field Summary
 String attribute
          Attribute name.
 com.sun.portal.search.soif.AVPair.AVValue[] value
          Attribute value.
 
Constructor Summary
AVPair(String att)
          Constructs an empty, named AVPair instance
AVPair(String att, byte[] bval)
          Constructs a new AVPairs instance with a byte array value.
AVPair(String att, byte[] bval, int index)
          Constructs an AVPair consisting of a byte array value with the given index.
AVPair(String att, byte[] bval, int index, String encoding)
          Constructs an AVPair consisting of a String value with the given index and encoding.
AVPair(String att, String val)
          Constructs a new AVPairs instance with a String value.
AVPair(String att, String val, int index)
          Constructs an AVPair consisting of a String value with the given index.
 
Method Summary
 int contentSize()
           
 String getAttribute()
           
 byte[] getBytes()
           
 byte[] getBytes(int i)
           
 byte[][] getByteValues()
          Gets all valid values of this attribute.
 int getMaxIndex()
           
 String[] getStringValues()
          Gets all valid values of this attribute.
 String getValue()
           
 String getValue(int i)
           
 boolean insert(byte[] b, int index)
          Inserts a byte array at the given index, no duplicates.
 boolean insert(String v, int index)
          Inserts a String at the given index, no duplicates.
 boolean isMV()
           
 boolean nthValid(int n)
           
 boolean remove(int index)
          Removes a mutivalued entry by index.
 boolean replace(byte[] b, int index)
          Replaces the byte array at the given index.
 boolean replace(String v, int index)
          Replaces the string at the given index.
 void setAttribute(String s)
          (Re)names an AVPair.
 int size()
           
 void squeeze()
          Packs the index array by closing all holes towards the index zero.
 String toString()
           
 int valueCount()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

attribute

public String attribute
Attribute name. Multivalued attr bob-1, bob-2, bob-4 have the name bob. Case is preserved, although SOIF lookups are case insensitive.

value

public com.sun.portal.search.soif.AVPair.AVValue[] value
Attribute value. Can be binary (assumed when reading from stream) For internal use, directly supports String values for efficiency.
Constructor Detail

AVPair

public AVPair(String att)
Constructs an empty, named AVPair instance
Parameters:
att - the attribute

AVPair

public AVPair(String att,
              String val)
Constructs a new AVPairs instance with a String value.
Parameters:
att - the attribute
val - the value

AVPair

public AVPair(String att,
              byte[] bval)
Constructs a new AVPairs instance with a byte array value.
Parameters:
att - the attribute
val - the value

AVPair

public AVPair(String att,
              String val,
              int index)
Constructs an AVPair consisting of a String value with the given index.

AVPair

public AVPair(String att,
              byte[] bval,
              int index)
Constructs an AVPair consisting of a byte array value with the given index.

AVPair

public AVPair(String att,
              byte[] bval,
              int index,
              String encoding)
Constructs an AVPair consisting of a String value with the given index and encoding.
Method Detail

insert

public boolean insert(String v,
                      int index)
Inserts a String at the given index, no duplicates.
Returns:
false if slot already taken

insert

public boolean insert(byte[] b,
                      int index)
Inserts a byte array at the given index, no duplicates.
Returns:
false if slot already taken

replace

public boolean replace(String v,
                       int index)
Replaces the string at the given index.
Returns:
false if slot already taken

replace

public boolean replace(byte[] b,
                       int index)
Replaces the byte array at the given index.
Returns:
false if slot already taken

remove

public boolean remove(int index)
Removes a mutivalued entry by index.
Returns:
false if index was not occupied

squeeze

public void squeeze()
Packs the index array by closing all holes towards the index zero.

getAttribute

public String getAttribute()
Returns:
the attribute name for this AVPair.

setAttribute

public void setAttribute(String s)
(Re)names an AVPair.

getValue

public String getValue()
Returns:
the value of this AVPair (uses the first occupied slot if multivalued)

getBytes

public byte[] getBytes()
Returns:
the value of this AVPair (uses the first occupied slot if multivalued)

getValue

public String getValue(int i)
Parameters:
i - multivalue index
Returns:
String value at index i

getBytes

public byte[] getBytes(int i)
Parameters:
i - multivalue index
Returns:
byte array value at index i

valueCount

public int valueCount()
Returns:
the number of non-null values for this attribute.

getMaxIndex

public int getMaxIndex()
Returns:
the maximum occupied index.

size

public int size()
Returns:
the total size - some values may be null

getStringValues

public String[] getStringValues()
Gets all valid values of this attribute.
Returns:
an array of Strings for multiple values for an attribute, e.g., for Bob, return values for Bob-1 and Bob-2.

getByteValues

public byte[][] getByteValues()
Gets all valid values of this attribute.
Returns:
an array of byte arrays for multiple values for an attribute, e.g., for image, return values for image-1 and image-2.

nthValid

public boolean nthValid(int n)
Returns:
true if the value at index n exists and is non-null

contentSize

public int contentSize()
Returns:
size of AVPair contents in bytes

isMV

public boolean isMV()
Returns:
true if APVair is multivalued

toString

public String toString()
Overrides:
toString in class Object
Returns:
a String representation of this AVPair - mainly for debugging