/*
 * Copyright (C) 2008 TranceCode Software
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 *
 * $Id$
 */
package org.trancecode.xml.saxon;

import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XdmNodeKind;

/**
 * Utility methods related to {@link Predicate} and Saxon.
 * 
 * @author Herve Quiroz
 */
public final class SaxonPredicates
{
    private SaxonPredicates()
    {
        // No instantiation
    }

    public static Predicate<XdmNode> isElement()
    {
        // TODO memoize?
        return Predicates.compose(Predicates.equalTo(XdmNodeKind.ELEMENT), SaxonFunctions.getNodeKind());
    }

    public static Predicate<XdmNode> isAttribute()
    {
        // TODO memoize?
        return Predicates.compose(Predicates.equalTo(XdmNodeKind.ATTRIBUTE), SaxonFunctions.getNodeKind());
    }
}

@@ -1189,37 +1189,38 @@
     %7D%0A%0A    p
-ublic
+rivate
  static 
 Predicate%3CXd
@@ -1199,32 +1199,38 @@
  private static 
+final 
 Predicate%3CXdmNod
@@ -1236,65 +1236,20 @@
 de%3E 
-isElement()%0A    %7B%0A        // TODO memoize?%0A        return
+IS_ELEMENT =
  Pre
@@ -1304,16 +1304,28 @@
 LEMENT),
+%0A           
  SaxonFu
@@ -1347,22 +1347,16 @@
 Kind());
-%0A    %7D
 %0A%0A    pu
@@ -1392,17 +1392,15 @@
 %3E is
-Attribute
+Element
 ()%0A 
@@ -1416,39 +1416,92 @@
     
-// TODO memoize?
+return IS_ELEMENT;
 %0A    
+%7D%0A%0A
     
-return
+private static final Predicate%3CXdmNode%3E IS_ATTRIBUTE =
  Pre
@@ -1508,32 +1508,45 @@
 dicates.compose(
+%0A            
 Predicates.equal
@@ -1602,16 +1602,103 @@
 Kind());
+%0A%0A    public static Predicate%3CXdmNode%3E isAttribute()%0A    %7B%0A        return IS_ATTRIBUTE;
 %0A    %7D%0A%7D

Use constants to avoid building the predicates on demand