package edu.vt.marian.search; import java.io.*; import java.net.*; import java.lang.*; import java.util.*; import edu.vt.marian.common.*; /** * This class augments weighted objects with a "pointer" to a FullID. * This is to enable the creation of weighted object tables which are * "threaded" like a singly-linked list. The purpose of such a table * is to allow O(1) ("direct") access to any point in the logical * list, but thereafter to "follow" the entries in the list from that * point onwards. * * @author Paul Mather * @version 0.9 * @see edu.vt.marian.common.WtdObj * @see edu.vt.marian.common.FullID * @see edu.vt.marian.common.Debug */ public class WtdObjSingleLink extends WtdObj { /** "Pointer" to the next "list" entry */ protected FullID next; /** * Create a singly-linked weighted object given only a debug * object. The resultant object will have its weighted object set * to a newly-created WtdObj and its next "pointer" set to a * newly-created---and invalid---FullID. * @param debug debug object */ public WtdObjSingleLink( Debug debug ) { super(debug); this.next = null; } /** * Create a singly-linked weighted object given a weighted object * (and a debug object). The resultant object will have its next * "pointer" set to a newly-created---and invalid---FullID. * @param w weighted object * @param debug debug object */ public WtdObjSingleLink( WtdObj w, Debug debug ) { super(w, debug); this.next = null; } /** * Create a singly-linked weighted object given a weighted object, * a FullID pointing to the "next" list item, and a debug object. * @param w weighted object * @param next key of next element in this list * @param debug debug object */ public WtdObjSingleLink( WtdObj w, FullID fullID, Debug debug ) { super(w, debug); this.next = new FullID(fullID, debug); } /** * Return the FullID key of the next item pointed to in this ordering. * @return key of the next weighted object in this ordering */ public FullID getNext() { return this.next; } /** * Set the FullID key of the next item pointed to in this ordering. * @param nextElt the "key" of the next element "pointed" to by this one * @return key of the next weighted object in this ordering */ public void setNext(FullID nextElt) { // if (nextElt.isValid()) this.next = nextElt; // else // { // debug.dumpTrace("WtdObjSingleLink.setNext: Invalid FullID"); // this.next = null; // } } /** * Return the WtdObj portion of this WtdObjSingleLink object. * @return copy of the WtdObj portion of this WtdObjSingleLink object. */ public WtdObj getWtdObj() { return new WtdObj(this.getID(),this.getWeight(),this.debug); } /** * Convert this WtdObjSingleLink to a string representation. * The printable form is "WtdObj(FullID)", where WtdObj * is the string representation of the weighted object portion * of this object, and FullID is the string representation of * the FullID "next" pointer of this object. * @return string containing printable representation of object data * @see edu.vt.marian.common.WtdObj#toString * @see edu.vt.marian.common.FullID#toString */ public String toString() { if (next == null) return super.toString() + "(null)" ; else return super.toString() + '(' + next.toString() + ')'; } }