krysalis-update/src/java/org/krysalis/depot/update/util/identity IIdentifiable.java,NONE,1.1 GenericIdentifier.java,NONE,1.1 GenericNamespace.java,NONE,1.1
Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:06:41 +0000
| Newsgroups | gmane.comp.krysalis.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/krysalis/krysalis-update/src/java/org/krysalis/depot/update/util/identity
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/java/org/krysalis/depot/update/util/identity
Added Files:
IIdentifiable.java GenericIdentifier.java
GenericNamespace.java
Log Message:
Copied from the apache incubator.
--- NEW FILE: IIdentifiable.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.depot.update.util.identity;
/**
* @author arb_jack
*/
public interface IIdentifiable {
GenericIdentifier getIdentifier();
}
--- NEW FILE: GenericIdentifier.java ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.depot.update.util.identity;
import org.krysalis.depot.update.util.select.ISelectable;
/**
* @author anou_mana
*/
public class GenericIdentifier implements ISelectable {
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 ---
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.krysalis.depot.update.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 + "]";
}
}
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://productguide.itmanagersjournal.com/