package com.nailabs.abac.process; import edu.stanford.peer.rbtm.credential.*; import java.util.*; import java.io.*; public class CountTable { protected Hashtable table = new Hashtable(20); public float SAT = 4.0f; public float INIT = 7.0f; public CountTable(String file) { load(file); } public void load(String filename) { try { BufferedReader in = new BufferedReader(new FileReader(filename)); while(true) { String line = in.readLine(); StringTokenizer st = new StringTokenizer(line, "="); EntityExpression expr = StaticCredential.getEntityExpression(st.nextToken()); Float weight = new Float(st.nextToken()); table.put(expr, weight); } } catch(Exception ex) { //ex.printStackTrace(); } } public void save(String filename) { try { PrintStream out = new PrintStream(new FileOutputStream(filename)); Iterator i = table.keySet().iterator(); while(i.hasNext()) { EntityExpression key = (EntityExpression)i.next(); Float entry = (Float)table.get(key); out.println(key + "=" + getWeight(key)); } } catch(Exception ex) { ex.printStackTrace(); } } public float getWeight(EntityExpression r) { Float val = (Float)table.get(r); if(val == null) { val = new Float(INIT); table.put(r, val); } return val.floatValue(); } public void addSatisfied(EntityExpression r) { Float val = (Float)table.get(r); if(val == null) { val = new Float(INIT); } val = new Float(SAT); table.put(r, val); } public void addFailed(EntityExpression r) { Float val = (Float)table.get(r); float f = (val == null)? INIT: val.floatValue(); f = (f <= 1.0f)? 0.0f: (f - 1.0f); table.put(r, new Float(f)); } }