Esempio n. 1
0
 private static Field[] getAllFields(Class cls) {
   ArrayList<Field> res = new ArrayList<>();
   Class c = cls;
   while (c != View.class) {
     assert Utils.check(c != null);
     res.addAll(Arrays.asList(c.getDeclaredFields()));
     c = c.getSuperclass();
   }
   return res.toArray(new Field[res.size()]);
 }
Esempio n. 2
0
    public static RInt expandYVector(IntImpl yarg, int ysize, int count) {
        int size = ysize;
        int nsize = size * count;
        int[] y = yarg.getContent();

        int[] res = new int[nsize];
        int offset = 0;
        for (int elem = 0; elem < size; elem++) {
            int v = y[elem];
            Arrays.fill(res, offset, offset + count, v);
            offset += count;
        }
        return RInt.RIntFactory.getFor(res);
    }
Esempio n. 3
0
    public static RDouble expandYVector(DoubleImpl yarg, int ysize, int count) {
        int size = ysize;
        int nsize = size * count;
        double[] y = yarg.getContent();

        double[] res = new double[nsize];
        int offset = 0;
        for (int elem = 0; elem < size; elem++) {
            double v = y[elem];
            Arrays.fill(res, offset, offset + count, v);
            offset += count;
        }
        return RDouble.RDoubleFactory.getFor(res);
    }
Esempio n. 4
0
 static {
   Arrays.fill(connections, null);
 }
Esempio n. 5
0
  public static class Site {
    final StackTraceElement[] site;
    int hashCode;
    final int offset; // offset to first element that we care about (for performance of tracing)

    public Site(StackTraceElement[] site) {
      this.site = site;

      int i = 0;
      while (!THIS_FILE_NAME.equals(site[i].getFileName())) {
        i++;
      }
      while (THIS_FILE_NAME.equals(site[i].getFileName())) {
        i++;
      }
      assert Utils.check(i < site.length - 1);
      this.offset = i;
    }

    public Site() {
      this(Thread.currentThread().getStackTrace());
    }

    @Override
    public boolean equals(Object o) {
      if (o == this) {
        return true;
      }
      if (!(o instanceof Site)) {
        return false;
      }
      Site other = (Site) o;
      if (other.hashCode() != hashCode()) {
        return false;
      }
      StackTraceElement[] osite = other.site();
      if (site.length != osite.length) {
        return false;
      }
      for (int i = offset; i < site.length; i++) {
        if (!site[i].equals(osite[i])) {
          return false;
        }
      }
      return true;
    }

    @Override
    public int hashCode() {
      if (hashCode == 0) {
        int res = 1 + site.length * 17;
        int max = Math.max(site.length, 10);
        for (int i = offset; i < max; i++) {
          StackTraceElement e = site[i];
          int lineNumber = e.getLineNumber();
          res = res * 19 + 31 * lineNumber;
        }
        hashCode = res;
      }
      return hashCode;
    }

    public StackTraceElement[] site() {
      return site;
    }

    private static final String[] skipMethodsNames =
        new String[] {
          "getRAny",
          "getString",
          "getComplex",
          "getReal",
          "getImag",
          "getDouble",
          "getInt",
          "getLogical",
          "getRaw",
          "boxedGet",
          "getRef",
          "copy"
        };

    private static final HashSet<String> skipMethods =
        new HashSet<String>(Arrays.asList(skipMethodsNames));

    public static void printSite(Site s, StringBuilder out) {
      if (s == null) {
        out.append("(null)");
        return;
      }
      StackTraceElement[] st = s.site();

      int interestingSitesPrinted = 0;
      for (int i = s.offset; i < st.length; i++) {
        StackTraceElement e = st[i];
        String fileName = e.getFileName();
        if (THIS_FILE_NAME.equals(fileName)) {
          continue;
        }
        out.append(" " + e.getMethodName() + "(" + e.getFileName() + ":" + e.getLineNumber() + ")");
        interestingSitesPrinted++;
        if (interestingSitesPrinted <= SITES_TO_PRINT) {
          continue;
        }
        if (fileName == null || "View.java".equals(fileName)) {
          continue;
        }
        String methodName = e.getMethodName();
        if (skipMethods.contains(methodName)) {
          continue;
        }
        break;
      }
    }

    public static void printSite(Site s) {
      StringBuilder b = new StringBuilder();
      printSite(s, b);
      ps.println(b.toString());
    }

    public static void printElement(Site s, int index) {
      if (s == null || index >= s.site().length) {
        ps.print("(null)");
      } else {
        StackTraceElement e = s.site()[index];
        ps.print(e.getMethodName() + " (" + e.getFileName() + ":" + e.getLineNumber() + ")");
      }
    }

    public static void printElements(Site s, int index, int nelems) {
      if (s == null || index >= s.site().length) {
        ps.print("(null)");
      } else {
        for (int i = 0; i < nelems; i++) {
          int j = index + i;
          if (j >= s.site().length) {
            break;
          }
          if (i > 0) {
            ps.print(", ");
          }
          StackTraceElement e = s.site()[j];
          ps.print(e.getMethodName() + " (" + e.getFileName() + ":" + e.getLineNumber() + ")");
        }
      }
    }
  }