KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > YDate


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o;
22
23 import java.util.*;
24
25 import com.db4o.foundation.*;
26 import com.db4o.reflect.*;
27
28
29 final class YDate extends YLong
30 {
31     
32     private static final Date PROTO = new Date(0);
33     
34     public YDate(YapStream stream) {
35         super(stream);
36     }
37     
38     public Object JavaDoc coerce(ReflectClass claxx, Object JavaDoc obj) {
39         return canHold(claxx) ? obj : No4.INSTANCE;
40     }
41
42     public void copyValue(Object JavaDoc a_from, Object JavaDoc a_to){
43         try{
44             ((Date)a_to).setTime(((Date)a_from).getTime());
45         }catch(Exception JavaDoc e){
46         }
47     }
48     
49     public Object JavaDoc defaultValue(){
50         return PROTO;
51     }
52     
53     public int getID(){
54         return 10;
55     }
56     
57     public boolean indexNullHandling() {
58         return true;
59     }
60     
61     protected Class JavaDoc primitiveJavaClass(){
62         return null;
63     }
64     
65     Object JavaDoc primitiveNull(){
66         return null;
67     }
68     
69     Object JavaDoc read1(YapReader a_bytes){
70         return new Date(readLong(a_bytes));
71     }
72     
73     public void write(Object JavaDoc a_object, YapReader a_bytes){
74         // TODO: This is a temporary fix to prevent exceptions with
75
// Marshaller.LEGACY.
76
if(a_object == null){
77             a_object = new Date(0);
78         }
79         a_bytes.writeLong(((Date)a_object).getTime());
80     }
81     
82     public Object JavaDoc current1(){
83         return new Date(currentLong());
84     }
85     
86     static String JavaDoc now(){
87         return Platform4.format(new Date(), true);
88     }
89     
90     long val(Object JavaDoc obj){
91         return ((Date)obj).getTime();
92     }
93     
94     boolean isEqual1(Object JavaDoc obj){
95         return obj instanceof Date && val(obj) == currentLong();
96     }
97     
98     boolean isGreater1(Object JavaDoc obj){
99         return obj instanceof Date && val(obj) > currentLong();
100     }
101     
102     boolean isSmaller1(Object JavaDoc obj){
103         return obj instanceof Date && val(obj) < currentLong();
104     }
105     
106     
107 }
108
Popular Tags