コード例 #1
0
ファイル: CSSParser.java プロジェクト: rubenagm/Antorcha
  /*
   * Used by renderer to check if a CSS rule matches the current element.
   */
  protected static boolean ruleMatch(Selector selector, SvgElementBase obj) {
    // Build the list of ancestor objects
    List<SvgContainer> ancestors = new ArrayList<SvgContainer>();
    SvgContainer parent = obj.parent;
    while (parent != null) {
      ancestors.add(0, parent);
      parent = ((SvgObject) parent).parent;
    }

    int ancestorsPos = ancestors.size() - 1;

    // Check the most common case first as a shortcut.
    if (selector.size() == 1) return selectorMatch(selector.get(0), ancestors, ancestorsPos, obj);

    // We start at the last part of the selector and loop back through the parts
    // Get the next selector part
    return ruleMatch(selector, selector.size() - 1, ancestors, ancestorsPos, obj);
  }
コード例 #2
0
ファイル: ReadArray.java プロジェクト: nunb/fastr
    public Object execute(
        RArray source, Selector selectorI, Selector selectorJ, boolean drop, int exact)
        throws UnexpectedResultException {
      assert Utils.check(subset);
      int[] ndim = source.dimensions();
      int m = ndim[0];
      int n = ndim[1];
      selectorI.start(m, ast);
      selectorJ.start(n, ast);
      int nm = selectorI.size();
      int nn = selectorJ.size();
      boolean mayHaveNA = selectorI.mayHaveNA() || selectorJ.mayHaveNA();
      int nsize = nm * nn;
      if ((nm != 1 && nn != 1) || !drop) {
        ndim = new int[] {nm, nn};
      } else {
        ndim = null;
      }
      RArray res = Utils.createArray(source, nsize, ndim, null, null); // drop attributes
      if (!mayHaveNA) {
        int resoffset = 0;
        for (int nj = 0; nj < nn; nj++) {
          int j = selectorJ.nextIndex(ast);
          int srcoffset = j * m;
          for (int ni = 0; ni < nm; ni++) {
            int i = selectorI.nextIndex(ast);
            Object value =
                source.getRef(
                    srcoffset
                        + i); // FIXME: check overflow? (the same is at many locations, whenever
                              // indexing a matrix)
            res.set(resoffset++, value);
          }
          selectorI.restart();
        }
      } else {
        for (int nj = 0; nj < nn; nj++) {
          int j = selectorJ.nextIndex(ast);
          if (j != RInt.NA) {
            selectorI.restart();
            for (int ni = 0; ni < nm; ni++) {
              int offset = nj * nm + ni;
              int i = selectorI.nextIndex(ast);
              if (i != RInt.NA) {
                Object value;
                value =
                    source.getRef(
                        j * m
                            + i); // FIXME: check overflow? (the same is at many locations, whenever
                                  // indexing a matrix)
                res.set(offset, value);
              } else {
                Utils.setNA(res, offset);
              }
            }
          } else {
            for (int ni = 0; ni < nm; ni++) {
              Utils.setNA(res, nj * nm + ni);
            }
          }
        }
      }

      return res;
    }