001package basics.hashmutable;
002import java.util.Date;
003import java.util.Hashtable;
004// example from http://www.vipan.com/htdocs/hashcode_help.html
005public class Main {
006        public static void main (String[] args) {
007                //stdlib.Trace.graphvizShowSteps (true); stdlib.Trace.run ();
008
009                Hashtable<Date,String> map = new Hashtable<Date,String>();
010                long time = System.currentTimeMillis();
011                Date dt1 = new Date(time);
012                Date dt2 = new Date(time);
013                map.put(dt1, "blah");
014
015                System.out.println("dt1.toString() = " + dt1.toString());
016                System.out.println("dt2.toString() = " + dt2.toString());
017                System.out.println("Is dt2.equals(dt)? = " + dt2.equals(dt1));
018                System.out.println("map.get(dt1) = " + map.get(dt1) );
019                System.out.println("map.get(dt2) = " + map.get(dt2) );
020
021                // Change dt by adding a day to its time
022                dt1.setTime(time + 24*60*60*1000L);
023
024                System.out.println("\nAfter dt.setTime(newTime):");
025                System.out.println("dt1.toString() = " + dt1.toString());
026                System.out.println("dt2.toString() = " + dt2.toString());
027                System.out.println("Is dt2.equals(dt)? = " + dt2.equals(dt1));
028                System.out.println("map.get(dt1) = " + map.get(dt1) );
029                System.out.println("map.get(dt2) = " + map.get(dt2) );
030
031                //System.out.println("\nmap = " + map.toString() );
032        }
033}