1 package com.puppycrawl.tools.checkstyle.checks.xpath; 20 21 import java.util.Iterator ; 22 import java.util.NoSuchElementException ; 23 24 import com.puppycrawl.tools.checkstyle.api.DetailAST; 25 26 30 public abstract class NodeIterator 31 implements Iterator 32 { 33 34 35 private DetailAST mNode; 36 37 41 public NodeIterator(DetailAST aAST) 42 { 43 this.mNode = getFirstNode(aAST); 44 } 45 46 47 public boolean hasNext() 48 { 49 return mNode != null; 50 } 51 52 53 public Object next() 54 { 55 if (mNode == null) { 56 throw new NoSuchElementException (); 57 } 58 final DetailAST ret = mNode; 59 mNode = getNextNode(mNode); 60 return ret; 61 } 62 63 64 public void remove() 65 { 66 throw new UnsupportedOperationException (); 67 } 68 69 74 protected abstract DetailAST getFirstNode(DetailAST aAST); 75 76 81 protected abstract DetailAST getNextNode(DetailAST aAST); 82 83 88 protected DetailAST getPreviousSibling(DetailAST aAST) 89 { 90 return aAST.getPreviousSibling(); 91 } 92 93 98 protected DetailAST getNextSibling(DetailAST aAST) 99 { 100 return (DetailAST) aAST.getNextSibling(); 101 } 102 103 108 protected DetailAST getFirstChild(DetailAST aAST) 109 { 110 return (DetailAST) aAST.getFirstChild(); 111 } 112 113 118 protected DetailAST getLastChild(DetailAST aAST) 119 { 120 return aAST.getLastChild(); 121 } 122 } | Popular Tags |