[jboss-cvs] jboss-portal/portlet/src/main/org/jboss/portal/portlet/state ...

Julien Viet julien at jboss.com
Tue Aug 22 08:33:28 EDT 2006


  User: julien  
  Date: 06/08/22 08:33:28

  Modified:    portlet/src/main/org/jboss/portal/portlet/state 
                        PropertyChange.java
  Log:
  make the PropertyChange instances created via factory methods
  
  Revision  Changes    Path
  1.2       +47 -53    jboss-portal/portlet/src/main/org/jboss/portal/portlet/state/PropertyChange.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: PropertyChange.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-portal/portlet/src/main/org/jboss/portal/portlet/state/PropertyChange.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- PropertyChange.java	20 Apr 2006 12:56:47 -0000	1.1
  +++ PropertyChange.java	22 Aug 2006 12:33:28 -0000	1.2
  @@ -24,96 +24,90 @@
   import org.jboss.portal.common.value.Value;
   
   /**
  - * A preference change.
  + * A property change. The class is immutable
    *
    * @author <a href="mailto:julien at jboss.org">Julien Viet</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class PropertyChange
   {
   
  -   /**
  -    *
  -    */
  -   public static final int PREF_SET = 0;
  +   /** The change is an update of the property value. */
  +   public static final int PREF_UPDATE = 0;
   
  -   /**
  -    *
  -    */
  +   /** The change is a reset of the property value. */
      public static final int PREF_RESET = 1;
   
  -   /**
  -    * The type of change.
  -    */
  -   private int type;
  +   /** The key. */
  +   private final String key;
  +
  +   /** The value. */
  +   private final Value value;
   
      /**
  -    * The key.
  +    * Create a new property update.
  +    *
  +    * @param key the property key
  +    * @param value the property value
  +    * @return an instance representing a property update
       */
  -   private String key;
  +   public static PropertyChange newUpdate(String key, Value value)
  +   {
  +      if (value == null)
  +      {
  +         throw new IllegalArgumentException("No value provided");
  +      }
  +      return new PropertyChange(key, value);
  +   }
   
      /**
  -    * The possible value.
  +    * Create a new property reset.
  +    *
  +    * @param key the property key
  +    * @return an instance representing a property reset
       */
  -   private Value value;
  +   public static PropertyChange newReset(String key)
  +   {
  +      return new PropertyChange(key, null);
  +   }
   
  -   public PropertyChange(int type, String key, Value value)
  +   private PropertyChange(String key, Value value)
      {
         if (key == null)
         {
            throw new IllegalArgumentException("No key provided");
         }
  -      switch (type)
  -      {
  -         case PREF_SET:
  -            if (value == null)
  -            {
  -               throw new IllegalArgumentException("Must provide value when adding the preference " + key);
  -            }
  -            break;
  -         case PREF_RESET:
  -            if (value != null)
  -            {
  -               throw new IllegalArgumentException("Must not provide value when updating the preference " + key);
  -            }
  -            this.value = value;
  -            break;
  -         default:
  -            throw new IllegalArgumentException("Unrecognized change type " + type + " for preference " + key);
  -      }
  -      this.type = type;
         this.key = key;
         this.value = value;
      }
   
  +   /**
  +    * Return the property change type.
  +    *
  +    * @return the proeprty change type
  +    */
      public int getType()
      {
  -      return type;
  +      return value == null ? PREF_RESET : PREF_UPDATE;
      }
   
  +   /**
  +    * Return the property key
  +    *
  +    * @return the property key
  +    */
      public String getKey()
      {
         return key;
      }
   
  +   /**
  +    * Return the new value or null in case of a property reset.
  +    *
  +    * @return the property value
  +    */
      public Value getValue()
      {
         return value;
      }
  -
  -   public void asSet(Value value)
  -   {
  -      if (value == null)
  -      {
  -         throw new IllegalArgumentException("No value provided for added");
  -      }
  -      this.type = PREF_SET;
  -      this.value = value;
  -   }
  -
  -   public void asReset()
  -   {
  -      this.type = PREF_RESET;
  -      this.value = null;
  -   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list