KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > timestamp > Timestamps


1 /*
2   Copyright (C) 2004 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

17
18 package org.objectweb.jac.aspects.timestamp;
19
20 import java.util.Hashtable JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map.Entry;
23 import java.io.File JavaDoc;
24
25 public class Timestamps {
26     Hashtable JavaDoc stamps = new Hashtable JavaDoc();
27
28     /**
29      * Set the stamp of an object to current time
30      * @see #touch(Object)
31      */

32     public void touch(Object JavaDoc object) {
33         stamps.put(object,new Long JavaDoc(System.currentTimeMillis()));
34     }
35
36     /**
37      * Gets the time an object was last modified, or 0.
38      *
39      * @param object the object whose timestamp you request
40      * @return if object is a file, obect.lastModified(), otherwise
41      * the stored timestamp for that object, or if 0 no timestamp is
42      * stored for it.
43      *
44      * @see #touch(Object)
45      */

46     public long getStamp(Object JavaDoc object) {
47         if (object instanceof File JavaDoc) {
48             return ((File JavaDoc)object).lastModified();
49         } else {
50             Long JavaDoc stamp = (Long JavaDoc)stamps.get(object);
51             if (stamp!=null) {
52                 return stamp.longValue();
53             } else {
54                 return 0;
55             }
56         }
57     }
58
59     /**
60      * Delete all timestamps
61      */

62     public void touchAll() {
63         Long JavaDoc time = new Long JavaDoc(System.currentTimeMillis());
64         Iterator JavaDoc i = stamps.entrySet().iterator();
65         while (i.hasNext()) {
66             Entry entry = (Entry)i.next();
67             entry.setValue(time);
68         }
69     }
70 }
71
Popular Tags