Example #1
0
 public SubstanceIngredientComponent copy() {
   SubstanceIngredientComponent dst = new SubstanceIngredientComponent();
   copyValues(dst);
   dst.quantity = quantity == null ? null : quantity.copy();
   dst.substance = substance == null ? null : substance.copy();
   return dst;
 }
  private static Ratio[] loadRatios(InputStream in, Ratio[] r)
      throws IOException, XmlPullParserException {

    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
    factory.setNamespaceAware(true);

    XmlPullParser parser = factory.newPullParser();

    parser.setInput(in, null);
    while (true) {
      if (parser.nextTag() != XmlPullParser.START_TAG) continue;
      if (!parser.getName().equals("coverage")) continue;
      break;
    }

    if (r == null || r.length < 5) r = new Ratio[5];

    // head for the first <coverage> tag.
    for (int i = 0; i < r.length; i++) {
      if (!parser.getName().equals("coverage")) break; // line coverage is optional

      parser.require(XmlPullParser.START_TAG, "", "coverage");
      String v = parser.getAttributeValue("", "value");
      String t = parser.getAttributeValue("", "type");

      int index;
      if (t.equals("class, %")) index = 0;
      else if (t.equals("method, %")) index = 1;
      else if (t.equals("block, %")) index = 2;
      else if (t.equals("line, %")) index = 3;
      else if (t.equals("condition, %")) index = 4;
      else continue;

      if (r[index] == null) {
        r[index] = Ratio.parseValue(v);
      } else {
        r[index].addValue(v);
      }

      // move to the next coverage tag.
      parser.nextTag();
      parser.nextTag();
    }

    return r;
  }
Example #3
0
 public boolean isEmpty() {
   return super.isEmpty()
       && (quantity == null || quantity.isEmpty())
       && (substance == null || substance.isEmpty());
 }