Package gnu.mapping

Class Symbol

  • All Implemented Interfaces:
    EnvironmentKey, java.io.Externalizable, java.io.Serializable, java.lang.Comparable
    Direct Known Subclasses:
    Keyword, SimpleSymbol, XName

    public class Symbol
    extends java.lang.Object
    implements EnvironmentKey, java.lang.Comparable, java.io.Externalizable
    A Symbol is a name, usually in a specific Namespace. A Symbol is stateless: Common Lisp-style "value", "function" and "property list" bindings are not part of the Symbol itself, but looked up in the current Environment. A Symbol may be viewed as an EnvironmentKey with a null property component.
    See Also:
    Serialized Form
    • Field Detail

      • name

        protected java.lang.String name
      • FUNCTION

        public static final Symbol FUNCTION
        Conventional value used as a property key for function bindings.
      • PLIST

        public static final Symbol PLIST
        Conventional value used as a Symbol name to access an Object's property list. A property list is a list with a even number of Pairs, containing alternating keys and values. They are used in Common Lisp and Emacs Lisp. Kawa (following XEmacs) allows arbitrary objects to have property lists, thus the PLIST as used as the name and the object as the property. (In the future we'll do somethingg clever so that get(SYMBOL, KEY) as the same as getf(get(PLIST, SYMBOL), KEY) - but much faster.)
    • Constructor Detail

      • Symbol

        public Symbol()
      • Symbol

        protected Symbol​(java.lang.String name,
                         Namespace ns)
        Create new Symbol in a given namespace. Does not enter the result in the namespace's symbol table.
        Parameters:
        name - an interned String
    • Method Detail

      • getNamespaceURI

        public final java.lang.String getNamespaceURI()
      • getLocalPart

        public final java.lang.String getLocalPart()
      • getPrefix

        public final java.lang.String getPrefix()
      • hasEmptyNamespace

        public final boolean hasEmptyNamespace()
      • hasUnknownNamespace

        public final boolean hasUnknownNamespace()
      • getLocalName

        public final java.lang.String getLocalName()
        Synonym for getName - the "print name" of the symbol without Namespace. Useful when thinking of a Symbol as an XML QName.
      • getName

        public final java.lang.String getName()
      • make

        public static Symbol make​(java.lang.String uri,
                                  java.lang.String name,
                                  java.lang.String prefix)
        Find or create a symbol in a specificed namespace.
        Parameters:
        uri - a namespace uri.
        name - The "local name" or "print name" of the desired symbol.
        prefix - namespace prefix, or ""
      • make

        public static Symbol make​(java.lang.Object namespace,
                                  java.lang.String name)
        Find or create a symbol in a specificed namespace.
        Parameters:
        namespace - can be an Namespace, or a namespace/environment name (resolved using Namespace.getInstance), or null (in which case an uninterned symbol is created).
        name - The "local name" or "print name" of the desired symbol.
      • valueOf

        public static SimpleSymbol valueOf​(java.lang.String name)
      • valueOf

        public static Symbol valueOf​(java.lang.String name,
                                     java.lang.Object spec)
      • valueOf

        public static Symbol valueOf​(java.lang.String name,
                                     java.lang.String namespace,
                                     java.lang.String prefix)
      • parse

        public static Symbol parse​(java.lang.String symbol)
        Parse a String as a Symbol. Recognizes:
        • "{namespace-uri}:local-name" - which creates a symbol with that namespace-uri and an empty prefix;
        • "{namespace-uri}local-name" - which is the same as above
        • "prefix{namespace-uri}:local-name" - which creates a symbok with that prefix and namespace-uri
        • "prefix:local-name"- which creates a symbol with that prefix and an "unknown" namespace-uri, using makeWithUnknownNamespace(java.lang.String, java.lang.String);
        • and plain "local-name" - which creates a symbol in Namespace.EmptyNamespace.
      • makeWithUnknownNamespace

        public static Symbol makeWithUnknownNamespace​(java.lang.String local,
                                                      java.lang.String prefix)
        Make a placeholder symbol with a known prefix and unknown namespace-uri. This is convenient for processing definition commands like "prefix:name=value" - such as on the Kawa command-line - where we don't yet know the namespace-uri. Code that later looks for a value should look both under the true namespace-uri and the prefix combined with Namespace.makeUnknownNamespace(String).
      • makeUninterned

        public static Symbol makeUninterned​(java.lang.String name)
      • makeUninterned

        public static Symbol makeUninterned​(java.lang.String name,
                                            Namespace namespace)
      • compareTo

        public int compareTo​(java.lang.Object o)
        Specified by:
        compareTo in interface java.lang.Comparable
      • equals

        public static boolean equals​(Symbol sym1,
                                     Symbol sym2)
      • equals

        public final boolean equals​(java.lang.Object o)
        Just tests for identity. Otherwise hashTables that have Symbols as keys will break.
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getNamespace

        public final Namespace getNamespace()
      • setNamespace

        public final void setNamespace​(Namespace ns)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toString

        public java.lang.String toString​(char style)
        Convert a Symbol to a printable String.
        Parameters:
        style - if 'P' then print prefix if available (otherwise Uri), if 'U' then print Uri if available (otherwise prefix), if '+' then print both if available.
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • readResolve

        public java.lang.Object readResolve()
                                     throws java.io.ObjectStreamException
        Throws:
        java.io.ObjectStreamException