Package convex.core.data
Class StringShort
- All Implemented Interfaces:
IValidated
,IWriteable
,CharSequence
,Comparable<AString>
Class representing a short CVM string.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
Length of longest StringShort value that is embedded in chars Just long enough for a 64-char hex string with 0x and 2 delimiters.static int
Length of longest StringShort value in charsFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected AString
append(char charValue)
protected void
appendToStringBuffer(StringBuilder sb, int start, int length)
char
charAt(int index)
int
static StringShort
Creates a StringShort instance from a regular Java Stringint
encodeRaw(byte[] bs, int pos)
Writes this Cell's encoding to a byte array, excluding the tag byteboolean
Checks for equality with another object.boolean
equals(StringShort a)
int
Estimate the encoded data size for this Cell.int
Gets the number of Refs contained within this Cell.int
hashCode()
Gets the Java hashCode for this cell.boolean
Returns true if this Cell is in a canonical format for message writing.boolean
Returns true if this object represents a first class CVM Value.boolean
Determines if this Cell Represents an embedded object.static AString
read(int length, ByteBuffer bb)
Read a StringShort from a ByteBuffer.subSequence(int start, int end)
Converts this Cell to its canonical version.toString()
Returns the String representation of this Cell.void
Validates the local structure and invariants of this cell.Methods inherited from class convex.core.data.AString
count, empty, encode, get, getElementRef, getTag, getType, length, print
Methods inherited from class convex.core.data.ACountable
isEmpty, size
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, updateRefs, validate, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
Field Details
-
MAX_EMBEDDED_STRING_LENGTH
public static final int MAX_EMBEDDED_STRING_LENGTHLength of longest StringShort value that is embedded in chars Just long enough for a 64-char hex string with 0x and 2 delimiters. If that helps.- See Also:
- Constant Field Values
-
MAX_LENGTH
public static final int MAX_LENGTHLength of longest StringShort value in chars- See Also:
- Constant Field Values
-
-
Constructor Details
-
StringShort
-
-
Method Details
-
create
Creates a StringShort instance from a regular Java String- Parameters:
string
- String to wrap as StringShort- Returns:
- StringShort instance, or null if String is of invalid size
-
charAt
public char charAt(int index) -
subSequence
- Specified by:
subSequence
in interfaceCharSequence
- Specified by:
subSequence
in classAString
-
validateCell
Description copied from class:ACell
Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.- Specified by:
validateCell
in classACell
- Throws:
InvalidDataException
- If the Cell is invalid
-
encodeRaw
public int encodeRaw(byte[] bs, int pos)Description copied from class:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte -
estimatedEncodingSize
public int estimatedEncodingSize()Description copied from interface:IWriteable
Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.- Returns:
- The estimated size for the binary representation of this object.
-
isCanonical
public boolean isCanonical()Description copied from class:ACell
Returns true if this Cell is in a canonical format for message writing. Reading or writing a non-canonical value should be considered illegal, but non-canonical objects may be used on a temporary internal basis.- Specified by:
isCanonical
in classACell
- Returns:
- true if the object is in canonical format, false otherwise
-
isCVMValue
public final boolean isCVMValue()Description copied from class:ACell
Returns true if this object represents a first class CVM Value. Sub-structural cells that are not themselves first class values should return false. CVM values might not be in a canonical format, e.g. temporary data structures- Specified by:
isCVMValue
in classACell
- Returns:
- true if the object is a CVM Value, false otherwise
-
isEmbedded
public boolean isEmbedded()Description copied from class:ACell
Determines if this Cell Represents an embedded object. Embedded objects are encoded directly into the encoding of the containing Cell (avoiding the need for a hashed reference). Subclasses should override this if they have a cheap O(1) way to determine if they are embedded or otherwise.- Overrides:
isEmbedded
in classACell
- Returns:
- true if Cell is embedded, false otherwise
-
getRefCount
public int getRefCount()Description copied from class:ACell
Gets the number of Refs contained within this Cell. This number is final / immutable for any given instance. Contained Refs may be either external or embedded.- Specified by:
getRefCount
in classACell
- Returns:
- The number of Refs in this Cell
-
read
Read a StringShort from a ByteBuffer. Assumes tag and length already read and correct.- Parameters:
length
- Length in number of chars to readbb
- ByteBuffer to read from- Returns:
- AString instance
-
toString
Description copied from class:ACell
Returns the String representation of this Cell. The String representation is intended to be a easy-to-read textual representation of the Cell's data content.- Specified by:
toString
in interfaceCharSequence
- Overrides:
toString
in classAString
-
hashCode
public int hashCode()Description copied from class:ACell
Gets the Java hashCode for this cell. Must be consistent with equals. Default is the first bytes (big-endian) of the Cell Encoding's hash, since this is consistent with encoding-based equality. However, different Types may provide more efficient hashcodes provided that the usual invariants are preserved -
equals
Description copied from class:ACell
Checks for equality with another object. In general, data objects should be considered equal if they have the same canonical representation, i.e. an identical encoding with the same hash value. Subclasses should override this if they have a more efficient equals implementation. -
equals
-
compareTo
- Specified by:
compareTo
in interfaceComparable<AString>
- Overrides:
compareTo
in classAString
-
appendToStringBuffer
- Specified by:
appendToStringBuffer
in classAString
-
append
-
toCanonical
Description copied from class:ACell
Converts this Cell to its canonical version. Returns this if already canonical- Specified by:
toCanonical
in classACell
- Returns:
- Canonical version of Cell
-