JsonObject build() {

    entryMap.forEach(
        (name, value) -> {
          ValueType type = ValueType.valueOf(value.getClass());
          switch (type) {
            case JsonObjectBuilder:
              jsonObjectBuilder.add(name, ((JsonObjectBuilder) value).build());
              break;
            case JsonArrayBuilder:
              jsonObjectBuilder.add(name, ((JsonArrayBuilder) value).build());
              break;
            case BigDecimal:
              jsonObjectBuilder.add(name, (BigDecimal) value);
              break;
            case Integer:
              jsonObjectBuilder.add(name, (Integer) value);
              break;
            case JsonObject:
              jsonObjectBuilder.add(name, (JsonObject) value);
              break;
            case Boolean:
              jsonObjectBuilder.add(name, (Boolean) value);
              break;
            default:
              jsonObjectBuilder.add(name, String.valueOf(value));
          }
        });
    return jsonObjectBuilder.build();
  }
Example #2
0
 /**
  * Performs unit analysis of a given infix operation. The first unit (non-scalar token)
  * encountered is returned, except with division. In that case, scalar is returned if both units
  * are the same and points is returned when dividing inches and points.
  *
  * @param u1 left-hand unit
  * @param u2 right-hand unit
  * @param op operator
  * @return Token containing resultant unit.
  */
 public static ValueType evaluateUnits(ValueType u1, ValueType u2, Token op) {
   String unit = "SCALAR"; // default ValueType
   final String left = u1.toString();
   final String right = u2.toString();
   switch (op.text) {
     case "/":
       // In the case of division, we need only to be concerned in situations where
       // the final unit is not scalar
       if (!u1.toString().equals(right)) {
         if (left.equals("SCALAR")) {
           unit = right;
           break;
         }
         if (right.equals("SCALAR")) {
           unit = left;
           break;
         }
       }
       break;
     default:
       if (left.equals("SCALAR")) {
         unit = right;
         break;
       }
       if (right.equals("SCALAR")) {
         unit = left;
         break;
       }
       unit = left;
       break;
   }
   return ValueType.valueOf(unit);
 }
Example #3
0
 public ValueType valueType() {
   return ValueType.valueOf(n_getValueType(nativeObject()));
 }