Main Page   Packages   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Statistics.java

00001 package gov.nasa.arc.ase.util;
00002 
00003 import java.io.PrintStream;
00004 import java.util.*;
00005 
00006 public class Statistics {
00007   private Hashtable ht = new Hashtable();
00008 
00009   public Object get(Category c) {
00010     if(ht.containsKey(c))
00011       return ht.get(c);
00012     return null;
00013   }  
00014   public Object get(String s) {
00015     return get(new Category(s));
00016   }  
00017   public void print() {
00018     List l = new ArrayList(ht.entrySet());
00019     Collections.sort(l, new Comparator() {
00020       public int compare(Object obj1, Object obj2) {
00021         Map.Entry m1 = (Map.Entry)obj1;
00022         Map.Entry m2 = (Map.Entry)obj2;
00023 
00024         return ((Comparable)m1.getKey()).compareTo(m2.getKey());
00025       }
00026     });
00027 
00028     Category last = null;
00029 
00030     for(Iterator i = l.iterator(); i.hasNext(); ) {
00031       Map.Entry e = (Map.Entry)i.next();
00032       Object value = e.getValue();
00033       Category category = (Category)e.getKey();
00034 
00035       category.print(last);
00036       if(value != null)
00037     Debug.print(Debug.WARNING, ": " + value);
00038       Debug.println(Debug.WARNING);
00039 
00040       last = category;
00041     }
00042   }  
00043   public void save(PrintStream out) {
00044     Set entries = ht.entrySet();
00045 
00046     for(Iterator i = entries.iterator(); i.hasNext(); ) {
00047       Map.Entry e = (Map.Entry)i.next();
00048       Object value = e.getValue();
00049       Category category = (Category)e.getKey();
00050 
00051       out.print(category);
00052       if(value != null)
00053     out.print(": " + value);
00054       out.println();
00055     }
00056   }  
00057   public void set(Category c, Object o) {
00058     if(ht.containsKey(c))
00059       ht.remove(c);
00060     ht.put(c, o);
00061   }  
00062   public void set(String s, Object o) {
00063     set(new Category(s), o);
00064   }  
00065 }

Generated at Thu Feb 7 06:55:53 2002 for Bandera by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001