View Javadoc
1 /* 2 * Copyright (C) 2002 Carsten Krebs (Team-Konzept GmbH & Co.KG) 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 package com.teamkonzept.dom4jb.saxon; 19 20 import java.util.ArrayList; 21 22 import com.icl.saxon.om.AxisEnumeration; 23 import com.icl.saxon.om.NodeInfo; 24 import com.icl.saxon.pattern.NodeTest; 25 26 public class FilterEnumeration implements AxisEnumeration { 27 private final NodeTest test; 28 private AxisEnumeration enum; 29 private ArrayList nodes = null; 30 private int idx = 0; 31 private int last = -1; 32 private NodeInfo next = null; 33 34 public FilterEnumeration( final AxisEnumeration base, final NodeTest test) { 35 this.enum = base; 36 this.test = test; 37 } 38 39 public int getLastPosition() { 40 if ( nodes != null ) { 41 return last; 42 } 43 44 final ArrayList filteredNodes = new ArrayList(); 45 final NodeTest nodeTest = test; 46 for ( AxisEnumeration e = enum; e.hasMoreElements(); ) { 47 final NodeInfo node = e.nextElement(); 48 if ( nodeTest.matches( node ) ) { 49 filteredNodes.add( node ); 50 } 51 } 52 53 last = idx + filteredNodes.size(); 54 if ( next != null ) { 55 last += 1; 56 } 57 58 nodes = filteredNodes; 59 60 return last; 61 } 62 63 public boolean hasMoreElements() { 64 if ( next != null ) { 65 return true; 66 } 67 if ( nodes != null ) { 68 if ( idx < nodes.size() ) { 69 next = (NodeInfo)nodes.get(idx++); 70 return true; 71 } else { 72 next = null; 73 return false; 74 } 75 } 76 final NodeTest nodeTest = test; 77 for ( AxisEnumeration e = enum; enum.hasMoreElements(); ) { 78 final NodeInfo n = e.nextElement(); 79 if ( nodeTest.matches( n ) ) { 80 next = n; 81 return true; 82 } 83 } 84 next = null; 85 return false; 86 } 87 88 public boolean isPeer() { 89 return enum.isPeer(); 90 } 91 92 public boolean isReverseSorted() { 93 return enum.isReverseSorted(); 94 } 95 96 public boolean isSorted() { 97 return enum.isSorted(); 98 } 99 100 public NodeInfo nextElement() { 101 if ( next != null || hasMoreElements() ) { 102 final NodeInfo retNode = next; 103 next = null; 104 return retNode; 105 } 106 return null; 107 } 108 }

This page was automatically generated by Maven