commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator/util FlagsTest.java
Date Sat, 17 Jan 2004 17:32:28 GMT
dgraham     2004/01/17 09:32:28

  Modified:    validator/src/share/org/apache/commons/validator/util
                        Flags.java
               validator/src/test/org/apache/commons/validator/util
                        FlagsTest.java
  Log:
  Added Flags.clear() method and test, javadoc changes, throw 
  RuntimeException if clone fails instead of InternalError.
  
  Revision  Changes    Path
  1.6       +25 -20    jakarta-commons/validator/src/share/org/apache/commons/validator/util/Flags.java
  
  Index: Flags.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/util/Flags.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Flags.java	11 Jan 2004 23:30:21 -0000	1.5
  +++ Flags.java	17 Jan 2004 17:32:28 -0000	1.6
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2001-2004 The Apache Software Foundation.  All rights
  + * Copyright (c) 2003-2004 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -64,19 +64,15 @@
   import java.io.Serializable;
   
   /**
  - * Represents a collection of 64 boolean (on/off) flags.  Individual flags are
  - * represented by powers of 2.  For example,<br/>
  + * Represents a collection of 64 boolean (on/off) flags.  Individual flags 
  + * are represented by powers of 2.  For example,<br/>
    * Flag 1 = 1<br/>
    * Flag 2 = 2<br/>
    * Flag 3 = 4<br/>
    * Flag 4 = 8<br/>
    * <p>
  - * There cannot be a flag with a value of 3 because that represents Flag 1 and Flag
  - * 2 both being on/true.
  - * </p>
  - * <p>
  - * Typically this class will be used in support of another class with constants
  - * and not directly by clients.
  + * There cannot be a flag with a value of 3 because that represents Flag 1 
  + * and Flag 2 both being on/true.
    * </p>
    */
   public class Flags implements Serializable {
  @@ -109,16 +105,16 @@
       }
   
       /**
  -     * Tests whether the given flag is on.  If the flag is not a power of 2 (ie. 3) this
  -     * tests whether the combination of flags is on.
  +     * Tests whether the given flag is on.  If the flag is not a power of 2 
  +     * (ie. 3) this tests whether the combination of flags is on.
        */
       public boolean isOn(long flag) {
           return (this.flags & flag) > 0;
       }
   
       /**
  -     * Tests whether the given flag is off.  If the flag is not a power of 2 (ie. 3) this
  -     * tests whether the combination of flags is off.
  +     * Tests whether the given flag is off.  If the flag is not a power of 2 
  +     * (ie. 3) this tests whether the combination of flags is off.
        */
       public boolean isOff(long flag) {
           return (this.flags & flag) == 0;
  @@ -146,9 +142,17 @@
       public void turnOffAll() {
           this.flags = 0;
       }
  +    
  +    /**
  +     * Turn off all flags.  This is a synonym for <code>turnOffAll()</code>.
  +     * @since Validator 1.1.1
  +     */
  +    public void clear() {
  +        this.flags = 0;
  +    }
   
       /**
  -     * Turn on all 32 flags.
  +     * Turn on all 64 flags.
        */
       public void turnOnAll() {
           this.flags = Long.MAX_VALUE;
  @@ -162,7 +166,7 @@
           try {
               return super.clone();
           } catch(CloneNotSupportedException e) {
  -            throw new InternalError("Couldn't clone Flags object.");
  +            throw new RuntimeException("Couldn't clone Flags object.");
           }
       }
   
  @@ -194,8 +198,9 @@
       }
   
       /**
  -     * Returns a 64 length String with the first flag on the right and the 64th flag on
  -     * the left.  A 1 indicates the flag is on, a 0 means it's off.
  +     * Returns a 64 length String with the first flag on the right and the 
  +     * 64th flag on the left.  A 1 indicates the flag is on, a 0 means it's 
  +     * off.
        */
       public String toString() {
           StringBuffer bin = new StringBuffer(Long.toBinaryString(this.flags));
  
  
  
  1.4       +11 -6     jakarta-commons/validator/src/test/org/apache/commons/validator/util/FlagsTest.java
  
  Index: FlagsTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/util/FlagsTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FlagsTest.java	11 Jan 2004 23:30:22 -0000	1.3
  +++ FlagsTest.java	17 Jan 2004 17:32:28 -0000	1.4
  @@ -77,10 +77,9 @@
   
   	/**
   	 * Constructor for FlagsTest.
  -	 * @param arg0
   	 */
  -	public FlagsTest(String arg0) {
  -		super(arg0);
  +	public FlagsTest(String name) {
  +		super(name);
   	}
   
   	public void testHashCode() {
  @@ -117,6 +116,12 @@
   		f.turnOffAll();
   		assertEquals(0, f.getFlags());
   	}
  +    
  +    public void testClear() {
  +        Flags f = new Flags(98432);
  +        f.clear();
  +        assertEquals(0, f.getFlags());
  +    }
   
   	public void testTurnOnAll() {
   		Flags f = new Flags();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message