1 package org.apache.torque.om; 2 3 21 22 import java.util.Date ; 23 24 31 public class DateKey extends SimpleKey 32 { 33 36 private static final long serialVersionUID = 3102583536685348517L; 37 38 42 public DateKey() 43 { 44 } 45 46 53 public DateKey(String key) 54 { 55 this.key = new Date (Long.parseLong(key)); 56 } 57 58 63 public DateKey(Date key) 64 { 65 this.key = key; 66 } 67 68 73 public DateKey(DateKey key) 74 { 75 if (key != null) 76 { 77 this.key = key.getValue(); 78 } 79 else 80 { 81 this.key = null; 82 } 83 } 84 85 90 public void setValue(String key) 91 { 92 this.key = new Date (Long.parseLong(key)); 93 } 94 95 100 public void setValue(DateKey key) 101 { 102 if (key != null) 103 { 104 this.key = key.getValue(); 105 } 106 else 107 { 108 this.key = null; 109 } 110 } 111 112 117 public Date getDate() 118 { 119 return (Date ) key; 120 } 121 122 130 public boolean equals(Object keyObj) 131 { 132 boolean isEqual = false; 133 134 if (key != null) 135 { 136 if (keyObj instanceof String ) 137 { 138 isEqual = toString().equals(keyObj); 139 } 140 else if (keyObj instanceof DateKey) 143 { 144 Object obj = ((DateKey) keyObj).getValue(); 145 isEqual = key.equals(obj); 146 } 147 } 148 return isEqual; 149 } 150 151 157 public String toString() 158 { 159 Date dt = getDate(); 160 return (dt == null ? "" : Long.toString(dt.getTime())); 161 } 162 } 163 | Popular Tags |