Record Class ResourceId

java.lang.Object
java.lang.Record
icyllis.modernui.resources.ResourceId
Record Components:
namespace - the domain of resource
type - the class of resource
entry - the name of resource entry
All Implemented Interfaces:
Comparable<ResourceId>

@Immutable public record ResourceId(String namespace, String type, String entry) extends Record implements Comparable<ResourceId>
A resource identifier. This can uniquely identify a resource in the ResourceTable.

A resource identifier consists of three parts: namespace, type, and entry. Its single string representation is "namespace:type/entry" or "type/entry" (if namespace is empty). For a valid resource identifier, type and entry can not be empty.

  • Constructor Details

    • ResourceId

      public ResourceId(@NonNull String namespace, @NonNull String type, @NonNull String entry)
      Creates an instance of a ResourceId record class.
      Parameters:
      namespace - the value for the namespace record component
      type - the value for the type record component
      entry - the value for the entry record component
  • Method Details

    • parse

      @NonNull @Contract("_ -> new") public static ResourceId parse(@NonNull String name)
    • parse

      @NonNull @Contract("_, _, _ -> new") public static ResourceId parse(@NonNull String name, @NonNull String fallbackType, @NonNull String fallbackNamespace)
    • attr

      @NonNull @Contract("_, _ -> new") public static ResourceId attr(@NonNull String namespace, @NonNull String name)
      Helper method to create an attribute resource id, where the resource type name will be "attr".
    • toString

      @NonNull @Contract(pure=true) public String toString()
      Returns a new, single string representation of this resource identifier.
      Specified by:
      toString in class Record
    • toString

      @NonNull @Contract(pure=true) public static String toString(@NonNull String namespace, @NonNull String type, @NonNull String entry)
    • equals

      public boolean equals(Object object)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      object - the object with which to compare
      Returns:
      true if this object is the same as the object argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • compareTo

      public int compareTo(@NonNull ResourceId o)
      Compare strings lexicographically, by namespace, then type, then entry.
      Specified by:
      compareTo in interface Comparable<ResourceId>
      Parameters:
      o - the object to be compared.
    • comparePair

      public static int comparePair(@NonNull String lhsNamespace, @NonNull String lhsName, @NonNull String rhsNamespace, @NonNull String rhsName)
    • namespace

      @NonNull public String namespace()
      Returns the value of the namespace record component.
      Returns:
      the value of the namespace record component
    • type

      @NonNull public String type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • entry

      @NonNull public String entry()
      Returns the value of the entry record component.
      Returns:
      the value of the entry record component