⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 expr.java

📁 linux下建立JAVA虚拟机的源码KAFFE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * node-set with the context node as its only member.   */  public static String _namespace_uri(Node context, Collection nodeSet)  {    if (nodeSet == null || nodeSet.isEmpty())      return "";    Node node = firstNode(nodeSet);    String ret = node.getNamespaceURI();    return (ret == null) ? "" : ret;  }    /**   * The name function returns a string containing a QName representing the   * expanded-name of the node in the argument node-set that is first in   * document order. The QName must represent the expanded-name with respect   * to the namespace declarations in effect on the node whose expanded-name   * is being represented. Typically, this will be the QName that occurred   * in the XML source. This need not be the case if there are namespace   * declarations in effect on the node that associate multiple prefixes   * with the same namespace. However, an implementation may include   * information about the original prefix in its representation of nodes;   * in this case, an implementation can ensure that the returned string is   * always the same as the QName used in the XML source. If the argument   * node-set is empty or the first node has no expanded-name, an empty   * string is returned. If the argument it omitted, it defaults to a   * node-set with the context node as its only member.   */  public static String _name(Node context, Collection nodeSet)  {    if (nodeSet == null || nodeSet.isEmpty())      return "";    Node node = firstNode(nodeSet);    String ret = null;    switch (node.getNodeType())      {      case Node.ATTRIBUTE_NODE:      case Node.ELEMENT_NODE:      case Node.PROCESSING_INSTRUCTION_NODE:        ret = node.getNodeName();      }    return (ret == null) ? "" : ret;  }  /**   * Returns the first node in the set in document order.   */  static Node firstNode(Collection nodeSet)  {    List list = new ArrayList(nodeSet);    Collections.sort(list, documentOrderComparator);    return (Node) list.get(0);  }  /* -- 4.2 String Functions -- */  /**   * Implementation of the XPath <code>string</code> function.   */  public static String _string(Node context, Object object)  {    if (object == null)      {        return stringValue(context);      }    if (object instanceof String)      {        return (String) object;      }    if (object instanceof Boolean)      {        return object.toString();      }    if (object instanceof Double)      {        double d = ((Double) object).doubleValue();        if (Double.isNaN(d))          {            return "NaN";          }        else if (d == 0.0d)          {            return "0";          }        else if (Double.isInfinite(d))          {            if (d < 0)              {                return "-Infinity";              }            else              {                return "Infinity";              }          }        else          {            String ret = decimalFormat.format(d);            if (ret.endsWith (".0"))              {                 ret = ret.substring(0, ret.length() - 2);              }            return ret;          }      }    if (object instanceof Collection)      {        Collection nodeSet = (Collection) object;        if (nodeSet.isEmpty())          {            return "";          }        Node node = firstNode(nodeSet);        return stringValue(node);      }    throw new IllegalArgumentException(object.toString());  }  /* -- 4.3 Boolean Functions -- */    /**   * Implementation of the XPath <code>boolean</code> function.   */  public static boolean _boolean(Node context, Object object)  {    if (object instanceof Boolean)      {        return ((Boolean) object).booleanValue();      }    if (object instanceof Double)      {        Double value = (Double) object;        if (value.isNaN())          return false;        return value.doubleValue() != 0.0;      }    if (object instanceof String)      {        return ((String) object).length() != 0;      }    if (object instanceof Collection)      {        return ((Collection) object).size() != 0;      }    return false; // TODO user defined types  }  /* -- 4.4 Number Functions -- */  /**   * Implementation of the XPath <code>number</code> function.   */  public static double _number(Node context, Object object)  {    if (object == null)      {        object = Collections.singleton(context);      }    if (object instanceof Double)      {        return ((Double) object).doubleValue();      }    if (object instanceof Boolean)      {        return ((Boolean) object).booleanValue() ? 1.0 : 0.0;      }    if (object instanceof Collection)      {        // Convert node-set to string        object = stringValue((Collection) object);      }    if (object instanceof String)      {        String string = ((String) object).trim();        try          {            return Double.parseDouble(string);          }        catch (NumberFormatException e)          {            return Double.NaN;          }      }    return Double.NaN; // TODO user-defined types  }  /**   * Computes the XPath string-value of the specified node-set.   */  public static String stringValue(Collection nodeSet)  {    StringBuffer buf = new StringBuffer();    for (Iterator i = nodeSet.iterator(); i.hasNext(); )      {        buf.append(stringValue((Node) i.next()));      }    return buf.toString();  }  /**   * Computes the XPath string-value of the specified node.   */  public static String stringValue(Node node)  {    return stringValue(node, false);  }    static String stringValue(Node node, boolean elementMode)  {    switch (node.getNodeType())      {      case Node.DOCUMENT_NODE: // 5.1 Root Node      case Node.DOCUMENT_FRAGMENT_NODE:      case Node.ELEMENT_NODE: // 5.2 Element Nodes        StringBuffer buf = new StringBuffer();        for (Node ctx = node.getFirstChild(); ctx != null;             ctx = ctx.getNextSibling())          {            buf.append(stringValue(ctx, true));          }        return buf.toString();      case Node.TEXT_NODE: // 5.7 Text Nodes      case Node.CDATA_SECTION_NODE:        return node.getNodeValue();      case Node.ATTRIBUTE_NODE: // 5.3 Attribute Nodes      case Node.PROCESSING_INSTRUCTION_NODE: // 5.5 Processing Instruction      case Node.COMMENT_NODE: // 5.6 Comment Nodes        if (!elementMode)          {            return node.getNodeValue();          }      default:        return "";      }  }  static int intValue(Object val)  {    if (val instanceof Double)      {        Double d = (Double) val;        return d.isNaN() ? 0 : d.intValue();      }    else      return (int) Math.ceil(_number(null, val));  }}

⌨️ 快捷键说明

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