commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosu...@apache.org
Subject cvs commit: jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples BeanAttribute.java Dependency.java RuntimeSample.java Sample.java Sample2.java SampleIF1.java SampleIF2.java SampleIFJoin.java SampleService.java SuperSample.java ThreadSafe.java
Date Sat, 11 Sep 2004 19:21:19 GMT
leosutic    2004/09/11 12:21:19

  Added:       attributes/unittest/src/test/org/apache/commons/attributes/test/samples
                        BeanAttribute.java Dependency.java
                        RuntimeSample.java Sample.java Sample2.java
                        SampleIF1.java SampleIF2.java SampleIFJoin.java
                        SampleService.java SuperSample.java ThreadSafe.java
  Log:
  Refactored samples.
  
  Revision  Changes    Path
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/BeanAttribute.java
  
  Index: BeanAttribute.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  import org.apache.commons.attributes.DefaultSealable;
  import org.apache.commons.attributes.Sealable;
  
  /**
   * A sample attribute with bean-like properties. Used to test the 
   * named parameter syntax.
   */
  public class BeanAttribute extends DefaultSealable {
      
      private final int number;
      private final String string;
      private String name;
      private int anotherNumber;
      
      public BeanAttribute (int number, String string) {
          this.number = number;
          this.string = string;
      }
      
      public int getNumber () {
          return number;
      }
      
      public String getString () {
          return string;
      }
      
      public String getName () {
          return name;
      }
      
      public int getAnotherNumber () {
          return anotherNumber;
      }
      
      public void setAnotherNumber (int anotherNumber) {
          checkSealed ();
          this.anotherNumber = anotherNumber;
      }
      
      public void setName (String name) {
          checkSealed ();
          this.name = name;
      }
      
      public boolean equals (Object o) {
          return o instanceof BeanAttribute &&
              ((BeanAttribute) o).string.equals (string) &&
              ((BeanAttribute) o).anotherNumber == anotherNumber &&
              ((BeanAttribute) o).number == number &&
              ((BeanAttribute) o).name.equals (name);
      }
      
      public int hashCode () {
          return string.hashCode ();
      }
      
      public String toString () {
          return "[BeanAttribute " + number + ", " + string + "; " + name + ", " + anotherNumber
+ "\"]";
      }
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/Dependency.java
  
  Index: Dependency.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  /**
   * Declares a dependency.
   * 
   * @@org.apache.commons.attributes.Inheritable()
   */
  public class Dependency {
      
      private final Class clazz;
      private final String name;
      
      public Dependency (Class clazz, String name) {
          this.clazz = clazz;
          this.name = name;
      }
      
      public Class getDependencyClass () {
          return clazz;
      }
      
      public String getDependencyName () {
          return name;
      }
      
      public boolean equals (Object o) {
          return o instanceof Dependency &&
              ((Dependency) o).clazz == clazz &&
              ((Dependency) o).name.equals (name);
      }
      
      public int hashCode () {
          return clazz.hashCode () ^ name.hashCode ();
      }
      
      public String toString () {
          return "[Dependency on " + clazz.getName () + " via name \"" + name + "\"]";
      }
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/RuntimeSample.java
  
  Index: RuntimeSample.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  import org.apache.commons.attributes.Attributes;
  import org.apache.commons.attributes.RuntimeAttributeRepository;
  
  public class RuntimeSample extends SuperSample implements SampleIFJoin {
      
      static {
          try {
              RuntimeAttributeRepository rar = new RuntimeAttributeRepository (RuntimeSample.class);
              rar.addClassAttribute (new ThreadSafe ());
              rar.addClassAttribute (new Dependency ( SampleService.class, "sample" ));
              
              rar.addFieldAttribute ("field", new ThreadSafe ());
              
              rar.addMethodAttribute ("someMethod", new Class[]{}, new Dependency ( SampleService.class,
"sample-some-method1" ));
              
              rar.addParameterAttribute ("methodWithAttributes", new Class[]{ Integer.TYPE,
Integer.TYPE }, 1, new ThreadSafe ());
              rar.addReturnAttribute ("methodWithAttributes", new Class[]{ Integer.TYPE, Integer.TYPE
}, new Dependency ( SampleService.class, "sample-return" ));
              
              rar.addMethodAttribute ("someMethod", new Class[]{ Integer.TYPE }, new Dependency
( SampleService.class, "sample-some-method2" ));
              
              BeanAttribute ba = new BeanAttribute (1, "a");
              ba.setAnotherNumber (56 - 14);
              ba.setName ("Smith, John \"Agent\"");
              rar.addMethodAttribute ("methodWithNamedParameters", new Class[]{}, ba);
              
              rar.addMethodAttribute ("privateMethod", new Class[]{}, new Dependency ( SampleService.class,
"sample-privateMethod" ));
              
              Attributes.setAttributes (rar);
          } catch (Exception e) {
              throw new Error ("Unable to set attribute information: " + e.toString ());
          }
      }
      
      public Object field;
      
      public Object noAttributesInSubClass;
      
      public void someMethod () {
          
      }
  
      public Integer methodWithAttributes (int param1, int param2) {
          return null;
      }
      
      public void someMethod (int parameter) {
          
      }
      
      public void methodWithNamedParameters () {
          
      }
      
      public void methodWithNoAttributes () {
      }
      
      private void privateMethod () {
      }
      
      public static class InnerSample {
          static {
              try {
                  RuntimeAttributeRepository rar = new RuntimeAttributeRepository (RuntimeSample.InnerSample.class);
                  rar.addClassAttribute (new Dependency ( SampleService.class, "inner-sample"
));
                  Attributes.setAttributes (rar);
              } catch (Exception e) {
                  throw new Error ("Unable to set attribute information: " + e.toString ());
              }
          }
      }
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/Sample.java
  
  Index: Sample.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  /**
   * @@ThreadSafe ()
   * @@Dependency ( SampleService.class, "sample" )
   */
  public class Sample extends SuperSample implements SampleIFJoin {
      
      /**
       * @@ThreadSafe ()
       */
      public Object field;
      
      public Object noAttributesInSubClass;
      
      /**
       * @@Dependency ( SampleService.class, "sample-some-method1" )
       */
      public void someMethod () {
          
      }
  
      /**
       * @@.param2 ThreadSafe ()
       * @@.return Dependency ( SampleService.class, "sample-return" )
       */
      public Integer methodWithAttributes (int param1, int param2) {
          return null;
      }
      
      /**
       * @@Dependency ( SampleService.class, "sample-some-method2" )
       */
      public void someMethod (int parameter) {
          
      }
      
      /**
       * @@BeanAttribute ( 1, "a", anotherNumber = (56 - 14), name = "Smith, John \"Agent\""
)
       */
      public void methodWithNamedParameters () {
          
      }
      
      public void methodWithNoAttributes () {
      }
      
      /**
       * @@Dependency ( SampleService.class, "inner-sample" )
       */
      public static class InnerSample {
      }
      
      /**
       * @@Dependency ( SampleService.class, "sample-privateMethod" )
       */
      private void privateMethod () {
          
      }
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/Sample2.java
  
  Index: Sample2.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  public class Sample2 {
      
  
      public Object aaaa;
   
      
  
      public Sample2 () {
          
      }
  
      public Sample2 (String input) {
          
      }
      
  
      public void someMethod () {
          
      }
  
      public void someMethod (int parameter) {
          
      }
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/SampleIF1.java
  
  Index: SampleIF1.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  /**
   * @@Dependency ( SampleService.class, "sample-if-1-c" )
   */
  public interface SampleIF1 {
      
      /**
       * @@Dependency ( SampleService.class, "sample-if-1" )
       * @@ThreadSafe ()
       */
      public void someMethod (int parameter);
      
      /**
       * @@.return Dependency ( SampleService.class, "sample-if-return" )
       * @@.param2 Dependency ( SampleService.class, "sample-if-param-2" )
       */
      public Integer methodWithAttributes (int param1, int param2);
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/SampleIF2.java
  
  Index: SampleIF2.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  /**
   * @@Dependency ( SampleService.class, "sample-if-2-c" )
   */
  public interface SampleIF2 {
      
      /**
       * @@Dependency ( SampleService.class, "sample-if-2" )
       * @@ThreadSafe ()
       */
      public void someMethod (int parameter);
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/SampleIFJoin.java
  
  Index: SampleIFJoin.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  public interface SampleIFJoin extends SampleIF1, SampleIF2 {
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/SampleService.java
  
  Index: SampleService.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  public interface SampleService {}
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/SuperSample.java
  
  Index: SuperSample.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  /**
   * @@Dependency ( SampleService.class, "super-sample" )
   */
  public class SuperSample {
      
      /**
       * @@ThreadSafe ()
       * @@Dependency ( SampleService.class, "super-field" )
       */
      public Object field;
      
      /**
       * @@Dependency ( SampleService.class, "super-noattrs" )
       */
      public Object noAttributesInSubClass;
      
      /**
       * @@Dependency ( SampleService.class, "sample-ctor1" )
       */
      public SuperSample () {
          
      }
      
      /**
       * @@Dependency ( SampleService.class, "sample-ctor2" )
       * @@.array ThreadSafe()
       */
      public SuperSample (String input, String[][] array) {
          
      }
      
      /**
       * @@Dependency ( SampleService.class, "super-some-method-sample" )
       * @@ThreadSafe ()
       */
      public void someMethod (int parameter) {
          
      }
      
      /**
       * @@Dependency ( SampleService.class, "super-privateMethod" )
       */
      private void privateMethod () {
          
      }
      
  }
  
  
  1.1                  jakarta-commons/attributes/unittest/src/test/org/apache/commons/attributes/test/samples/ThreadSafe.java
  
  Index: ThreadSafe.java
  ===================================================================
  /*
   * Copyright 2003-2004 The Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.commons.attributes.test.samples;
  
  public class ThreadSafe {
      
      public ThreadSafe () {
      }
      
      public boolean equals (Object o) {
          return o instanceof ThreadSafe;
      }
      
      public int hashCode () {
          return 0;
      }
      
      public String toString () {
          return "[ThreadSafe]";
      }
  }
  
  

---------------------------------------------------------------------
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