Class Record

All Implemented Interfaces:
Comparable<Item>, Iterable<Item>, Collection<Item>, List<Item>, Debug, Display, Builder<Item,Record>, PairBuilder<Value,Value,Record>
Direct Known Subclasses:
AbstractRecordOutlet, RecordStreamlet

public abstract class Record extends Value implements List<Item>, Builder<Item,Record>, PairBuilder<Value,Value,Record>
  • Constructor Details

    • Record

      public Record()
  • Method Details

    • isDefinite

      public boolean isDefinite()
      Description copied from class: Value
      Returns true if this Value is not one of: an empty Record, False, Extant, or Absent.
      Overrides:
      isDefinite in class Value
    • isEmpty

      public abstract boolean isEmpty()
      Returns true if this Record has no members.
      Specified by:
      isEmpty in interface Collection<Item>
      Specified by:
      isEmpty in interface List<Item>
    • isArray

      public boolean isArray()
      Returns true if this Record has only Value members–no Field members.
    • isObject

      public boolean isObject()
      Returns true if this Record has only Field members–no Value members.
    • size

      public abstract int size()
      Returns the number of members contained in this Record.
      Specified by:
      size in interface Collection<Item>
      Specified by:
      size in interface List<Item>
    • length

      public final int length()
      Returns the number of members contained in this Record; equivalent to size().
      Overrides:
      length in class Value
    • fieldCount

      public int fieldCount()
      Returns the number of Field members contained in this Record.
    • valueCount

      public int valueCount()
      Returns the number of Value members contained in this Record.
    • isConstant

      public boolean isConstant()
      Description copied from class: Item
      Returns true if this Item always evaluates to the same Item.
      Specified by:
      isConstant in class Item
    • tag

      public String tag()
      Returns the key string of the first member of this Record, if the first member is an Attr; otherwise returns null if the 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.

      Overrides:
      tag in class Value
    • target

      public Value target()
      Returns the flattened members of this Record after all attributes have been removed.

      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.

      Overrides:
      target in class Value
    • flattened

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

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

      Overrides:
      flattened in class Value
    • unflattened

      public Record unflattened()
      Returns this Record.
      Overrides:
      unflattened in class Value
    • header

      public Value header(String tag)
      Returns the value of the first member of this Record, if the first member is an Attr whose key string is equal to tag; otherwise returns Absent if the first member of this Record is not an Attr, or if the first member of this Record 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.

      Overrides:
      header in class Value
    • headers

      public Record headers(String tag)
      Returns the unflattened header of this Record. 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.
      Overrides:
      headers in class Value
    • head

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

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

      public Value body()
      Returns the flattened tail of this Record. 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.
      Overrides:
      body in class Value
    • contains

      public boolean contains(Object item)
      Returns true if this Record has a member equal to Item.fromObject(item); otherwise returns false if this Record has no member equal to Item.fromObject(item).
      Specified by:
      contains in interface Collection<Item>
      Specified by:
      contains in interface List<Item>
    • contains

      public boolean contains(Item item)
      Returns true if this Record has a member equal to item; otherwise returns false if this Record has no member equal to item.
      Overrides:
      contains in class Value
    • containsAll

      public boolean containsAll(Collection<?> items)
      Returns true if this Record has a member equal to every item in items; returns false if any item in items is not contained in this Record.
      Specified by:
      containsAll in interface Collection<Item>
      Specified by:
      containsAll in interface List<Item>
    • containsKey

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

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

      public boolean containsValue(Value value)
      Returns true if this Record has a Field member with a value that is equal to the given value; otherwise returns false if this Record has no Field member with a value equal to the given value.
      Overrides:
      containsValue in class Value
    • indexOf

      public int indexOf(Object item)
      Specified by:
      indexOf in interface List<Item>
    • lastIndexOf

      public int lastIndexOf(Object item)
      Specified by:
      lastIndexOf in interface List<Item>
    • get

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

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

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

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

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

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

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

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

      public abstract Item get(int index)
      Returns the member of this Record at the given index, if the index is greater than or equal to zero, and less than the length of this Record.
      Specified by:
      get in interface List<Item>
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds.
    • getItem

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

      public Value put(Value key, Value newValue)
    • put

      public Value put(Value key, String newValue)
    • put

      public Value put(Value key, int newValue)
    • put

      public Value put(Value key, long newValue)
    • put

      public Value put(Value key, float newValue)
    • put

      public Value put(Value key, double newValue)
    • put

      public Value put(Value key, boolean newValue)
    • put

      public Value put(String key, Value newValue)
    • put

      public Value put(String key, String newValue)
    • put

      public Value put(String key, int newValue)
    • put

      public Value put(String key, long newValue)
    • put

      public Value put(String key, float newValue)
    • put

      public Value put(String key, double newValue)
    • put

      public Value put(String key, boolean newValue)
    • putAttr

      public Value putAttr(Text key, Value newValue)
    • putAttr

      public Value putAttr(Text key, String newValue)
    • putAttr

      public Value putAttr(Text key, int newValue)
    • putAttr

      public Value putAttr(Text key, long newValue)
    • putAttr

      public Value putAttr(Text key, float newValue)
    • putAttr

      public Value putAttr(Text key, double newValue)
    • putAttr

      public Value putAttr(Text key, boolean newValue)
    • putAttr

      public Value putAttr(String key, Value newValue)
    • putAttr

      public Value putAttr(String key, String newValue)
    • putAttr

      public Value putAttr(String key, int newValue)
    • putAttr

      public Value putAttr(String key, long newValue)
    • putAttr

      public Value putAttr(String key, float newValue)
    • putAttr

      public Value putAttr(String key, double newValue)
    • putAttr

      public Value putAttr(String key, boolean newValue)
    • putSlot

      public Value putSlot(Value key, Value newValue)
    • putSlot

      public Value putSlot(Value key, String newValue)
    • putSlot

      public Value putSlot(Value key, int newValue)
    • putSlot

      public Value putSlot(Value key, long newValue)
    • putSlot

      public Value putSlot(Value key, float newValue)
    • putSlot

      public Value putSlot(Value key, double newValue)
    • putSlot

      public Value putSlot(Value key, boolean newValue)
    • putSlot

      public Value putSlot(String key, Value newValue)
    • putSlot

      public Value putSlot(String key, String newValue)
    • putSlot

      public Value putSlot(String key, int newValue)
    • putSlot

      public Value putSlot(String key, long newValue)
    • putSlot

      public Value putSlot(String key, float newValue)
    • putSlot

      public Value putSlot(String key, double newValue)
    • putSlot

      public Value putSlot(String key, boolean newValue)
    • putAll

      public void putAll(Map<? extends Value,? extends Value> fields)
    • set

      public Item set(int index, Item item)
      Replaces the member of this Record at the given index with a new item, returning the previous Item at the given index, if the index is greater than or equal to zero, and less than the length of this Record. Equivalent to setItem(int, Item).
      Specified by:
      set in interface List<Item>
      Throws:
      UnsupportedOperationException - if this is an immutable Record.
      IndexOutOfBoundsException - if the index is out of bounds.
    • setItem

      public abstract Item setItem(int index, Item item)
      Replaces the member of this Record at the given index with a new item, returning the previous Item at the given index, if the index is greater than or equal to zero, and less than the length of this Record.
      Throws:
      UnsupportedOperationException - if this is an immutable Record.
      IndexOutOfBoundsException - if the index is out of bounds.
    • setItem

      public Item setItem(int index, String value)
      Replaces the member of this Record at the given index with a Text value, returning the previous Item at the given index, if the index is greater than or equal to zero, and less than the length of this Record.
      Throws:
      UnsupportedOperationException - if this is an immutable Record.
      IndexOutOfBoundsException - if the index is out of bounds.
    • setItem

      public Item setItem(int index, int value)
      Replaces the member of this Record at the given index with a Num value, returning the previous Item at the given index, if the index is greater than or equal to zero, and less than the length of this Record.
      Throws:
      UnsupportedOperationException - if this is an immutable Record.
      IndexOutOfBoundsException - if the index is out of bounds.
    • setItem

      public Item setItem(int index, long value)
      Replaces the member of this Record at the given index with a Num value, returning the previous Item at the given index, if the index is greater than or equal to zero, and less than the length of this Record.
      Throws:
      UnsupportedOperationException - if this is an immutable Record.
      IndexOutOfBoundsException - if the index is out of bounds.
    • setItem

      public Item setItem(int index, float value)
      Replaces the member of this Record at the given index with a Num value, returning the previous Item at the given index, if the index is greater than or equal to zero, and less than the length of this Record.
      Throws:
      UnsupportedOperationException - if this is an immutable Record.
      IndexOutOfBoundsException - if the index is out of bounds.
    • setItem

      public Item setItem(int index, double value)
      Replaces the member of this Record at the given index with a Num value, returning the previous Item at the given index, if the index is greater than or equal to zero, and less than the length of this Record.
      Throws:
      UnsupportedOperationException - if this is an immutable Record.
      IndexOutOfBoundsException - if the index is out of bounds.
    • setItem

      public Item setItem(int index, boolean value)
      Replaces the member of this Record at the given index with a Bool value, returning the previous Item at the given index, if the index is greater than or equal to zero, and less than the length of this Record.
      Throws:
      UnsupportedOperationException - if this is an immutable Record.
      IndexOutOfBoundsException - if the index is out of bounds.
    • add

      public abstract boolean add(Item item)
      Description copied from interface: Builder
      Adds a single input value to this builder, returning true if the state of the builder changed.
      Specified by:
      add in interface Builder<Item,Record>
      Specified by:
      add in interface Collection<Item>
      Specified by:
      add in interface List<Item>
    • add

      public boolean add(String item)
    • add

      public boolean add(int item)
    • add

      public boolean add(long item)
    • add

      public boolean add(float item)
    • add

      public boolean add(double item)
    • add

      public boolean add(boolean item)
    • add

      public abstract void add(int index, Item item)
      Specified by:
      add in interface List<Item>
    • add

      public void add(int index, String item)
    • add

      public void add(int index, int item)
    • add

      public void add(int index, long item)
    • add

      public void add(int index, float item)
    • add

      public void add(int index, double item)
    • add

      public void add(int index, boolean item)
    • add

      public boolean add(Value key, Value value)
      Description copied from interface: PairBuilder
      Adds an input pair to this builder, returning true if the state of the builder changed.
      Specified by:
      add in interface PairBuilder<Value,Value,Record>
    • addAll

      public boolean addAll(Collection<? extends Item> items)
      Description copied from interface: Builder
      Adds multiple input values to this builder, returning true if the state of the builder changed.
      Specified by:
      addAll in interface Builder<Item,Record>
      Specified by:
      addAll in interface Collection<Item>
      Specified by:
      addAll in interface List<Item>
    • addAll

      public boolean addAll(int index, Collection<? extends Item> items)
      Specified by:
      addAll in interface List<Item>
    • attr

      public Record attr(Text key, Value value)
    • attr

      public Record attr(Text key, String value)
    • attr

      public Record attr(Text key, int value)
    • attr

      public Record attr(Text key, long value)
    • attr

      public Record attr(Text key, float value)
    • attr

      public Record attr(Text key, double value)
    • attr

      public Record attr(Text key, boolean value)
    • attr

      public Record attr(Text key)
    • attr

      public Record attr(String key, Value value)
    • attr

      public Record attr(String key, String value)
    • attr

      public Record attr(String key, int value)
    • attr

      public Record attr(String key, long value)
    • attr

      public Record attr(String key, float value)
    • attr

      public Record attr(String key, double value)
    • attr

      public Record attr(String key, boolean value)
    • attr

      public Record attr(String key)
    • slot

      public Record slot(Value key, Value value)
    • slot

      public Record slot(Value key, String value)
    • slot

      public Record slot(Value key, int value)
    • slot

      public Record slot(Value key, long value)
    • slot

      public Record slot(Value key, float value)
    • slot

      public Record slot(Value key, double value)
    • slot

      public Record slot(Value key, boolean value)
    • slot

      public Record slot(Value key)
    • slot

      public Record slot(String key, Value value)
    • slot

      public Record slot(String key, String value)
    • slot

      public Record slot(String key, int value)
    • slot

      public Record slot(String key, long value)
    • slot

      public Record slot(String key, float value)
    • slot

      public Record slot(String key, double value)
    • slot

      public Record slot(String key, boolean value)
    • slot

      public Record slot(String key)
    • item

      public Record item(Item item)
    • item

      public Record item(String item)
    • item

      public Record item(int item)
    • item

      public Record item(long item)
    • item

      public Record item(float item)
    • item

      public Record item(double item)
    • item

      public Record item(boolean item)
    • remove

      public abstract Item remove(int index)
      Specified by:
      remove in interface List<Item>
    • remove

      public boolean remove(Object object)
      Specified by:
      remove in interface Collection<Item>
      Specified by:
      remove in interface List<Item>
    • removeKey

      public boolean removeKey(Value key)
    • removeKey

      public boolean removeKey(String key)
    • removeAll

      public boolean removeAll(Collection<?> items)
      Specified by:
      removeAll in interface Collection<Item>
      Specified by:
      removeAll in interface List<Item>
    • retainAll

      public boolean retainAll(Collection<?> items)
      Specified by:
      retainAll in interface Collection<Item>
      Specified by:
      retainAll in interface List<Item>
    • clear

      public abstract void clear()
      Specified by:
      clear in interface Collection<Item>
      Specified by:
      clear in interface List<Item>
    • updated

      public Record updated(Value key, Value value)
      Overrides:
      updated in class Item
    • updated

      public Record updated(String key, Value value)
      Overrides:
      updated in class Item
    • updatedAttr

      public Record updatedAttr(Text key, Value value)
      Overrides:
      updatedAttr in class Item
    • updatedAttr

      public Record updatedAttr(String key, Value value)
      Overrides:
      updatedAttr in class Item
    • updatedSlot

      public Record updatedSlot(Value key, Value value)
      Overrides:
      updatedSlot in class Item
    • updatedSlot

      public Record updatedSlot(String key, Value value)
      Overrides:
      updatedSlot in class Item
    • appended

      public Record appended(Item item)
      Overrides:
      appended in class Item
    • appended

      public Record appended(Object... items)
      Overrides:
      appended in class Item
    • prepended

      public Record prepended(Item item)
      Overrides:
      prepended in class Item
    • prepended

      public Record prepended(Object... items)
      Overrides:
      prepended in class Item
    • removed

      public Record removed(Value key)
      Overrides:
      removed in class Value
    • removed

      public Record removed(String key)
      Overrides:
      removed in class Value
    • concat

      public Record concat(Item that)
      Overrides:
      concat in class Item
    • evaluate

      public Record evaluate(Interpreter interpreter)
      Overrides:
      evaluate in class Item
    • substitute

      public Record substitute(Interpreter interpreter)
      Overrides:
      substitute in class Item
    • stringValue

      public String stringValue()
      Description copied from class: Value
      Converts this Value into a String value, if possible.
      Overrides:
      stringValue in class Value
    • stringValue

      public String stringValue(String orElse)
      Description copied from class: Value
      Converts this Value into a String value, if possible; otherwise returns orElse if this Value can't be converted into a string value.
      Overrides:
      stringValue in class Value
    • isAliased

      public boolean isAliased()
      Overrides:
      isAliased in class Value
    • isMutable

      public boolean isMutable()
      Overrides:
      isMutable in class Value
    • asMutable

      public Record asMutable()
    • alias

      public void alias()
      Overrides:
      alias in class Value
    • branch

      public Record branch()
      Overrides:
      branch in class Value
    • commit

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

      public Record bind()
      Description copied from interface: Builder
      Returns the output result of this builder.
      Specified by:
      bind in interface Builder<Item,Record>
      Specified by:
      bind in interface PairBuilder<Value,Value,Record>
    • toArray

      public Item[] toArray()
      Specified by:
      toArray in interface Collection<Item>
      Specified by:
      toArray in interface List<Item>
    • toArray

      public <T> T[] toArray(T[] array)
      Specified by:
      toArray in interface Collection<Item>
      Specified by:
      toArray in interface List<Item>
    • subList

      public Record subList(int fromIndex, int toIndex)
      Specified by:
      subList in interface List<Item>
    • entrySet

      public Set<Map.Entry<Value,Value>> entrySet()
    • fieldSet

      public Set<Field> fieldSet()
    • keySet

      public Set<Value> keySet()
    • values

      public Collection<Value> values()
    • iterator

      public Iterator<Item> iterator()
      Specified by:
      iterator in interface Collection<Item>
      Specified by:
      iterator in interface Iterable<Item>
      Specified by:
      iterator in interface List<Item>
      Overrides:
      iterator in class Item
    • listIterator

      public ListIterator<Item> listIterator()
      Specified by:
      listIterator in interface List<Item>
    • listIterator

      public ListIterator<Item> listIterator(int index)
      Specified by:
      listIterator in interface List<Item>
    • keyIterator

      public Iterator<Value> keyIterator()
    • valueIterator

      public Iterator<Value> valueIterator()
    • fieldIterator

      public Iterator<Field> fieldIterator()
    • typeOrder

      public int typeOrder()
      Description copied from class: Item
      Returns the heterogeneous sort order of this Item. Used to impose a total order on the set of all items. When comparing two items of different types, the items order according to their typeOrder.
      Specified by:
      typeOrder in class Item
    • compareTo

      public int compareTo(Item other)
      Specified by:
      compareTo in interface Comparable<Item>
      Specified by:
      compareTo in class Item
    • compareTo

      public int compareTo(Record that)
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Collection<Item>
      Specified by:
      equals in interface List<Item>
      Specified by:
      equals in class Item
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<Item>
      Specified by:
      hashCode in interface List<Item>
      Specified by:
      hashCode in class Item
    • debug

      public <T> Output<T> debug(Output<T> output)
      Description copied from interface: Debug
      Writes a developer readable, debug-formatted string representation of this object to output.
      Specified by:
      debug in interface Debug
      Specified by:
      debug in class Item
      Returns:
      the continuation of the output.
    • empty

      public static Record empty()
    • create

      public static Record create()
    • create

      public static Record create(int initialSize)
    • of

      public static Record of()
    • of

      public static Record of(Object object)
    • of

      public static Record of(Object... objects)