1 27 package org.htmlparser.lexer; 28 29 import java.io.Serializable ; 30 import org.htmlparser.util.sort.Ordered; 31 32 36 public class Cursor 37 implements 38 Serializable , 39 Ordered, 40 Cloneable 41 { 42 45 protected int mPosition; 46 47 50 protected Page mPage; 51 52 57 public Cursor (Page page, int offset) 58 { 59 mPage = page; 60 mPosition = offset; 61 } 62 63 67 public Page getPage () 68 { 69 return (mPage); 70 } 71 72 76 public int getPosition () 77 { 78 return (mPosition); 79 } 80 81 85 public void setPosition (int position) 86 { 87 mPosition = position; 88 } 89 90 93 public void advance () 94 { 95 mPosition++; 96 } 97 98 101 public void retreat () 102 { 103 mPosition--; 104 if (0 > mPosition) 105 mPosition = 0; 106 } 107 108 113 public Cursor dup () 114 { 115 try 116 { 117 return ((Cursor)clone ()); 118 } 119 catch (CloneNotSupportedException cnse) 120 { 121 return (new Cursor (getPage (), getPosition ())); 122 } 123 } 124 125 public String toString () 126 { 127 StringBuffer ret; 128 129 ret = new StringBuffer (9 * 3 + 3); ret.append (getPosition ()); 131 ret.append ("["); 132 if (null != mPage) 133 ret.append (mPage.row (this)); 134 else 135 ret.append ("?"); 136 ret.append (","); 137 if (null != mPage) 138 ret.append (mPage.column (this)); 139 else 140 ret.append ("?"); 141 ret.append ("]"); 142 143 return (ret.toString ()); 144 } 145 146 150 154 public int compare (Object that) 155 { 156 Cursor r = (Cursor)that; 157 return (getPosition () - r.getPosition ()); 158 } 159 } 160 161 | Popular Tags |