コード例 #1
0
ファイル: SPDecimalImpl.java プロジェクト: anukat2015/mulgara
 /**
  * Creates an xsd:decimal by decoding from a data buffer.
  *
  * @param subtypeId The ID for either the full or abbreviated xsd:decimal.
  * @param typeURI The full or abbreviated URI for xsd:decimal.
  * @param data The data containing the xsd:decimal value.
  */
 SPDecimalBaseImpl(int subtypeId, URI typeURI, ByteBuffer data) {
   super(subtypeId, typeURI);
   if (data.limit() == Constants.SIZEOF_LONG)
     throw new IllegalArgumentException("Buffer does not hold a decimal.");
   ByteBuffer number = data;
   if (data.limit() == END_IDX + 1) {
     if (data.get(END_IDX) == END_BYTE) {
       data.limit(END_IDX);
       number = data.slice();
     }
   }
   lexical = CHARSET.decode(number).toString();
   val = new BigDecimal(lexical);
 }
コード例 #2
0
ファイル: SPDecimalImpl.java プロジェクト: anukat2015/mulgara
 /**
  * Reads a byte buffer and converts to a BigDecimal, regardless of formatting.
  *
  * @param bb The byte buffer to decode.
  * @return A BigDecimal representing the stored number.
  */
 static BigDecimal decode(ByteBuffer bb) {
   ByteBuffer number = bb;
   int limit = bb.limit();
   if (limit == Constants.SIZEOF_LONG) return BigDecimal.valueOf(bb.getLong());
   if (limit == END_IDX + 1) {
     // is this buffer padded?
     byte terminator = bb.get(END_IDX);
     if (terminator == SPDecimalBaseImpl.END_BYTE) {
       // remove the padding
       bb.limit(END_IDX);
       number = bb.slice();
     }
   }
   return new BigDecimal(CHARSET.decode(number).toString());
 }