[jboss-cvs] JBossCache/src/org/jboss/cache ...

Manik Surtani manik at jboss.org
Mon Mar 12 17:17:05 EDT 2007


  User: msurtani
  Date: 07/03/12 17:17:05

  Modified:    src/org/jboss/cache  Fqn.java
  Log:
  refactorings
  
  Revision  Changes    Path
  1.51      +20 -49    JBossCache/src/org/jboss/cache/Fqn.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Fqn.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Fqn.java,v
  retrieving revision 1.50
  retrieving revision 1.51
  diff -u -b -r1.50 -r1.51
  --- Fqn.java	12 Mar 2007 18:13:46 -0000	1.50
  +++ Fqn.java	12 Mar 2007 21:17:05 -0000	1.51
  @@ -58,7 +58,7 @@
    * Another way to look at it is that the "/" separarator is only parsed when it forms
    * part of a String passed in to Fqn.fromString() and not otherwise.
    *
  - * @version $Revision: 1.50 $
  + * @version $Revision: 1.51 $
    */
   @Immutable
   public class Fqn<E> implements Cloneable, Externalizable, Comparable<Fqn>
  @@ -79,7 +79,7 @@
      private static Log log = LogFactory.getLog(Fqn.class);
   
      /**
  -    * Constructs a root FQN.
  +    * Constructs a root Fqn
       */
      public Fqn()
      {
  @@ -87,18 +87,6 @@
      }
   
      /**
  -    * Constructs a single element Fqn.  Note that if a String is passed in, separator characters {@link #SEPARATOR} are <b>not</b> parsed.
  -    * If you wish these to be parsed, use {@link #fromString(String)}.
  -    *
  -    * @param name the name of the node identified by the Fqn
  -    * @see #fromString(String)
  -    */
  -   public Fqn(E name)
  -   {
  -      elements = Collections.singletonList(name);
  -   }
  -
  -   /**
       * Constructs a FQN from a list of names.
       *
       * @param names List of names
  @@ -107,7 +95,7 @@
      {
         if (names != null)
         {
  -         elements = new ArrayList<E>(names);
  +         elements = Collections.unmodifiableList(new ArrayList<E>(names));
         }
         else
         {
  @@ -122,13 +110,13 @@
       */
      public Fqn(E... names)
      {
  -      if (names == null)
  +      if (names != null)
         {
  -         elements = Collections.emptyList();
  +         elements = Collections.unmodifiableList(Arrays.asList(names));
         }
         else
         {
  -         elements = Arrays.asList(names);
  +         elements = Collections.emptyList();
         }
      }
   
  @@ -151,9 +139,10 @@
       */
      public Fqn(Fqn<E> base, List<E> relative)
      {
  -      elements = new ArrayList<E>(base.elements.size() + relative.size());
  +      List<E> elements = new ArrayList<E>(base.elements.size() + relative.size());
         elements.addAll(base.elements);
         elements.addAll(relative);
  +      this.elements = Collections.unmodifiableList(elements);
      }
   
      /**
  @@ -164,20 +153,10 @@
       */
      public Fqn(Fqn<E> base, E... childNames)
      {
  -      elements = new ArrayList<E>(base.elements.size() + childNames.length);
  +      List<E> elements = new ArrayList<E>(base.elements.size() + childNames.length);
         elements.addAll(base.elements);
  -      for (E relative : childNames) elements.add(relative);
  -   }
  -
  -   /**
  -    * Construct from an unmodifiable list.
  -    * For internal use.
  -    */
  -   private static <T> Fqn<T> createFqn(List<T> list)
  -   {
  -      Fqn<T> fqn = new Fqn<T>();
  -      fqn.elements = list;
  -      return fqn;
  +      elements.addAll(Arrays.asList(childNames));
  +      this.elements = Collections.unmodifiableList(elements);
      }
   
      /**
  @@ -185,15 +164,15 @@
       * one or more separator ({@link #SEPARATOR}) characters.<br><br>
       * Example use:<br>
       * <pre>
  -    * Fqn.fromString("/a//b/c/");
  +    * Fqn.fromString("/a/b/c/");
       * </pre><br>
       * is equivalent to:<br>
       * <pre>
  -    * new Fqn<String>(new String[] { "a", "b", "c" });
  +    * new Fqn("a", "b", "c");
       * </pre><br>
       * but not<br>
       * <pre>
  -    * new Fqn<String>("/a/b/c");
  +    * new Fqn("/a/b/c");
       * </pre>
       *
       * @param stringRepresentation String representation of the Fqn
  @@ -204,20 +183,12 @@
      {
         if (stringRepresentation == null)
         {
  -         return ROOT;
  +         return Fqn.ROOT;
         }
  -      return createFqn(parse(stringRepresentation));
  -   }
  -
  -   private static List<String> parse(String stringRepresentation)
  -   {
         List<String> list = new ArrayList<String>();
         StringTokenizer tok = new StringTokenizer(stringRepresentation, SEPARATOR);
  -      while (tok.hasMoreTokens())
  -      {
  -         list.add(tok.nextToken());
  -      }
  -      return list;
  +      while (tok.hasMoreTokens()) list.add(tok.nextToken());
  +      return new Fqn<String>(list);
      }
   
      /**
  @@ -254,7 +225,7 @@
       */
      public Fqn<E> getSubFqn(int startIndex, int endIndex)
      {
  -      return createFqn(elements.subList(startIndex, endIndex));
  +      return new Fqn<E>(elements.subList(startIndex, endIndex));
      }
   
      /**
  @@ -473,7 +444,7 @@
            case 1:
               return ROOT;
            default:
  -            return createFqn(elements.subList(0, elements.size() - 1));
  +            return new Fqn<E>(elements.subList(0, elements.size() - 1));
         }
      }
   
  @@ -512,7 +483,7 @@
       */
      public List<E> peekElements()
      {
  -      return Collections.unmodifiableList(elements);
  +      return elements;
      }
   
      /**
  
  
  



More information about the jboss-cvs-commits mailing list