relativestepfilter.java

来自「A framework written in Java for implemen」· Java 代码 · 共 70 行

JAVA
70
字号
// Copyright (c) 2006  Per M.A. Bothner.// This is free software;  for terms and warranty disclaimer see ./COPYING.package gnu.xquery.util;import gnu.lists.*;import gnu.kawa.xml.*;/** Used to filter the output of RelativeStep. * Atomic values are passed though as-is, while node values are sorted * by document order and duplicates removed.  An exception is thrown * if there is a mix of atoms and nodes. * Informally: {@code E1/E2} is implemented as: * {@code RelativeStepFilter(for $dot in E1 return E2)}. */public class RelativeStepFilter extends FilterConsumer  implements PositionConsumer{  // 'A' for atomic, 'N' for nodes, '\0' for neither.  char seen;  SortedNodes snodes;  public RelativeStepFilter (Consumer base)  {    super(base);  }  // Not sure if this is ever called ...  public void consume(SeqPosition position)  {    writePosition(position.sequence, position.ipos);  }  public void writeObject(Object v)  {    if (v instanceof SeqPosition)      {        SeqPosition n = (SeqPosition) v;        writePosition(n.sequence, n.ipos);      }    else      super.writeObject(v);  }  protected void beforeContent ()  {    if (seen == 'N')      throw new Error("path returns mix of atoms and nodes");    seen = 'A';  }  public void writePosition(AbstractSequence seq, int ipos)  {    if (seen == 'A')      throw new Error("path returns mix of atoms and nodes");    seen = 'N';    if (snodes == null)      snodes = new SortedNodes();    snodes.writePosition(seq, ipos);  }  public void finish ()  {    if (snodes != null)      snodes.consume(base);    snodes = null;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?