Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.pc.mylib » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software 
   12    * distributed under the License is distributed on an "AS IS" BASIS, 
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
   14    * See the License for the specific language governing permissions and 
   15    * limitations under the License.
   16    */
   17    
   18   package org.apache.jdo.tck.pc.mylib;
   19   
   20   import java.io.Serializable;
   21   import java.util.Date;
   22   
   23   /**
   24   * Test for instances with application identity containing instances of 
   25   * a user-defined class.
   26   *
   27   * @author Marina Vatkina
   28   */
   29   public class PCRect {
   30       
   31       private static long counter = new Date().getTime();
   32       private static long newId() {
   33           synchronized (PCRect.class) {
   34               return counter++;
   35           }
   36       }
   37   
   38       public long id = newId();
   39   
   40       public PCPoint upperLeft;
   41       public PCPoint lowerRight;
   42   
   43       public PCRect() { }
   44   
   45       public PCRect(long id, PCPoint ul, PCPoint lr) {
   46           upperLeft = ul;
   47           lowerRight = lr;
   48       }
   49   
   50       public PCRect(PCPoint ul, PCPoint lr) {
   51           upperLeft = ul;
   52           lowerRight = lr;
   53       }
   54   
   55       public PCPoint getUpperLeft() {
   56           return upperLeft;
   57       }
   58   
   59       public PCPoint getLowerRight() {
   60           return lowerRight;
   61       }
   62   
   63       public long getId() {
   64           return id;
   65       }
   66   
   67       public void setId(long id) {
   68           this.id = id;
   69       }
   70   
   71       public String toString() {
   72           String rc = null;
   73   	Object obj = this;
   74           try {
   75               //rc = Util.getClassName(this)
   76   	     rc = obj.getClass().getName()
   77                   + " ul: " + getUpperLeft().name()
   78                   + " lr: " + getLowerRight().name();
   79           } catch (NullPointerException ex) {
   80               rc = "NPE getting PCRect's values";
   81           }
   82           return rc;
   83       }
   84   
   85       public static class Oid implements Serializable {
   86           public long id;
   87   
   88           public Oid() {
   89           }
   90   
   91           public Oid(String s) { id = Long.parseLong(justTheId(s)); }
   92   
   93           public String toString() { return this.getClass().getName() + ": "  + id;}
   94   
   95           public int hashCode() { return (int)id ; }
   96   
   97           public boolean equals(Object other) {
   98               if (other != null && (other instanceof Oid)) {
   99                   Oid k = (Oid)other;
  100                   return k.id == this.id;
  101               }
  102               return false;
  103           }
  104           
  105           protected static String justTheId(String str) {
  106               return str.substring(str.indexOf(':') + 1);
  107           }
  108   
  109       }
  110   
  111   }

Home » jdo2-tck-2.3-ea-src » org.apache.jdo.tck.pc.mylib » [javadoc | source]