Class Value

All Implemented Interfaces:
Comparable<Item>, Iterable<Item>, Debug, Display
Direct Known Subclasses:
Absent, Bool, Data, Expression, Extant, Num, Record, Text

public abstract class Value extends Item
  • Method Details

    • isDefined

      public boolean isDefined()
      Returns true if this Value is not Absent.
      Specified by:
      isDefined in class Item
    • isDistinct

      public boolean isDistinct()
      Returns true if this Value is neither Extant nor Absent.
      Specified by:
      isDistinct in class Item
    • isDefinite

      public boolean isDefinite()
      Returns true if this Value is not one of: an empty Record, False, Extant, or Absent.
      Specified by:
      isDefinite in class Item
    • key

      public final Value key()
      Always returns Absent because a Value can't be a Field, so it can't have a key component.
      Specified by:
      key in class Item
    • toValue

      public final Value toValue()
      Always returns this because every Value is its own value component.
      Specified by:
      toValue in class Item
    • tag

      public String tag()
      Returns the key string of the first member of this Value, if this Value is a Record, and its first member is an Attr; otherwise returns null if this Value is not a Record, or if this Value is a Record whose first member is not an Attr.

      Used to concisely get the name of the discriminating attribute of a structure. The tag can be used to discern the nominal type of a polymorphic structure, similar to an XML element tag.

      Specified by:
      tag in class Item
    • target

      public Value target()
      Returns the flattened members of this Value after all attributes have been removed, if this Value is a Record; otherwise returns this if this Value is not a Record.

      Used to concisely get the scalar value of an attributed structure. An attributed structure is a Record with one or more attributes that modify one or more other members.

      Specified by:
      target in class Item
    • flattened

      public Value flattened()
      Returns the sole member of this Value, if this Value is a Record with exactly one member, and its member is a Value; returns Extant if this Value is an empty Record; otherwise returns this if this Value is a Record with more than one member, or if this Value is not a Record.

      Used to convert a unary Record into its member Value. Facilitates writing code that treats a unary Record equivalently to a bare Value.

      Specified by:
      flattened in class Item
    • unflattened

      public Record unflattened()
      Returns this if this Value is a Record; returns a Record containing just this Value, if this Value is distinct; otherwise returns an empty Record if this Value is Extant or Absent. Facilitates writing code that treats a bare Value equivalently to a unary Record.
      Specified by:
      unflattened in class Item
    • header

      public Value header(String tag)
      Returns the value of the first member of this Value, if this Value is a Record, and its first member is an Attr whose key string is equal to tag; otherwise returns Absent if this Value is not a Record, or if this Value is a Record whose first member is not an Attr, or if this Value is a Record whose first member is an Attr whose key does not equal the tag.

      Used to conditionally get the value of the head Attr of a structure, if and only if the key string of the head Attr is equal to the tag. Can be used to check if a structure might conform to a nominal type named tag, while simultaneously getting the value of the tag attribute.

      Specified by:
      header in class Item
    • headers

      public Record headers(String tag)
      Returns the unflattened header of this Value, if this Value is a Record, and its first member is an Attr whose key string is equal to tag; otherwise returns null.

      The headers of the tag attribute of a structure are like the attributes of an XML element tag; through unlike an XML element, tag attribute headers are not limited to string keys and values.

      Specified by:
      headers in class Item
    • head

      public Item head()
      Returns the first member of this Value, if this Value is a non-empty Record; otherwise returns Absent.
      Specified by:
      head in class Item
    • tail

      public Record tail()
      Returns a view of all but the first member of this Value, if this Value is a non-empty Record; otherwise returns an empty Record if this Value is not a Record, of if this Value is itself an empty Record.
      Specified by:
      tail in class Item
    • body

      public Value body()
      Returns the flattened tail of this Value. Used to recursively deconstruct a structure, terminating with its last Value, rather than a unary Record containing its last value, if the structure ends with a Value member.
      Specified by:
      body in class Item
    • length

      public int length()
      Returns the number of members contained in this Value, if this Value is a Record; otherwise returns 0 if this Value is not a Record.
      Specified by:
      length in class Item
    • contains

      public boolean contains(Item item)
      Returns true if this Value is a Record that has a member equal to item; otherwise returns false if this Value is not a Record, or if this Value is a Record, but has no member equal to item.
      Specified by:
      contains in class Item
    • containsKey

      public boolean containsKey(Value key)
      Returns true if this Value is a Record that has a Field member with a key that is equal to the given key; otherwise returns false if this Value is not a Record, or if this Value is a Record, but has no Field member with a key equal to the given key.
      Specified by:
      containsKey in class Item
    • containsKey

      public boolean containsKey(String key)
      Returns true if this Value is a Record that has a Field with a Text key whose string value is equal to the given key; otherwise returns false if this Value is not a Record, or if this Value is a Record, but has no Field member with a Text key whose string value equals the given key. Equivalent to containsKey(Value), but avoids boxing the key string into a Text value.
      Specified by:
      containsKey in class Item
    • containsValue

      public boolean containsValue(Value value)
      Returns true if this Value is a Record that has a Field member with a value that is equal to the given value; otherwise returns false if this Value is not a Record, or if this Value is a Record, but has no Field member with a value equal to the given value.
      Specified by:
      containsValue in class Item
    • get

      public Value get(Value key)
      Returns the value of the last Field member of this Value whose key is equal to the given key; returns Absent if this Value is not a Record, or if this Value is a Record, but has no Field member with a key equal to the given key.
      Specified by:
      get in class Item
    • get

      public Value get(String key)
      Returns the value of the last Field member of this Value with a Text key whose string value is equal to the given key; returns Absent if this Value is not a Record, or if this Value is a Record, but has no Field member with a Text key whose string value equals the given key. Equivalent to get(Value), but avoids boxing the key string into a Text value.
      Specified by:
      get in class Item
    • getAttr

      public Value getAttr(Text key)
      Returns the value of the last Attr member of this Value whose key is equal to the given key; returns Absent if this Value is not a Record, or if this Value is a Record, but has no Attr member with a key equal to the given key.
      Specified by:
      getAttr in class Item
    • getAttr

      public Value getAttr(String key)
      Returns the value of the last Attr member of this Value with a Text key whose string value is equal to the given key; returns Absent if this Value is not a Record, or if this Value is a Record, but has no Attr member with a Text key whose string value equals the given key. Equivalent to getAttr(Text), but avoids boxing the key string into a Text value.
      Specified by:
      getAttr in class Item
    • getSlot

      public Value getSlot(Value key)
      Returns the value of the last Slot member of this Value whose key is equal to the given key; returns Absent if this Value is not a Record, or if this Value is a Record, but has no Slot member with a key equal to the given key.
      Specified by:
      getSlot in class Item
    • getSlot

      public Value getSlot(String key)
      Returns the value of the last Slot member of this Value with a Text key whose string value is equal to the given key; returns Absent if this Value is not a Record, or if this Value is a Record, but has no Slot member with a Text key whose string value equals the given key. Equivalent to getSlot(Value), but avoids boxing the key string into a Text value.
      Specified by:
      getSlot in class Item
    • getField

      public Field getField(Value key)
      Returns the last Field member of this Value whose key is equal to the given key; returns null if this Value is not a Record, or if this Value is a Record, but has no Field member with a key equal to the given key.
      Specified by:
      getField in class Item
    • getField

      public Field getField(String key)
      Returns the last Field member of this Value with a Text key whose string value is equal to the given key; returns null if this Value is not a Record, or if this Value is a Record, but has no Field member with a Text key whose string value equals the given key. Equivalent to getField(Value), but avoids boxing the key string into a Text value.
      Specified by:
      getField in class Item
    • getItem

      public Item getItem(int index)
      Returns the member of this Value at the given index, if this Value is a Record, and the index is greater than or equal to zero, and less than the length of the Record; otherwise returns Absent if this Value is not a Record, or if this Value is a Record, but the index is out of bounds.
      Specified by:
      getItem in class Item
    • removed

      public Value removed(Value key)
      Specified by:
      removed in class Item
    • removed

      public Value removed(String key)
      Specified by:
      removed in class Item
    • conditional

      public Item conditional(Item thenTerm, Item elseTerm)
      Specified by:
      conditional in class Item
    • conditional

      public Value conditional(Value thenTerm, Value elseTerm)
    • or

      public Item or(Item that)
      Specified by:
      or in class Item
    • or

      public Value or(Value that)
    • and

      public Item and(Item that)
      Specified by:
      and in class Item
    • and

      public Value and(Value that)
    • bitwiseOr

      public Item bitwiseOr(Item that)
      Specified by:
      bitwiseOr in class Item
    • bitwiseOr

      public Value bitwiseOr(Value that)
    • bitwiseXor

      public Item bitwiseXor(Item that)
      Specified by:
      bitwiseXor in class Item
    • bitwiseXor

      public Value bitwiseXor(Value that)
    • bitwiseAnd

      public Item bitwiseAnd(Item that)
      Specified by:
      bitwiseAnd in class Item
    • bitwiseAnd

      public Value bitwiseAnd(Value that)
    • lt

      public Item lt(Item that)
      Overrides:
      lt in class Item
    • lt

      public Value lt(Value that)
    • le

      public Item le(Item that)
      Overrides:
      le in class Item
    • le

      public Value le(Value that)
    • eq

      public Item eq(Item that)
      Overrides:
      eq in class Item
    • eq

      public Value eq(Value that)
    • ne

      public Item ne(Item that)
      Overrides:
      ne in class Item
    • ne

      public Value ne(Value that)
    • ge

      public Item ge(Item that)
      Overrides:
      ge in class Item
    • ge

      public Value ge(Value that)
    • gt

      public Item gt(Item that)
      Overrides:
      gt in class Item
    • gt

      public Value gt(Value that)
    • plus

      public Item plus(Item that)
      Specified by:
      plus in class Item
    • plus

      public Value plus(Value that)
    • minus

      public Item minus(Item that)
      Specified by:
      minus in class Item
    • minus

      public Value minus(Value that)
    • times

      public Item times(Item that)
      Specified by:
      times in class Item
    • times

      public Value times(Value that)
    • divide

      public Item divide(Item that)
      Specified by:
      divide in class Item
    • divide

      public Value divide(Value that)
    • modulo

      public Item modulo(Item that)
      Specified by:
      modulo in class Item
    • modulo

      public Value modulo(Value that)
    • not

      public Value not()
      Specified by:
      not in class Item
    • bitwiseNot

      public Value bitwiseNot()
      Specified by:
      bitwiseNot in class Item
    • negative

      public Value negative()
      Specified by:
      negative in class Item
    • positive

      public Value positive()
      Specified by:
      positive in class Item
    • inverse

      public Value inverse()
      Specified by:
      inverse in class Item
    • lambda

      public Value lambda(Value template)
      Specified by:
      lambda in class Item
    • stringValue

      public String stringValue()
      Converts this Value into a String value, if possible.
      Specified by:
      stringValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a String value.
    • stringValue

      public String stringValue(String orElse)
      Converts this Value into a String value, if possible; otherwise returns orElse if this Value can't be converted into a string value.
      Specified by:
      stringValue in class Item
    • byteValue

      public byte byteValue()
      Converts this Value into a primitive byte value, if possible.
      Specified by:
      byteValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a primitive byte value.
    • byteValue

      public byte byteValue(byte orElse)
      Converts this Value into a primitive byte value, if possible; otherwise returns orElse if this Value can't be converted into a primitive byte value.
      Specified by:
      byteValue in class Item
    • shortValue

      public short shortValue()
      Converts this Value into a primitive short value, if possible.
      Specified by:
      shortValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a primitive short value.
    • shortValue

      public short shortValue(short orElse)
      Converts this Value into a primitive short value, if possible; otherwise returns orElse if this Value can't be converted into a primitive short value.
      Specified by:
      shortValue in class Item
    • intValue

      public int intValue()
      Converts this Value into a primitive int value, if possible.
      Specified by:
      intValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a primitive int value.
    • intValue

      public int intValue(int orElse)
      Converts this Value into a primitive int value, if possible; otherwise returns orElse if this Value can't be converted into a primitive int value.
      Specified by:
      intValue in class Item
    • longValue

      public long longValue()
      Converts this Value into a primitive long value, if possible.
      Specified by:
      longValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a primitive long value.
    • longValue

      public long longValue(long orElse)
      Converts this Value into a primitive long value, if possible; otherwise returns orElse if this Value can't be converted into a primitive long value.
      Specified by:
      longValue in class Item
    • floatValue

      public float floatValue()
      Converts this Value into a primitive float value, if possible.
      Specified by:
      floatValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a primitive float value.
    • floatValue

      public float floatValue(float orElse)
      Converts this Value into a primitive float value, if possible; otherwise returns orElse if this Value can't be converted into a primitive float value.
      Specified by:
      floatValue in class Item
    • doubleValue

      public double doubleValue()
      Converts this Value into a primitive double value, if possible.
      Specified by:
      doubleValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a primitive double value.
    • doubleValue

      public double doubleValue(double orElse)
      Converts this Value into a primitive double value, if possible; otherwise returns orElse if this Value can't be converted into a primitive double value.
      Specified by:
      doubleValue in class Item
    • integerValue

      public BigInteger integerValue()
      Converts this Value into a BigInteger value, if possible.
      Specified by:
      integerValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a BigInteger value.
    • integerValue

      public BigInteger integerValue(BigInteger orElse)
      Converts this Value into a BigInteger value, if possible; otherwise returns orElse if this Value can't be converted into a BigInteger value.
      Specified by:
      integerValue in class Item
    • numberValue

      public Number numberValue()
      Converts this Value into a Number object, if possible.
      Specified by:
      numberValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a Number object.
    • numberValue

      public Number numberValue(Number orElse)
      Converts this Value into a Number object, if possible; otherwise returns orElse if this Value can't be converted into a Number object.
      Specified by:
      numberValue in class Item
    • charValue

      public char charValue()
      Converts this Value into a primitive char value, if possible.
      Specified by:
      charValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a primitive char value.
    • charValue

      public char charValue(char orElse)
      Converts this Value into a primitive char value, if possible; otherwise returns orElse if this Value can't be converted into a primitive char value.
      Specified by:
      charValue in class Item
    • booleanValue

      public boolean booleanValue()
      Converts this Value into a primitive boolean value, if possible.
      Specified by:
      booleanValue in class Item
      Throws:
      UnsupportedOperationException - if this Value can't be converted into a primitive boolean value.
    • booleanValue

      public boolean booleanValue(boolean orElse)
      Converts this Value into a primitive boolean value, if possible; otherwise returns orElse if this Value can't be converted into a primitive boolean value.
      Specified by:
      booleanValue in class Item
    • isAliased

      public boolean isAliased()
      Specified by:
      isAliased in class Item
    • isMutable

      public boolean isMutable()
      Specified by:
      isMutable in class Item
    • alias

      public void alias()
      Specified by:
      alias in class Item
    • branch

      public Value branch()
      Specified by:
      branch in class Item
    • commit

      public Value commit()
      Description copied from class: Item
      Flags this Item as immutable, recursively if it is a Record, then returns this Item.
      Specified by:
      commit in class Item
    • keyEquals

      public boolean keyEquals(Object key)
      Specified by:
      keyEquals in class Item
    • builder

      public static Builder<Item,Value> builder()
    • empty

      public static Value empty()
    • extant

      public static Value extant()
    • absent

      public static Value absent()
    • fromObject

      public static Value fromObject(Object object)