Package convex.core.data
Class AString
- All Implemented Interfaces:
IValidated,IWriteable,Comparable<AString>
- Direct Known Subclasses:
StringShort,StringSlice,StringTree
Class representing a CVM String
-
Field Summary
FieldsFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAppend a CVM String to this CVM String.Convenience method to add a Java String to a CVM String.abstract bytebyteAt(long i)Gets a byte at the specified index.abstract intcharAt(long i)Gets the Unicode character at position i, or -1 if not validabstract intlongcount()Returns the number of elements in this data structureempty()intencode(byte[] bs, int pos)Writes this Cell's encoding to a byte array, including a tag byte which will be written first.abstract intencodeRaw(byte[] bs, int pos)Encode the data of this String.abstract intencodeRawData(byte[] bs, int pos)Encode the raw UTF-8 data of this String.get(long i)Gets the element at the specified index in this collectiongetElementRef(long i)Gets a Ref to the element at the specified index in this collectionbytegetTag()Gets the tag byte for this cell.getType()Gets the most specific known runtime Type for this Cell.inthashCode()Gets a Java hashCode for this CVM String.intintAt(long index)Gets 32 bytes integer at given position.booleanprint(BlobBuilder sb, long limit)Prints this Object to a readable String Representationabstract AStringsubSequence(long start, long end)abstract ABlobtoBlob()Converts this String to a Blob byte representation.toCVMString(long limit)Returns the CVM String representation of this Cell.toString()Returns the Java String representation of this Cell.protected abstract voidwriteToBuffer(ByteBuffer bb)Methods inherited from class convex.core.data.ACountable
isEmpty, sizeMethods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, calcMemorySize, createAnnounced, createEncoding, createPersisted, createPersisted, createRef, equals, equals, getCanonical, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, getRefCount, isCanonical, isCompletelyEncoded, isCVMValue, isEmbedded, mark, mark, toCanonical, updateRefs, validate, validateCell, writeMethods inherited from class convex.core.data.AObject
attachEncoding, print, printMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface convex.core.data.IWriteable
estimatedEncodingSize
-
Field Details
-
length
protected long length
-
-
Constructor Details
-
AString
protected AString(long length)
-
-
Method Details
-
getType
Description copied from class:ACellGets the most specific known runtime Type for this Cell. -
print
Description copied from class:AObjectPrints this Object to a readable String Representation -
count
public long count()Description copied from class:ACountableReturns the number of elements in this data structure- Specified by:
countin classACountable<CVMChar>- Returns:
- Number of elements in this collection.
-
empty
-
charAt
public abstract int charAt(long i)Gets the Unicode character at position i, or -1 if not valid- Parameters:
i- Index into String (byte position)- Returns:
- Unicode code point, or -1 if not a valid code point at this position
-
intAt
public int intAt(long index)Gets 32 bytes integer at given position. Extends with 255 (invalid UTF-8) if needed- Parameters:
index- Index into String (byte position)- Returns:
- Raw integer value
-
byteAt
public abstract byte byteAt(long i)Gets a byte at the specified index. Returns -1 (0xff) if outside String.- Parameters:
i- Index into String (byte position)- Returns:
- Raw byte value
-
get
Description copied from class:ACountableGets the element at the specified index in this collection- Specified by:
getin classACountable<CVMChar>- Parameters:
i- Index of element to get- Returns:
- Element at the specified index
-
getElementRef
Description copied from class:ACountableGets a Ref to the element at the specified index in this collection- Specified by:
getElementRefin classACountable<CVMChar>- Parameters:
i- Index of element to get- Returns:
- Element at the specified index
-
compareTo
- Specified by:
compareToin interfaceComparable<AString>
-
toString
Description copied from class:ACellReturns the Java String representation of this Cell. The String representation is intended to be a easy-to-read textual representation of the Cell's data content. -
toCVMString
Description copied from class:ACellReturns the CVM String representation of this Cell. Normally, this is as printed, but may be different for some types. MUST return null in O(1) time if the length of the CVM String would exceed limit. The String representation is intended to be a easy-to-read textual representation of the Cell's data content.- Overrides:
toCVMStringin classACell- Parameters:
limit- Limit of CVM String length in UTF-8 bytes- Returns:
- CVM String, or null if limit exceeded by too much
-
append
Append a CVM String to this CVM String. Potentially O(n). Concatenates raw UTF-8 bytes.- Parameters:
b- String to append- Returns:
- Concatenated String
-
writeToBuffer
-
subSequence
-
encode
public int encode(byte[] bs, int pos)Description copied from class:ACellWrites this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.- Specified by:
encodein interfaceIWriteable- Specified by:
encodein classACell- Parameters:
bs- A byte array to which to write the encodingpos- The offset into the byte array- Returns:
- New position after writing
-
encodeRaw
public abstract int encodeRaw(byte[] bs, int pos)Encode the data of this String. Assumes tag already written -
encodeRawData
public abstract int encodeRawData(byte[] bs, int pos)Encode the raw UTF-8 data of this String. Assumes tag/length already written- Parameters:
bs- Byte array to encode topos- Position in target array to write to- Returns:
- End position in array after encoding
-
getTag
public final byte getTag()Description copied from class:ACellGets the tag byte for this cell. The tag byte is always written as the first byte of the Cell's Encoding -
hashCode
public final int hashCode()Gets a Java hashCode for this CVM String. Use the hashcode of underlying Blob -
toBlob
Converts this String to a Blob byte representation. Must round trip all values.- Returns:
- Blob representation of UTF-8 String
-
append
Convenience method to add a Java String to a CVM String. Not particularly efficient.- Parameters:
string- String to append- Returns:
- CVM String
-