Package convex.core.data
Class Keyword
java.lang.Object
convex.core.data.AObject
convex.core.data.ACell
convex.core.data.ASymbolic
convex.core.data.Keyword
- All Implemented Interfaces:
IValidated
,IWriteable
,Comparable<Keyword>
Keyword data type. Intended as human-readable map keys, tags and option
specifiers etc.
Keywords evaluate to themselves, and as such can be considered as literal
constants.
"Programs must be written for people to read, and only incidentally for
machines to execute." ― Harold Abelson
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
Maximum size of a Keyword in UTF-16 chars representationstatic int
Minimum size of a Keyword in UTF-16 chars representationFields inherited from class convex.core.data.ACell
cachedRef, EMPTY_ARRAY
-
Method Summary
Modifier and TypeMethodDescriptionint
static Keyword
static Keyword
Creates a Keyword with the given namestatic Keyword
createChecked(AString aString)
Creates a Keyword with the given name, throwing an exception if name is not validstatic Keyword
createChecked(String aString)
int
encode(byte[] bs, int pos)
Writes this Cell's encoding to a byte array, including a tag byte which will be written firstint
encodeRaw(byte[] bs, int pos)
Writes this Cell's encoding to a byte array, excluding the tag byteboolean
Checks for equality with another object.int
Estimate the encoded data size for this Cell.int
Gets the number of Refs contained within this Cell.byte
getTag()
Gets the tag byte for this cell.getType()
Gets the most specific known runtime Type for this Cell.boolean
Returns true if this Cell is in a canonical format for message writing.void
print(StringBuilder sb)
Prints this Object to a readable String Representationstatic Keyword
read(ByteBuffer bb)
Reads a Keyword from the given ByteBuffer, assuming tag already consumedConverts this Cell to its canonical version.void
Validates the name of this Symbolic valueMethods inherited from class convex.core.data.ASymbolic
calcMemorySize, createRef, getName, hashCode, isCVMValue, isEmbedded, validateName
Methods inherited from class convex.core.data.ACell
announce, announce, attachMemorySize, attachRef, cachedEncoding, cachedHash, createAnnounced, createEncoding, createPersisted, createPersisted, equals, getChildRefs, getEncoding, getEncodingLength, getHash, getMemorySize, getRef, getRef, toString, updateRefs, validate, write
Methods inherited from class convex.core.data.AObject
attachEncoding, print
-
Field Details
-
MAX_CHARS
public static final int MAX_CHARSMaximum size of a Keyword in UTF-16 chars representation- See Also:
- Constant Field Values
-
MIN_CHARS
public static final int MIN_CHARSMinimum size of a Keyword in UTF-16 chars representation- See Also:
- Constant Field Values
-
-
Method Details
-
getType
Description copied from class:ACell
Gets the most specific known runtime Type for this Cell. -
create
Creates a Keyword with the given name- Parameters:
name
- A String to use as the keyword name- Returns:
- The new Keyword, or null if the name is invalid for a Keyword
-
create
-
createChecked
Creates a Keyword with the given name, throwing an exception if name is not valid- Parameters:
aString
- A String of at least 1 and no more than 64 UTF-8 bytes in length- Returns:
- The new Keyword
-
createChecked
-
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
-
read
Reads a Keyword from the given ByteBuffer, assuming tag already consumed- Parameters:
bb
- ByteBuffer source- Returns:
- The Keyword read
- Throws:
BadFormatException
- If a Keyword could not be read correctly
-
encode
public int encode(byte[] bs, int pos)Description copied from class:ACell
Writes this Cell's encoding to a byte array, including a tag byte which will be written first- Specified by:
encode
in interfaceIWriteable
- Specified by:
encode
in 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 int encodeRaw(byte[] bs, int pos)Description copied from class:ACell
Writes this Cell's encoding to a byte array, excluding the tag byte -
print
Description copied from class:AObject
Prints this Object to a readable String Representation -
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.- Specified by:
estimatedEncodingSize
in interfaceIWriteable
- Returns:
- The estimated size for the binary representation of this object.
-
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. -
compareTo
- Specified by:
compareTo
in interfaceComparable<Keyword>
-
validateCell
Description copied from class:ASymbolic
Validates the name of this Symbolic value- Overrides:
validateCell
in classASymbolic
- Throws:
InvalidDataException
- If the Cell is invalid
-
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
-
getTag
public byte getTag()Description copied from class:ACell
Gets the tag byte for this cell. The tag byte will be the first byte of the encoding -
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
-