Ejemplo n.º 1
0
 public static final Object getDominantSortAttributeValueFromString(
     String v, DataField dominantAttr) {
   Object value;
   switch (dominantAttr.getDataType()) {
     case BINARY:
       throw new IllegalStateException("cannot sort on a binary field");
     case LONG_STRING:
       throw new IllegalStateException("cannot sort on a long text field");
     case URI:
     case STRING:
       {
         value = v;
         break;
       }
     case INTEGER:
       {
         if (v == null) {
           value = null;
         } else {
           value = Long.valueOf(v);
         }
         break;
       }
     case DECIMAL:
       {
         if (v == null) {
           value = null;
         } else {
           BigDecimal bd = new BigDecimal(v);
           value = bd.setScale(dominantAttr.getNumericScale(), BigDecimal.ROUND_HALF_UP);
         }
         break;
       }
     case BOOLEAN:
       {
         if (v == null) {
           value = null;
         } else {
           value = WebUtils.parseBoolean(v);
         }
         break;
       }
     case DATETIME:
       {
         if (v == null) {
           value = null;
         } else {
           value = WebUtils.parseDate(v);
         }
         break;
       }
     default:
       throw new IllegalStateException("datatype not handled");
   }
   return value;
 }
Ejemplo n.º 2
0
 DataValue(String str, Integer n, Double bd, String dateStr, Boolean b) {
   this.str = str;
   this.l = (n == null) ? null : Long.valueOf(n);
   this.bd = (bd == null) ? null : BigDecimal.valueOf(bd);
   this.d = WebUtils.parseDate(dateStr);
   this.b = b;
 }
Ejemplo n.º 3
0
 public static final String getDominantSortAttributeValueAsString(
     CommonFieldsBase cb, DataField dominantAttr) {
   String value;
   switch (dominantAttr.getDataType()) {
     case BINARY:
       throw new IllegalStateException("cannot sort on a binary field");
     case LONG_STRING:
       throw new IllegalStateException("cannot sort on a long text field");
     case URI:
     case STRING:
       {
         value = cb.getStringField(dominantAttr);
         break;
       }
     case INTEGER:
       {
         Long l = cb.getLongField(dominantAttr);
         if (l == null) {
           value = null;
         } else {
           value = Long.toString(l);
         }
         break;
       }
     case DECIMAL:
       {
         BigDecimal bd = cb.getNumericField(dominantAttr);
         if (bd == null) {
           value = null;
         } else {
           value = bd.toString();
         }
         break;
       }
     case BOOLEAN:
       {
         Boolean b = cb.getBooleanField(dominantAttr);
         if (b == null) {
           value = null;
         } else {
           value = b.toString();
         }
         break;
       }
     case DATETIME:
       {
         Date d = cb.getDateField(dominantAttr);
         if (d == null) {
           value = null;
         } else {
           value = WebUtils.iso8601Date(d);
         }
         break;
       }
     default:
       throw new IllegalStateException("datatype not handled");
   }
   return value;
 }
Ejemplo n.º 4
0
 public static final String getAttributeValueAsString(Object o, DataField dominantAttr) {
   String value;
   switch (dominantAttr.getDataType()) {
     case BINARY:
       throw new IllegalStateException("cannot sort on a binary field");
     case LONG_STRING:
       throw new IllegalStateException("cannot sort on a long text field");
     case URI:
     case STRING:
       {
         value = (String) o;
         break;
       }
     case INTEGER:
       {
         Long l = (Long) o;
         if (l == null) {
           value = null;
         } else {
           value = Long.toString(l);
         }
         break;
       }
     case DECIMAL:
       {
         BigDecimal bd;
         if (o == null) {
           bd = null;
         } else if (o instanceof Double) {
           bd = new BigDecimal(((Double) o).toString());
         } else {
           bd = new BigDecimal(o.toString());
         }
         if (bd == null) {
           value = null;
         } else {
           value = bd.toString();
         }
         break;
       }
     case BOOLEAN:
       {
         Boolean b = (Boolean) o;
         if (b == null) {
           value = null;
         } else {
           value = b.toString();
         }
         break;
       }
     case DATETIME:
       {
         Date d = (Date) o;
         if (d == null) {
           value = null;
         } else {
           value = WebUtils.iso8601Date(d);
         }
         break;
       }
     default:
       throw new IllegalStateException("datatype not handled");
   }
   return value;
 }