001 /*
002 * JBoss DNA (http://www.jboss.org/dna)
003 * See the COPYRIGHT.txt file distributed with this work for information
004 * regarding copyright ownership. Some portions may be licensed
005 * to Red Hat, Inc. under one or more contributor license agreements.
006 * See the AUTHORS.txt file in the distribution for a full listing of
007 * individual contributors.
008 *
009 * Unless otherwise indicated, all code in JBoss DNA is licensed
010 * to you under the terms of the GNU Lesser General Public License as
011 * published by the Free Software Foundation; either version 2.1 of
012 * the License, or (at your option) any later version.
013 *
014 * JBoss DNA is distributed in the hope that it will be useful,
015 * but WITHOUT ANY WARRANTY; without even the implied warranty of
016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017 * Lesser General Public License for more details.
018 *
019 * You should have received a copy of the GNU Lesser General Public
020 * License along with this software; if not, write to the Free
021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
023 */
024 package org.jboss.dna.jcr;
025
026 import java.util.UUID;
027 import net.jcip.annotations.Immutable;
028 import org.jboss.dna.common.util.HashCode;
029 import org.jboss.dna.graph.property.Name;
030
031 /**
032 * An immutable identifier for a property, often used to reference information a property held within the {@link SessionCache}.
033 */
034 @Immutable
035 public final class PropertyId {
036
037 private final UUID nodeId;
038 private final Name propertyName;
039 private final int hc;
040
041 /**
042 * Create a new property identifier.
043 *
044 * @param nodeId the UUID of the node that owns the property being reference; may not be null
045 * @param propertyName the name of the property being referenced; may not be null
046 */
047 public PropertyId( UUID nodeId,
048 Name propertyName ) {
049 assert nodeId != null;
050 assert propertyName != null;
051 this.nodeId = nodeId;
052 this.propertyName = propertyName;
053 this.hc = HashCode.compute(this.nodeId, this.propertyName);
054 }
055
056 /**
057 * Get the UUID of the node that owns the property.
058 *
059 * @return the node's UUID; never null
060 */
061 public UUID getNodeId() {
062 return nodeId;
063 }
064
065 /**
066 * Get the name of the property.
067 *
068 * @return the property name; never null
069 */
070 public Name getPropertyName() {
071 return propertyName;
072 }
073
074 /**
075 * {@inheritDoc}
076 *
077 * @see java.lang.Object#hashCode()
078 */
079 @Override
080 public int hashCode() {
081 return hc;
082 }
083
084 /**
085 * {@inheritDoc}
086 *
087 * @see java.lang.Object#equals(java.lang.Object)
088 */
089 @Override
090 public boolean equals( Object obj ) {
091 if (obj == this) return true;
092 if (obj instanceof PropertyId) {
093 PropertyId that = (PropertyId)obj;
094 if (this.hc != that.hc) return false;
095 if (!this.nodeId.equals(that.nodeId)) return false;
096 return this.propertyName.equals(that.propertyName);
097 }
098 return false;
099 }
100
101 /**
102 * {@inheritDoc}
103 *
104 * @see java.lang.Object#toString()
105 */
106 @Override
107 public String toString() {
108 return this.nodeId.toString() + '@' + this.propertyName.toString();
109 }
110
111 }