package username.graph; import java.util.Vector; /** * A simple implementation of markers. * * @author Samuel A. Rebelsky * @version 1.0 of April 2006 */ public class SimpleMarker implements Marker { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** * A Vector that represents the marks. marks[v] holds only when * v is marked. */ Vector marks; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Build a new marker that supports graphs of size _size. */ public SimpleMarker(int _size) { this.marks = new Vector(_size); this.marks.setSize(_size); } // SimpleMarker(int) // +-----------+--------------------------------------------------------- // | Observers | // +-----------+ public boolean isMarked(int v) { return (v < this.marks.size()) && (this.marks.get(v) != null); } // isMarked(int) public T getMark(int v) { return this.marks.get(v); } // getMark(int) // +----------+---------------------------------------------------------- // | Mutators | // +----------+ public void mark(int v, T mark) throws Exception { if (v < this.marks.size()) { this.marks.set(v,mark); } else { throw new Exception("Invalid vertex: " + v); } } // mark(int, T) public void unmark(int v) { if (v < this.marks.size()) { this.marks.set(v,null); } } // unmark(int) } // class SimpleMarker