ruper2/src/java/core/org/krysalis/ruper2/util/identity GenericIdentifier.java,NONE,1.1 GenericNamespace.java,NONE,1.1 Identifiable.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.metamorphosis.cvs
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/ruper2/src/java/core/org/krysalis/ruper2/util/identity
In directory sc8-pr-cvs1:/tmp/cvs-serv30481/src/java/core/org/krysalis/ruper2/util/identity

Added Files:
	GenericIdentifier.java GenericNamespace.java Identifiable.java 
Log Message:
Avoid clash with existing Ruper...

--- NEW FILE: GenericIdentifier.java ---
/*
 * Created on Aug 23, 2003
 *
 */
package org.krysalis.ruper2.util.identity;

import org.krysalis.ruper2.util.select.Selectable;

/**
 * @author anou_mana
 */
public class GenericIdentifier implements Selectable {

	private GenericNamespace m_ns = null;
	private String m_id = null;

	public GenericIdentifier(String uri, String prefix, String id) {
		m_ns = new GenericNamespace(uri, prefix);
		m_id = id;
	}

	public GenericIdentifier(GenericNamespace ns, String id) {
		m_ns = ns;
		m_id = id;
	}

	public GenericIdentifier(String uri, String id) {
		m_ns = new GenericNamespace(uri);
		m_id = id;
	}

	public Object getSelectionObject() {
		return m_id;
	}

	/**
	 * @return
	 */
	public String getId() {
		return m_id;
	}

	/**
	 * @param string
	 */
	public void setId(String string) {
		m_id = string;
	}

	/**
	 * @return
	 */
	public GenericNamespace getNamespace() {
		return m_ns;
	}

	/**
	 * @param genericURI
	 */
	public void setNamespace(GenericNamespace genericNS) {
		m_ns = genericNS;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object other) {
		boolean equal = true;

		if (other instanceof GenericIdentifier) {
			GenericIdentifier otherId = (GenericIdentifier) other;

			equal = otherId.m_ns.equals(m_ns);

			equal &= otherId.m_id.equals(m_id);
		}
		else
			throw new IllegalArgumentException(
				"Not a GenericIdentifier: " + other.getClass().getName());

		return equal;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return m_ns.hashCode() + m_id.hashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return "["+m_ns.getPrefix() + ":" + m_id+"]";
	}
}

--- NEW FILE: GenericNamespace.java ---
/*
 * Created on Aug 23, 2003
 *
 */
package org.krysalis.ruper2.util.identity;

/**
 * @author arb_jack
 */
public class GenericNamespace implements Comparable {

	private String m_uri = null;
	private String m_prefix = null;

	public GenericNamespace(String uri, String prefix) {
		m_uri = uri;
		m_prefix = prefix;
	}

	public GenericNamespace(String uri) {
		m_uri = uri;

		int posn = uri.lastIndexOf('/');
		if (-1 != posn)
			m_prefix = uri.substring(posn);
		else
			m_prefix = "unset";
	}

	/**
	 * @return
	 */
	public String getPrefix() {
		return m_prefix;
	}

	/**
	 * @return
	 */
	public String getUri() {
		return m_uri;
	}

	/**
	 * @param string
	 */
	public void setPrefix(String string) {
		m_prefix = string;
	}

	/**
	 * @param string
	 */
	public void setUri(String string) {
		m_uri = string;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object other) {
		boolean equal = true;

		if (other instanceof GenericNamespace) {
			GenericNamespace otherNS = (GenericNamespace) other;

			equal = m_uri.equals(otherNS.m_uri);
		}
		else {
			throw new IllegalArgumentException(
				"Not a GenericNamespace: " + other.getClass().getName());
		}

		return equal;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#compareTo(java.lang.Object)
	 */
	public int compareTo(Object other) {
		int comparison = 0;

		if (other instanceof GenericNamespace) {
			GenericNamespace otherNS = (GenericNamespace) other;

			// Sort in prefix order
			comparison = m_prefix.compareToIgnoreCase(otherNS.m_prefix);
		}
		else {
			throw new IllegalArgumentException(
				"Not a GenericNamespace: " + other.getClass().getName());
		}

		return comparison;
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return m_uri.hashCode();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return m_prefix + " [i.e. " + m_uri + "]";
	}
}

--- NEW FILE: Identifiable.java ---
/*
 * Created on Aug 29, 2003
 */
package org.krysalis.ruper2.util.identity;


/**
 * @author arb_jack
 */
public interface Identifiable {
	GenericIdentifier getIdentifier();
}




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.