Package gnu.mapping
Class Symbol
- java.lang.Object
-
- gnu.mapping.Symbol
-
- All Implemented Interfaces:
EnvironmentKey
,Externalizable
,Serializable
,Comparable
- Direct Known Subclasses:
Keyword
,SimpleSymbol
,XName
public class Symbol extends Object implements EnvironmentKey, Comparable, 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. ASymbol
may be viewed as anEnvironmentKey
with anull
property component.- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Object o)
static boolean
equals(Symbol sym1, Symbol sym2)
boolean
equals(Object o)
Just tests for identity.Object
getKeyProperty()
Symbol
getKeySymbol()
String
getLocalName()
Synonym for getName - the "print name" of the symbol without Namespace.String
getLocalPart()
String
getName()
Namespace
getNamespace()
String
getNamespaceURI()
String
getPrefix()
boolean
hasEmptyNamespace()
int
hashCode()
boolean
hasUnknownNamespace()
static Symbol
make(Object namespace, String name)
Find or create a symbol in a specificed namespace.static Symbol
make(String uri, String name, String prefix)
Find or create a symbol in a specificed namespace.static Symbol
makeUninterned(String name)
static Symbol
makeUninterned(String name, Namespace namespace)
static Symbol
makeWithUnknownNamespace(String local, String prefix)
Make a placeholder symbol with a known prefix and unknown namespace-uri.boolean
matches(EnvironmentKey key)
boolean
matches(Symbol symbol, Object property)
static Symbol
parse(String symbol)
Parse a String as a Symbol.void
readExternal(ObjectInput in)
Object
readResolve()
void
setNamespace(Namespace ns)
String
toString()
String
toString(char style)
Convert a Symbol to a printable String.static SimpleSymbol
valueOf(String name)
static Symbol
valueOf(String name, Object spec)
static Symbol
valueOf(String name, String namespace, String prefix)
void
writeExternal(ObjectOutput out)
-
-
-
Field Detail
-
name
protected 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 aSymbol
name to access anObject
's property list. A property list is a list with a even number ofPair
s, 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.)
-
-
Method Detail
-
getKeySymbol
public final Symbol getKeySymbol()
- Specified by:
getKeySymbol
in interfaceEnvironmentKey
-
getKeyProperty
public final Object getKeyProperty()
- Specified by:
getKeyProperty
in interfaceEnvironmentKey
-
matches
public boolean matches(EnvironmentKey key)
- Specified by:
matches
in interfaceEnvironmentKey
-
matches
public boolean matches(Symbol symbol, Object property)
- Specified by:
matches
in interfaceEnvironmentKey
-
getNamespaceURI
public final String getNamespaceURI()
-
getLocalPart
public final String getLocalPart()
-
getPrefix
public final String getPrefix()
-
hasEmptyNamespace
public final boolean hasEmptyNamespace()
-
hasUnknownNamespace
public final boolean hasUnknownNamespace()
-
getLocalName
public final 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 String getName()
-
make
public static Symbol make(String uri, String name, 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(Object namespace, 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(String name)
-
parse
public static Symbol parse(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, usingmakeWithUnknownNamespace(java.lang.String, java.lang.String)
;- and plain
"local-name"
- which creates a symbol inNamespace.EmptyNamespace
.
-
makeWithUnknownNamespace
public static Symbol makeWithUnknownNamespace(String local, 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 withNamespace.makeUnknownNamespace(String)
.
-
compareTo
public int compareTo(Object o)
- Specified by:
compareTo
in interfaceComparable
-
equals
public final boolean equals(Object o)
Just tests for identity. Otherwise hashTables that have Symbols as keys will break.
-
getNamespace
public final Namespace getNamespace()
-
setNamespace
public final void setNamespace(Namespace ns)
-
toString
public 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(ObjectOutput out) throws IOException
- Specified by:
writeExternal
in interfaceExternalizable
- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternal
in interfaceExternalizable
- Throws:
IOException
ClassNotFoundException
-
readResolve
public Object readResolve() throws ObjectStreamException
- Throws:
ObjectStreamException
-
-