[jboss-cvs] JBossAS SVN: r68924 - in projects/aop/branches/joinpoint_graph/aop/src: test/org/jboss/aop/joinpoint/graph/tree and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Jan 12 18:05:43 EST 2008


Author: flavia.rainone at jboss.com
Date: 2008-01-12 18:05:43 -0500 (Sat, 12 Jan 2008)
New Revision: 68924

Modified:
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/InternalNode.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/LeafNode.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/Node.java
   projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/Tree.java
   projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/TreeSearchTest.java
Log:
[JBAOP-503] Added single value search (without wildcards)

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/InternalNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/InternalNode.java	2008-01-12 19:16:05 UTC (rev 68923)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/InternalNode.java	2008-01-12 23:05:43 UTC (rev 68924)
@@ -99,12 +99,29 @@
          children.loadSlot(nextChar);
          if (!children.isSlotEmpty())
          {
-            /*return */children.getSlotContent().search(result, searchKey);
+            children.getSlotContent().search(result, searchKey);
          }
       }
-      //return result;
    }
    
+   public E searchValue(SearchKey searchKey)
+   {
+      char nextChar = searchKey.matches(super.keyPart);
+      if (nextChar == Flags.ALL)
+      {
+         throw new RuntimeException("Search key cannot contain wildcards");
+      }
+      if (nextChar != Flags.NEGATIVE)
+      {
+         children.loadSlot(nextChar);
+         if (!children.isSlotEmpty())
+         {
+            return children.getSlotContent().searchValue(searchKey);
+         }
+      }
+      return null;
+   }
+   
    public String toString()
    {
       return "(" + this.keyPart + ", " + this.children + ")";

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/LeafNode.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/LeafNode.java	2008-01-12 19:16:05 UTC (rev 68923)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/LeafNode.java	2008-01-12 23:05:43 UTC (rev 68924)
@@ -85,6 +85,16 @@
       return this;
    }
 
+   public E searchValue(SearchKey searchKey)
+   {
+      char nextChar = searchKey.matches(super.keyPart);
+      if (nextChar == Flags.POSITIVE)
+      {
+         return value;
+      }
+      return null;
+   }
+   
    public void search(Collection<E> result, SearchKey searchKey)
    {
       char nextChar = searchKey.matches(super.keyPart);

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/Node.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/Node.java	2008-01-12 19:16:05 UTC (rev 68923)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/Node.java	2008-01-12 23:05:43 UTC (rev 68924)
@@ -52,7 +52,7 @@
    }
    
    /**
-    * Searchs by <code>searchKey<code> on this node subtree.
+    * Searchs by all values that match {@code searchKey} in this node subtree.
     * 
     * @param searchKey represents a search element
     * @return a <code>Collection</code> of the objects identified by the keys
@@ -61,6 +61,16 @@
    public abstract void search(Collection<E> result, SearchKey searchKey);
    
    /**
+    * Searchs by the single value whose key equals {@code searchKey}.
+    * 
+    * @param searchKey a search key without wildcars, that identifies a single
+    *                  element in the tree.
+    * @return the object matched by {@code searchKey}. May be {@code null} if no such
+    *         object exists.
+    */
+   public abstract E searchValue(SearchKey searchKey);
+   
+   /**
     * Returns the identifier char of this node.
     * 
     * @return the char that identifies this node

Modified: projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/Tree.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/Tree.java	2008-01-12 19:16:05 UTC (rev 68923)
+++ projects/aop/branches/joinpoint_graph/aop/src/main/org/jboss/aop/joinpoint/graph/tree/Tree.java	2008-01-12 23:05:43 UTC (rev 68924)
@@ -104,23 +104,25 @@
       return state.search(searchKey);
    }
    
+   /**
+    * Returns {@code true} if the tree is empty.
+    * @return {@code true} if the tree is empty.
+    */
    public boolean isEmpty()
    {
 	   return this.root == null;
    }
-   // TODO create a node method for this type of search and test it.
-   public E searchElement(String elementName)
+
+   /**
+    * Searchs for a specific value, identified by {@code searchKey}.  
+    * @param searchKey the key that identifies the search value. Must not contain
+    *                  any wildcards
+    * @return the value identified by {@code searchKey}. May be {@code null} if there
+    *         is no such value.
+    */
+   public E searchValue(String searchKey)
    {
-	   Collection<E> elements = search(elementName);
-	   if (elements.isEmpty())
-	   {
-		   return null;
-	   }
-	   if (elements.size() > 1)
-	   {
-		   throw new RuntimeException("Element name shouldn't contain wildcards:" + elementName);
-	   }
-	   return elements.iterator().next();
+      return (E) state.searchElement(new SearchKey(searchKey));
    }
    
    /**
@@ -140,7 +142,7 @@
       
       /**
        * Performs a search in the tree.
-       * @see Tree#search(String)
+       * @see Tree#searchValue(String)
        */
       <E> Collection<E> search(SearchKey searchKey);
       
@@ -149,6 +151,12 @@
        * @see Tree#search(String, Collection)
        */
       <E> void search(SearchKey searchKey, Collection<E> result);
+      
+      /**
+       * Performs a search for a specific element in the tree.
+       * @see Tree#searchElement(String)
+       */
+      <E> E searchElement(SearchKey searchKey);
    }
 
    /**
@@ -161,7 +169,7 @@
    {
       public <E> void insert(InsertionKey insertionKey, E value)
       {
-         root = new LeafNode(insertionKey.toKeyPart(), value);
+         root = new LeafNode<E>(insertionKey.toKeyPart(), value);
          state = new NotEmptyState();
          
       }
@@ -172,6 +180,11 @@
       }
       
       public <E> void search(SearchKey searchKey, Collection<E> result) {}
+      
+      public <E> E searchElement(SearchKey searchKey)
+      {
+         return null;
+      }
    }   
 
    /**
@@ -200,6 +213,11 @@
          //return root.search(searchKey);
         root.search(result, searchKey);
       }
+      
+      public <E> E searchElement(SearchKey searchKey)
+      {
+         return (E) root.searchValue(searchKey);
+      }
    }
    
    public String toString()

Modified: projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/TreeSearchTest.java
===================================================================
--- projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/TreeSearchTest.java	2008-01-12 19:16:05 UTC (rev 68923)
+++ projects/aop/branches/joinpoint_graph/aop/src/test/org/jboss/aop/joinpoint/graph/tree/TreeSearchTest.java	2008-01-12 23:05:43 UTC (rev 68924)
@@ -1657,6 +1657,19 @@
       assertEquals(1, result.size());
       assertContent(result, "N1");
    }
+   
+   public void testComCompanyInternalStaticFactorySingleValue()
+   {
+      String value = tree.searchValue("com.company.internal.StaticFactory");
+      assertNotNull(value);
+      assertEquals(value, "N1");
+   }
+   
+   public void testComCompanyInternalStaticFactorSingleValue()
+   {
+      String value = tree.searchValue("com.company.internal.StaticFactor");
+      assertNull(value);
+   }
 
    public void testComCompAnyPackageClass30()
    {




More information about the jboss-cvs-commits mailing list