Author: rhauch
Date: 2009-02-23 12:56:28 -0500 (Mon, 23 Feb 2009)
New Revision: 734
Added:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java
Removed:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathLocation.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertiesLocation.java
trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertyLocation.java
Modified:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java
Log:
DNA-280 Create optimized versions of Location
Minor changes and improvements, including removal of duplicate CheckArg method calls.
Renamed *Location classes to Location* to follow some other naming patterns
("convention" is too harsh). Also added LocationWithUuid, since we'll have
a lot of Location objects that have only the UUID (not nearly as much as path+uuid, which
is covered by LocationWithPathAndProperty).
Modified: trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java 2009-02-23 15:55:50
UTC (rev 733)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/Location.java 2009-02-23 17:56:28
UTC (rev 734)
@@ -24,13 +24,13 @@
package org.jboss.dna.graph;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
+import java.util.Set;
import java.util.UUID;
-
import net.jcip.annotations.Immutable;
-
import org.jboss.dna.common.text.TextEncoder;
import org.jboss.dna.common.util.CheckArg;
import org.jboss.dna.common.util.HashCode;
@@ -75,7 +75,7 @@
public static Location create( Path path ) {
CheckArg.isNotNull(path, "path");
- return new PathLocation(path);
+ return new LocationWithPath(path);
}
/**
@@ -88,8 +88,7 @@
*/
public static Location create( UUID uuid ) {
CheckArg.isNotNull(uuid, "uuid");
- Property idProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
- return new PathPropertyLocation(null, idProperty);
+ return new LocationWithUuid(uuid);
}
/**
@@ -104,7 +103,7 @@
public static Location create( Path path,
UUID uuid ) {
CheckArg.isNotNull(uuid, "uuid");
- return new PathPropertyLocation(path, new
BasicSingleValueProperty(DnaLexicon.UUID, uuid));
+ return new LocationWithPathAndProperty(path, new
BasicSingleValueProperty(DnaLexicon.UUID, uuid));
}
/**
@@ -119,7 +118,7 @@
Property idProperty ) {
CheckArg.isNotNull(path, "path");
CheckArg.isNotNull(idProperty, "idProperty");
- return new PathPropertyLocation(path, idProperty);
+ return new LocationWithPathAndProperty(path, idProperty);
}
/**
@@ -138,11 +137,13 @@
CheckArg.isNotNull(firstIdProperty, "firstIdProperty");
CheckArg.isNotNull(remainingIdProperties, "remainingIdProperties");
List<Property> idProperties = new ArrayList<Property>(1 +
remainingIdProperties.length);
+ Set<Name> names = new HashSet<Name>();
+ names.add(firstIdProperty.getName());
idProperties.add(firstIdProperty);
for (Property property : remainingIdProperties) {
- idProperties.add(property);
+ if (names.add(property.getName())) idProperties.add(property);
}
- return new PathPropertiesLocation(path, idProperties);
+ return new LocationWithPathAndProperties(path, idProperties);
}
/**
@@ -158,10 +159,18 @@
CheckArg.isNotNull(path, "path");
CheckArg.isNotNull(idProperties, "idProperties");
List<Property> idPropertiesList = new ArrayList<Property>();
+ Set<Name> names = new HashSet<Name>();
for (Property property : idProperties) {
- idPropertiesList.add(property);
+ if (names.add(property.getName())) idPropertiesList.add(property);
}
- return new PathPropertiesLocation(path, idPropertiesList);
+ switch (idPropertiesList.size()) {
+ case 0:
+ return new LocationWithPath(path);
+ case 1:
+ return new LocationWithPathAndProperty(path, idPropertiesList.get(0));
+ default:
+ return new LocationWithPathAndProperties(path, idPropertiesList);
+ }
}
/**
@@ -173,7 +182,7 @@
*/
public static Location create( Property idProperty ) {
CheckArg.isNotNull(idProperty, "idProperty");
- return new PathPropertyLocation(null, idProperty);
+ return new LocationWithPathAndProperty(null, idProperty);
}
/**
@@ -189,11 +198,13 @@
CheckArg.isNotNull(firstIdProperty, "firstIdProperty");
CheckArg.isNotNull(remainingIdProperties, "remainingIdProperties");
List<Property> idProperties = new ArrayList<Property>(1 +
remainingIdProperties.length);
+ Set<Name> names = new HashSet<Name>();
+ names.add(firstIdProperty.getName());
idProperties.add(firstIdProperty);
for (Property property : remainingIdProperties) {
- idProperties.add(property);
+ if (names.add(property.getName())) idProperties.add(property);
}
- return new PathPropertiesLocation(null, idProperties);
+ return new LocationWithPathAndProperties(null, idProperties);
}
/**
@@ -206,14 +217,25 @@
public static Location create( Iterable<Property> idProperties ) {
CheckArg.isNotNull(idProperties, "idProperties");
List<Property> idPropertiesList = new ArrayList<Property>();
+ Set<Name> names = new HashSet<Name>();
for (Property property : idProperties) {
- idPropertiesList.add(property);
+ if (names.add(property.getName())) idPropertiesList.add(property);
}
- return new PathPropertiesLocation(null, idPropertiesList);
+ switch (idPropertiesList.size()) {
+ case 0:
+ CheckArg.isNotEmpty(idPropertiesList, "idProperties");
+ assert false;
+ return null; // never get here
+ case 1:
+ return new LocationWithPathAndProperty(null, idPropertiesList.get(0));
+ default:
+ return new LocationWithPathAndProperties(null, idPropertiesList);
+ }
}
/**
- * Create a location defined by multiple identification properties.
+ * Create a location defined by multiple identification properties. This method does
not check whether the identification
+ * properties are duplicated.
*
* @param idProperties the identification properties
* @return a new <code>Location</code> with no path and the given
identification properties.
@@ -221,7 +243,7 @@
*/
public static Location create( List<Property> idProperties ) {
CheckArg.isNotEmpty(idProperties, "idProperties");
- return new PathPropertiesLocation(null, idProperties);
+ return new LocationWithPathAndProperties(null, idProperties);
}
/**
@@ -544,6 +566,7 @@
* @return the new location, or this location if the new identification property is
null or empty
*/
public abstract Location with( Property newIdProperty );
+
/**
* Create a copy of this location that uses the supplied path.
*
Copied: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java (from rev
733, trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathLocation.java)
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java
(rev 0)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java 2009-02-23
17:56:28 UTC (rev 734)
@@ -0,0 +1,164 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.graph;
+
+import java.util.List;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.text.TextEncoder;
+import org.jboss.dna.common.util.HashCode;
+import org.jboss.dna.graph.property.NamespaceRegistry;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.Property;
+
+/**
+ * Special location type optimized for use when only a path is specified. This class
should never be directly instantiated by
+ * users of the DNA framework. Instead, use @{link Location#create} to create the correct
location.
+ *
+ * @see Location
+ */
+@Immutable
+class LocationWithPath extends Location {
+
+ private final Path path;
+ private final int hashCode;
+
+ LocationWithPath( Path path ) {
+ assert path != null;
+ this.path = path;
+
+ // Paths are immutable, so PathLocations are immutable...
+ // ... so we can cache the hash code.
+ hashCode = HashCode.compute(path);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getPath()
+ */
+ @Override
+ public final Path getPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#hasPath()
+ */
+ @Override
+ public final boolean hasPath() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getIdProperties()
+ */
+ @Override
+ public final List<Property> getIdProperties() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#hasIdProperties()
+ */
+ @Override
+ public final boolean hasIdProperties() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getUuid()
+ */
+ @Override
+ public final UUID getUuid() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getString(NamespaceRegistry, TextEncoder, TextEncoder)
+ */
+ @Override
+ public String getString( NamespaceRegistry namespaceRegistry,
+ TextEncoder encoder,
+ TextEncoder delimiterEncoder ) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("{ ");
+ sb.append(path.getString(namespaceRegistry, encoder, delimiterEncoder));
+ sb.append(" }");
+ return sb.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(Property)
+ */
+ @Override
+ public Location with( Property newIdProperty ) {
+ if (newIdProperty == null || newIdProperty.isEmpty()) return this;
+ return Location.create(path, newIdProperty);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(Path)
+ */
+ @Override
+ public Location with( Path newPath ) {
+ if (newPath == null || path.equals(newPath)) return this;
+ return Location.create(newPath);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(UUID)
+ */
+ @Override
+ public Location with( UUID uuid ) {
+ if (uuid == null) return this;
+ return Location.create(path, uuid);
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPath.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java (from
rev 733, trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertiesLocation.java)
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java 2009-02-23
17:56:28 UTC (rev 734)
@@ -0,0 +1,161 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.graph;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.HashCode;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.basic.BasicSingleValueProperty;
+
+/**
+ * General purpose location type that supports a path and zero or more properties. This
class should never be directly
+ * instantiated by users of the DNA framework. Instead, use @{link Location#create} to
create the correct location.
+ *
+ * @see Location
+ */
+@Immutable
+class LocationWithPathAndProperties extends Location {
+
+ private final Path path;
+ private final List<Property> idProperties;
+
+ private final int hashCode;
+
+ /**
+ * Create a new location with a given path and set of identification properties.
+ *
+ * @param path the path
+ * @param idProperties the identification properties
+ */
+ LocationWithPathAndProperties( Path path,
+ List<Property> idProperties ) {
+ assert idProperties != null;
+ assert !idProperties.isEmpty();
+ this.path = path;
+ this.idProperties = Collections.unmodifiableList(idProperties);
+ // Paths are immutable, Properties are immutable, the idProperties list
+ // is wrapped in an unmodifiableList by the Location factory methods...
+ // ... so we can cache the hash code.
+ hashCode = HashCode.compute(path, idProperties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getPath()
+ */
+ @Override
+ public final Path getPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getIdProperties()
+ */
+ @Override
+ public final List<Property> getIdProperties() {
+ return idProperties;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#hasIdProperties()
+ */
+ @Override
+ public final boolean hasIdProperties() {
+ return idProperties.size() > 0;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(Property)
+ */
+ @Override
+ public Location with( Property newIdProperty ) {
+ if (newIdProperty == null || newIdProperty.isEmpty()) return this;
+
+ List<Property> newIdProperties;
+
+ if (hasIdProperties()) {
+ newIdProperties = new ArrayList<Property>(idProperties.size() + 1);
+ for (Property property : idProperties) {
+ if (!newIdProperty.getName().equals(property.getName()))
newIdProperties.add(property);
+ }
+ newIdProperties.add(newIdProperty);
+ newIdProperties = Collections.unmodifiableList(newIdProperties);
+ return new LocationWithPathAndProperties(path, newIdProperties);
+ }
+ return Location.create(path, newIdProperty);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(Path)
+ */
+ @Override
+ public Location with( Path newPath ) {
+ if (newPath == null || this.getPath().equals(newPath)) return this;
+ return Location.create(newPath, idProperties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(UUID)
+ */
+ @Override
+ public Location with( UUID uuid ) {
+ if (uuid == null) return this;
+ Property newProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
+ if (this.hasIdProperties()) {
+ Property existing = this.getIdProperty(DnaLexicon.UUID);
+ if (existing != null && existing.equals(newProperty)) return this;
+ }
+
+ List<Property> newIdProperties = new
ArrayList<Property>(idProperties.size() + 1);
+ newIdProperties.addAll(idProperties);
+ newIdProperties.add(newProperty);
+ return Location.create(path, newIdProperties);
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperties.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java
(from rev 733,
trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertyLocation.java)
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java
(rev 0)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java 2009-02-23
17:56:28 UTC (rev 734)
@@ -0,0 +1,182 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.graph;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.CheckArg;
+import org.jboss.dna.common.util.HashCode;
+import org.jboss.dna.graph.property.Name;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.basic.BasicSingleValueProperty;
+
+/**
+ * General purpose location type that supports a path and a property. This class should
never be directly instantiated by users of
+ * the DNA framework. Instead, use @{link Location#create} to create the correct
location.
+ *
+ * @see Location
+ */
+@Immutable
+class LocationWithPathAndProperty extends Location {
+
+ private final Path path;
+ private final List<Property> idProperties;
+
+ private final int hashCode;
+
+ /**
+ * Create a new location with a given path and identification property.
+ *
+ * @param path the path
+ * @param idProperty the identification property
+ */
+ LocationWithPathAndProperty( Path path,
+ Property idProperty ) {
+ assert idProperty != null;
+ assert !idProperty.isEmpty();
+ // The path could be null
+ this.path = path;
+ this.idProperties = Collections.singletonList(idProperty);
+
+ // Paths are immutable, Properties are immutable, the idProperties list
+ // is wrapped in an unmodifiableList by the Location factory methods...
+ // ... so we can cache the hash code.
+ hashCode = HashCode.compute(path, idProperties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getPath()
+ */
+ @Override
+ public final Path getPath() {
+ return path;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getIdProperties()
+ */
+ @Override
+ public final List<Property> getIdProperties() {
+ return idProperties;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#hasIdProperties()
+ */
+ @Override
+ public final boolean hasIdProperties() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getIdProperty(Name)
+ */
+ @Override
+ public final Property getIdProperty( Name name ) {
+ CheckArg.isNotNull(name, "name");
+ Property property = idProperties.get(0); // this is fast
+ return property.getName().equals(name) ? property : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#getUuid()
+ */
+ @Override
+ public UUID getUuid() {
+ Property property = idProperties.get(0); // this is fast
+ if (DnaLexicon.UUID.equals(property.getName())) {
+ Object value = property.getFirstValue();
+ if (value instanceof UUID) return (UUID)value;
+ if (value instanceof String) return UUID.fromString((String)value);
+ }
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(Property)
+ */
+ @Override
+ public Location with( Property newIdProperty ) {
+ if (newIdProperty == null || newIdProperty.isEmpty()) return this;
+ Property idProperty = idProperties.get(0); // fast
+ if (newIdProperty.getName().equals(idProperty.getName())) {
+ return path == null ? Location.create(newIdProperty) : Location.create(path,
newIdProperty);
+ }
+ return path == null ? Location.create(idProperty, newIdProperty) :
Location.create(path, idProperty, newIdProperty);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(Path)
+ */
+ @Override
+ public Location with( Path newPath ) {
+ if (newPath == null && path == null) return this;
+ if (path != null && (path.equals(newPath))) return this;
+ Property idProperty = idProperties.get(0); // fast
+ return Location.create(newPath, idProperty);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#with(UUID)
+ */
+ @Override
+ public Location with( UUID uuid ) {
+ if (uuid == null) return this;
+ Property idProperty = idProperties.get(0); // fast
+ if (DnaLexicon.UUID.equals(idProperty.getName())) {
+ return path == null ? Location.create(uuid) : Location.create(path, uuid);
+ }
+ Property newUuidProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
+ return path == null ? Location.create(idProperty, newUuidProperty) :
Location.create(path, idProperty, newUuidProperty);
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithPathAndProperty.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java
(rev 0)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java 2009-02-23
17:56:28 UTC (rev 734)
@@ -0,0 +1,145 @@
+/*
+ * JBoss DNA (
http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of
+ * individual contributors.
+ *
+ * Unless otherwise indicated, all code in JBoss DNA is licensed
+ * to you under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * JBoss DNA is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.dna.graph;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import net.jcip.annotations.Immutable;
+import org.jboss.dna.common.util.HashCode;
+import org.jboss.dna.graph.property.Path;
+import org.jboss.dna.graph.property.Property;
+import org.jboss.dna.graph.property.basic.BasicSingleValueProperty;
+
+/**
+ * Special location type optimized for use when only a {@link UUID} is specified. This
class should never be directly instantiated
+ * by users of the DNA framework. Instead, use @{link Location#create} to create the
correct location.
+ *
+ * @see Location
+ */
+@Immutable
+public class LocationWithUuid extends Location {
+
+ private final UUID uuid;
+ private final int hashCode;
+ private final List<Property> properties;
+
+ LocationWithUuid( UUID uuid ) {
+ assert uuid != null;
+ this.uuid = uuid;
+ Property uuidProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
+ this.properties = Collections.singletonList(uuidProperty);
+ this.hashCode = HashCode.compute(null, this.properties);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Location#getIdProperties()
+ */
+ @Override
+ public List<Property> getIdProperties() {
+ return properties;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Location#getPath()
+ */
+ @Override
+ public Path getPath() {
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see Location#hasIdProperties()
+ */
+ @Override
+ public final boolean hasIdProperties() {
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Location#hasPath()
+ */
+ @Override
+ public boolean hasPath() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Location#getUuid()
+ */
+ @Override
+ public UUID getUuid() {
+ return this.uuid;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Location#with(org.jboss.dna.graph.property.Property)
+ */
+ @Override
+ public Location with( Property newIdProperty ) {
+ return Location.create(getIdProperties().get(0), newIdProperty);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Location#with(org.jboss.dna.graph.property.Path)
+ */
+ @Override
+ public Location with( Path newPath ) {
+ return Location.create(newPath, uuid);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Location#with(java.util.UUID)
+ */
+ @Override
+ public Location with( UUID uuid ) {
+ return new LocationWithUuid(uuid);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.jboss.dna.graph.Location#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return hashCode;
+ }
+}
Property changes on:
trunk/dna-graph/src/main/java/org/jboss/dna/graph/LocationWithUuid.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathLocation.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathLocation.java 2009-02-23
15:55:50 UTC (rev 733)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathLocation.java 2009-02-23
17:56:28 UTC (rev 734)
@@ -1,178 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.graph;
-
-import java.util.List;
-import java.util.UUID;
-
-import net.jcip.annotations.Immutable;
-
-import org.jboss.dna.common.text.TextEncoder;
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.HashCode;
-import org.jboss.dna.graph.property.NamespaceRegistry;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.Property;
-import org.jboss.dna.graph.property.basic.BasicSingleValueProperty;
-
-/**
- * Special location type optimized for use when only a path is specified.
- * This class should never be directly instantiated by users of the DNA framework.
- * Instead, use @{link Location#create} to create the correct location.
- *
- * @see Location
- */
-@Immutable
-class PathLocation extends Location {
-
- private final Path path;
- private final int hashCode;
-
- PathLocation(Path path) {
- CheckArg.isNotNull(path, "path");
-
- this.path = path;
-
- // Paths are immutable, so PathLocations are immutable...
- // ... so we can cache the hash code.
- hashCode = HashCode.compute(path);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getPath()
- */
- @Override
- public final Path getPath() {
- return path;
- }
-
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hasPath()
- */
- @Override
- public final boolean hasPath() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getIdProperties()
- */
- @Override
- public final List<Property> getIdProperties() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hasIdProperties()
- */
- @Override
- public final boolean hasIdProperties() {
- return false;
- }
-
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getUuid()
- */
- @Override
- public final UUID getUuid() {
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hashCode()
- */
- @Override
- public int hashCode() {
- return hashCode;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getString(NamespaceRegistry, TextEncoder, TextEncoder)
- */
- @Override
- public String getString(NamespaceRegistry namespaceRegistry, TextEncoder encoder,
TextEncoder delimiterEncoder) {
- StringBuilder sb = new StringBuilder();
- sb.append("{ ");
- sb.append(path.getString(namespaceRegistry, encoder, delimiterEncoder));
- sb.append(" }");
- return sb.toString();
- }
-
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(Property)
- */
- @Override
- public Location with( Property newIdProperty ) {
- if (newIdProperty == null || newIdProperty.isEmpty()) return this;
- return Location.create(path, newIdProperty);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(Path)
- */
- @Override
- public Location with( Path newPath ) {
- if (newPath == null) return this;
- if (!this.getPath().equals(newPath)) return Location.create(newPath);
- return this;
- }
-
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(UUID)
- */
- @Override
- public Location with( UUID uuid ) {
- if (uuid == null) return this;
- Property newProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
- if (this.hasIdProperties()) {
- Property existing = this.getIdProperty(DnaLexicon.UUID);
- if (existing != null && existing.equals(newProperty)) return this;
- }
- return Location.create(path, uuid);
- }
-}
Deleted: trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertiesLocation.java
===================================================================
---
trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertiesLocation.java 2009-02-23
15:55:50 UTC (rev 733)
+++
trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertiesLocation.java 2009-02-23
17:56:28 UTC (rev 734)
@@ -1,173 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.graph;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
-import net.jcip.annotations.Immutable;
-
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.HashCode;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.Property;
-import org.jboss.dna.graph.property.basic.BasicSingleValueProperty;
-
-/**
- * General purpose location type that supports a path and zero or more properties.
- * This class should never be directly instantiated by users of the DNA framework.
- * Instead, use @{link Location#create} to create the correct location.
- *
- * @see Location
- */
-@Immutable
-class PathPropertiesLocation extends Location {
-
- private final Path path;
- private final List<Property> idProperties;
-
- private final int hashCode;
-
- /**
- * Create a new location with a given path and set of identification properties.
- *
- * @param path the path
- * @param idProperties the identification properties
- */
- PathPropertiesLocation( Path path, List<Property> idProperties ) {
- // The path could be null
- // CheckArg.isNotNull(path, "path");
- // If the properties are a null, a PathLocation should be used instead.
- CheckArg.isNotNull(idProperties, "idProperties");
-
- this.path = path;
- this.idProperties = Collections.unmodifiableList(idProperties);
-
- // Paths are immutable, Properties are immutable, the idProperties list
- // is wrapped in an unmodifiableList by the Location factory methods...
- // ... so we can cache the hash code.
-
- hashCode = HashCode.compute(path, idProperties);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getPath()
- */
- @Override
- public final Path getPath() {
- return path;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getIdProperties()
- */
- @Override
- public final List<Property> getIdProperties() {
- return idProperties;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hasIdProperties()
- */
- @Override
- public final boolean hasIdProperties() {
- return idProperties.size() > 0;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hashCode()
- */
- @Override
- public int hashCode() {
- return hashCode;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(Property)
- */
- @Override
- public Location with( Property newIdProperty ) {
- if (newIdProperty == null || newIdProperty.isEmpty()) return this;
-
- List<Property> newIdProperties;
-
- if (hasIdProperties()) {
- newIdProperties = new ArrayList<Property>(idProperties.size() + 1);
- for (Property property : idProperties) {
- if (!newIdProperty.getName().equals(property.getName()))
newIdProperties.add(property);
- }
- newIdProperties.add(newIdProperty);
- newIdProperties = Collections.unmodifiableList(newIdProperties);
- } else {
- return Location.create(path, newIdProperty);
- }
-
- return new PathPropertiesLocation(path, newIdProperties);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(Path)
- */
- @Override
- public Location with( Path newPath ) {
- if (newPath == null) return this;
- if (!this.getPath().equals(newPath)) return Location.create(newPath,
idProperties);
- return this;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(UUID)
- */
- @Override
- public Location with( UUID uuid ) {
- if (uuid == null) return this;
- Property newProperty = new BasicSingleValueProperty(DnaLexicon.UUID, uuid);
- if (this.hasIdProperties()) {
- Property existing = this.getIdProperty(DnaLexicon.UUID);
- if (existing != null && existing.equals(newProperty)) return this;
- }
-
- List<Property> newIdProperties = new
ArrayList<Property>(idProperties.size() + 1);
- newIdProperties.addAll(idProperties);
- newIdProperties.add(newProperty);
-
- return Location.create(path, newIdProperties);
- }
-}
Deleted: trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertyLocation.java
===================================================================
--- trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertyLocation.java 2009-02-23
15:55:50 UTC (rev 733)
+++ trunk/dna-graph/src/main/java/org/jboss/dna/graph/PathPropertyLocation.java 2009-02-23
17:56:28 UTC (rev 734)
@@ -1,197 +0,0 @@
-/*
- * JBoss DNA (
http://www.jboss.org/dna)
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- * See the AUTHORS.txt file in the distribution for a full listing of
- * individual contributors.
- *
- * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
- * is licensed to you under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * JBoss DNA is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.dna.graph;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-
-import net.jcip.annotations.Immutable;
-
-import org.jboss.dna.common.util.CheckArg;
-import org.jboss.dna.common.util.HashCode;
-import org.jboss.dna.graph.property.Name;
-import org.jboss.dna.graph.property.Path;
-import org.jboss.dna.graph.property.Property;
-import org.jboss.dna.graph.property.basic.BasicSingleValueProperty;
-
-/**
- * General purpose location type that supports a path and a property.
- * This class should never be directly instantiated by users of the DNA framework.
- * Instead, use @{link Location#create} to create the correct location.
- *
- * @see Location
- */
-@Immutable
-class PathPropertyLocation extends Location {
-
- private final Path path;
- private final Property idProperty;
- private final List<Property> idProperties;
-
- private final int hashCode;
-
- /**
- * Create a new location with a given path and identification property.
- *
- * @param path the path
- * @param idProperty the identification property
- */
- PathPropertyLocation( Path path, Property idProperty ) {
- // The path could be null
- // CheckArg.isNotNull(path, "path");
- // If the properties are a null, a PathLocation should be used instead.
- CheckArg.isNotNull(idProperty, "idProperty");
-
- this.path = path;
- this.idProperty = idProperty;
- this.idProperties = Collections.singletonList(idProperty);
-
- // Paths are immutable, Properties are immutable, the idProperties list
- // is wrapped in an unmodifiableList by the Location factory methods...
- // ... so we can cache the hash code.
-
- hashCode = HashCode.compute(path, idProperties);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getPath()
- */
- @Override
- public final Path getPath() {
- return path;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getIdProperties()
- */
- @Override
- public final List<Property> getIdProperties() {
- return idProperties;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hasIdProperties()
- */
- @Override
- public final boolean hasIdProperties() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getIdProperty(Name)
- */
- @Override
- public final Property getIdProperty( Name name ) {
- CheckArg.isNotNull(name, "name");
- if (idProperty.getName().equals(name)) return idProperty;
-
- return null;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#getUuid()
- */
- @Override
- public UUID getUuid() {
- if (DnaLexicon.UUID.equals(idProperty.getName())) {
- Object value = idProperty.getFirstValue();
- if (value instanceof UUID) return (UUID)value;
- }
- return null;
- }
-
-
- /**
- * {@inheritDoc}
- *
- * @see Location#hashCode()
- */
- @Override
- public int hashCode() {
- return hashCode;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(Property)
- */
- @Override
- public Location with( Property newIdProperty ) {
- if (newIdProperty == null || newIdProperty.isEmpty()) return this;
-
- // A new property with same name overrides the old property with the same name
- if (newIdProperty.getName().equals(idProperty.getName())) return
Location.create(path, newIdProperty);
-
- List<Property> newIdProperties = new ArrayList<Property>(2);
- newIdProperties.add(idProperty);
- newIdProperties.add(newIdProperty);
-
- return Location.create(path, newIdProperties);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(Path)
- */
- @Override
- public Location with( Path newPath ) {
- if (newPath == null && path == null) return this;
- if (path != null && (path.equals(newPath))) return this;
-
- return Location.create(newPath, idProperty);
- }
-
- /**
- * {@inheritDoc}
- *
- * @see Location#with(UUID)
- */
- @Override
- public Location with( UUID uuid ) {
- if (uuid == null) return this;
-
- // A new property with same name overrides the old property with the same name
- if (idProperty.getName().equals(DnaLexicon.UUID)) return Location.create(path,
uuid);
-
- List<Property> newIdProperties = new ArrayList<Property>(2);
- newIdProperties.add(idProperty);
- newIdProperties.add(new BasicSingleValueProperty(DnaLexicon.UUID, uuid));
-
- return Location.create(path, newIdProperties);
- }
-}