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 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed 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.graph.property.basic; 025 026 import java.util.UUID; 027 import net.jcip.annotations.Immutable; 028 import org.jboss.dna.common.text.TextEncoder; 029 import org.jboss.dna.graph.property.Path; 030 import org.jboss.dna.graph.property.Reference; 031 032 /** 033 * @author Randall Hauch 034 */ 035 @Immutable 036 public class UuidReference implements Reference { 037 038 /** 039 */ 040 private static final long serialVersionUID = 2299467578161645109L; 041 private UUID uuid; 042 043 public UuidReference( UUID uuid ) { 044 this.uuid = uuid; 045 } 046 047 /** 048 * @return uuid 049 */ 050 public UUID getUuid() { 051 return this.uuid; 052 } 053 054 /** 055 * {@inheritDoc} 056 */ 057 public String getString() { 058 return this.uuid.toString(); 059 } 060 061 /** 062 * {@inheritDoc} 063 */ 064 public String getString( TextEncoder encoder ) { 065 if (encoder == null) encoder = Path.DEFAULT_ENCODER; 066 return encoder.encode(getString()); 067 } 068 069 /** 070 * {@inheritDoc} 071 */ 072 public int compareTo( Reference that ) { 073 if (this == that) return 0; 074 if (that instanceof UuidReference) { 075 return this.uuid.compareTo(((UuidReference)that).getUuid()); 076 } 077 return this.getString().compareTo(that.getString()); 078 } 079 080 /** 081 * {@inheritDoc} 082 */ 083 @Override 084 public boolean equals( Object obj ) { 085 if (obj == this) return true; 086 if (obj instanceof UuidReference) { 087 return this.uuid.equals(((UuidReference)obj).getUuid()); 088 } 089 if (obj instanceof Reference) { 090 return this.getString().equals(((Reference)obj).getString()); 091 } 092 return super.equals(obj); 093 } 094 095 /** 096 * {@inheritDoc} 097 */ 098 @Override 099 public String toString() { 100 return this.uuid.toString(); 101 } 102 103 }