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   * A simple class with two fields for application identity
   25   *
   26   * @author Marina Vatkina
   27   */
   28   public class VersionedPCPoint implements Serializable {
   29       
   30       
   31       private static long counter = new Date().getTime();
   32       private static long newId() {
   33           synchronized (PCPoint.class) {
   34               return counter++;
   35           }
   36       }
   37       private long id = newId();
   38       public int x;
   39       public Integer y;
   40   
   41       public VersionedPCPoint() {
   42       }
   43   
   44       public VersionedPCPoint(int x, int y) {
   45           this.x = x;
   46           this.y = new Integer(y);
   47       }
   48   
   49       public VersionedPCPoint(int x, Integer y) {
   50           this.x = x;
   51           this.y = y;
   52       }
   53   
   54       public String toString() {
   55           String rc = null;
   56   	Object obj = this;
   57           try {
   58   	    rc = obj.getClass().getName();
   59               //rc = Util.getClassName(this) + name();
   60           } catch (NullPointerException ex) {
   61               rc = "NPE getting PCPoint's values";
   62           }
   63           return rc;
   64       }
   65   
   66       public void setX(int x) {
   67           this.x = x;
   68       }
   69   
   70       public int getX() {
   71           return x;
   72       }
   73   
   74       public void setY(Integer y) {
   75           this.y = y;
   76       }
   77   
   78       public Integer getY() {
   79           return y;
   80       }
   81       
   82       public String name() {
   83           return " x: " + getX() + ", y: " + getY().intValue();
   84       }
   85   
   86       public static class Oid implements Serializable {
   87           public long id;
   88   
   89           /** The name of the class of the target object.
   90           */
   91           public static String targetClassName = 
   92                   "org.apache.jdo.tck.pc.mylib.VersionedPCPoint"; 
   93   
   94           public Oid() {
   95           }
   96   
   97           public Oid(String s) { id = Long.parseLong(justTheId(s)); }
   98   
   99           public String toString() { return getTargetClassName() + ": "  + id;}
  100   
  101           public int hashCode() { return (int)id ; }
  102   
  103           public boolean equals(Object other) {
  104               if (other != null && (other instanceof Oid)) {
  105                   Oid k = (Oid)other;
  106                   return k.id == this.id;
  107               }
  108               return false;
  109           }
  110           
  111           protected static String justTheId(String str) {
  112               return str.substring(str.indexOf(':') + 1);
  113           }
  114   
  115           /** Return the target class name.
  116            * @return the target class name.
  117            */
  118           public String getTargetClassName() {
  119               return targetClassName;
  120           } 
  121   
  122       }   
  123   }

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