Esempio n. 1
0
 /* The result is the datetime value consisting of the parts given by year, month, day, hour, minute and second.
  */
 public static SchemaDateTime datetimeFromParts(
     SchemaTypeNumber year,
     SchemaTypeNumber month,
     SchemaTypeNumber day,
     SchemaTypeNumber hour /* optional */,
     SchemaTypeNumber minute /* optional */,
     SchemaTypeNumber second /* optional */,
     SchemaTypeNumber millisecond /* optional */,
     SchemaTypeNumber timezone /* optional */) {
   SchemaDateTime result =
       new SchemaDateTime(
           year.intValue(),
           month.intValue(),
           day.intValue(),
           hour.intValue(),
           minute.intValue(),
           second.intValue(),
           0);
   result.setMillisecond(millisecond.intValue());
   long tv = result.getTimeValue();
   result.setTimeFromTimeValue(tv);
   result.setDateFromTimeValue(tv);
   if (timezone.intValue() >= -1440 && timezone.intValue() <= 1440)
     result.setTimezone(SchemaCalendarBase.TZ_OFFSET, timezone.intValue());
   return result;
 }
Esempio n. 2
0
 /* Returns a string with the given number of characters on the left of the given string.
  */
 public static SchemaString left(SchemaString string, SchemaTypeNumber number) {
   try {
     return new SchemaString(string.getValue().substring(0, number.intValue()));
   } catch (IndexOutOfBoundsException e) {
     return new SchemaString(string);
   }
 }
Esempio n. 3
0
 /* Returns the index within the string of the first occurrence of the specified substring, starting at the specified index. The first character has index=1. If the substring was not found 0 is returned.
  */
 public static SchemaTypeNumber findSubstring(
     SchemaString string, SchemaString substr, SchemaTypeNumber startindex) {
   int nStart = startindex.intValue();
   if (nStart > 0)
     return new SchemaInt(string.getValue().indexOf(substr.getValue(), nStart - 1) + 1);
   else return new SchemaInt(string.getValue().indexOf(substr.getValue()) + 1);
 }
Esempio n. 4
0
 /* Returns a string with the given number of characters on the right side of the given string.
  */
 public static SchemaString right(SchemaString string, SchemaTypeNumber number) {
   String s = string.getValue();
   try {
     return new SchemaString(s.substring(s.length() - number.intValue(), s.length()));
   } catch (IndexOutOfBoundsException e) {
     return new SchemaString(string);
   }
 }
Esempio n. 5
0
 /* Returns the index within this string of the rightmost occurrence of the specified substring, starting at the specified index. The first character has index=0. If the substring was not found -1 is returned.
  */
 public static SchemaTypeNumber reversefindSubstring(
     SchemaString string, SchemaString substr, SchemaTypeNumber endindex) {
   int nLastPosition = -1;
   int nActPosition = string.getValue().indexOf(substr.getValue());
   int nEndIndex = endindex.intValue();
   if (nEndIndex < 0) nEndIndex = string.toString().length();
   while (nActPosition > -1 && nActPosition < nEndIndex) { // note: endindex is 1 based
     nLastPosition = nActPosition;
     nActPosition = string.getValue().indexOf(substr.getValue(), nActPosition + 1);
   }
   return new SchemaInt(nLastPosition + 1);
 }
Esempio n. 6
0
 /* Result is the numeric value of -value.
  */
 public static SchemaTypeNumber unaryMinus(SchemaTypeNumber value) {
   switch (value.numericType()) {
     case SchemaTypeNumber.NUMERIC_VALUE_INT:
       return new SchemaInt(-value.intValue());
     case SchemaTypeNumber.NUMERIC_VALUE_LONG:
       return new SchemaLong(-value.longValue());
     case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER:
       return new SchemaInteger(
           value.bigIntegerValue().negate()); // note: possible loss of precision
     case SchemaTypeNumber.NUMERIC_VALUE_FLOAT:
       return new SchemaFloat(-value.floatValue());
     case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE:
       return new SchemaDouble(-value.doubleValue());
   }
   return new SchemaDecimal(value.bigDecimalValue().negate());
 }
Esempio n. 7
0
 /* Returns the correctly rounded positive square root of a value.
  */
 public static SchemaTypeNumber sqrt(SchemaTypeNumber value) {
   switch (value.numericType()) {
     case SchemaTypeNumber.NUMERIC_VALUE_INT:
       return new SchemaInt((int) java.lang.Math.sqrt(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_LONG:
       return new SchemaLong((long) java.lang.Math.sqrt(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER:
       return new SchemaInteger(
           (long) java.lang.Math.sqrt(value.doubleValue())); // note: possible loss of precision
     case SchemaTypeNumber.NUMERIC_VALUE_FLOAT:
       return new SchemaFloat((float) java.lang.Math.sqrt(value.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE:
       return new SchemaDouble(java.lang.Math.sqrt(value.doubleValue()));
   }
   return new SchemaDecimal(java.lang.Math.sqrt(value.doubleValue()));
 }
Esempio n. 8
0
 protected static SchemaTypeNumber getCommonNumberInstance(
     int numericType, SchemaTypeNumber a_value) {
   switch (numericType) {
     case SchemaTypeNumber.NUMERIC_VALUE_INT:
       return new SchemaInt(a_value.intValue());
     case SchemaTypeNumber.NUMERIC_VALUE_LONG:
       return new SchemaLong(a_value.longValue());
     case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER:
       return new SchemaInteger(a_value.bigIntegerValue());
     case SchemaTypeNumber.NUMERIC_VALUE_FLOAT:
       return new SchemaFloat(a_value.floatValue());
     case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE:
       return new SchemaDouble(a_value.doubleValue());
     case SchemaTypeNumber.NUMERIC_VALUE_BIGDECIMAL:
       return new SchemaDecimal(a_value.bigDecimalValue());
   }
   return null;
 }
Esempio n. 9
0
 /* The result is the datetime value consisting of the parts given by year, month, day, hour, minute and second.
  */
 public static SchemaDuration durationFromParts(
     SchemaTypeNumber year,
     SchemaTypeNumber month,
     SchemaTypeNumber day,
     SchemaTypeNumber hour /* optional */,
     SchemaTypeNumber minute /* optional */,
     SchemaTypeNumber second /* optional */,
     SchemaTypeNumber partsecond /* optional */,
     SchemaBoolean negative /* optional */) {
   SchemaDuration result =
       new SchemaDuration(
           year.intValue(),
           month.intValue(),
           day.intValue(),
           hour.intValue(),
           minute.intValue(),
           second.intValue(),
           0,
           negative.booleanValue());
   result.setMillisecond(partsecond.intValue());
   return result;
 }
Esempio n. 10
0
 /* Generates numbers automatically. On every call of this function it returns the actual-counter-value (starting at 'start_at')
  * increased by the 'increase' value.
  * 'start_at' (default = 1) and 'increase' (default = 1) are optional.
  */
 public static SchemaTypeNumber autoNumber(
     AutoNumberState state, SchemaTypeNumber startAt, SchemaTypeNumber increase) {
   if (!state.isInitialized()) state.init(startAt.intValue(), increase.intValue());
   return new SchemaInt(state.getCurrent());
 }
Esempio n. 11
0
 /* Result is the numeric value of integer dividing value1 with value2.
  */
 public static SchemaTypeNumber divideInteger(SchemaTypeNumber value1, SchemaTypeNumber value2) {
   switch (java.lang.Math.max(value1.numericType(), value2.numericType())) {
     case SchemaTypeNumber.NUMERIC_VALUE_INT:
       return new SchemaInt(value1.intValue() / value2.intValue());
     case SchemaTypeNumber.NUMERIC_VALUE_LONG:
       return new SchemaLong(value1.longValue() / value2.longValue());
     case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER:
       return new SchemaInteger(value1.bigIntegerValue().divide(value2.bigIntegerValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_FLOAT:
       return new SchemaFloat((int) (value1.floatValue() / value2.floatValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE:
       return new SchemaDouble((long) (value1.doubleValue() / value2.doubleValue()));
   }
   return new SchemaDecimal(
       value1.bigDecimalValue().divide(value2.bigDecimalValue(), 0, BigDecimal.ROUND_DOWN));
 }
Esempio n. 12
0
 /* Returns a string with the character given by the numeric code.
  */
 public static SchemaString charFromCode(SchemaTypeNumber value) {
   Character c = new Character((char) value.intValue());
   return new SchemaString(c.toString());
 }
Esempio n. 13
0
 /* Returns the value of a raised to the power of b.
  */
 public static SchemaTypeNumber pow(SchemaTypeNumber a, SchemaTypeNumber b) {
   switch (java.lang.Math.max(a.numericType(), b.numericType())) {
     case SchemaTypeNumber.NUMERIC_VALUE_INT:
       return new SchemaInt((int) java.lang.Math.pow(a.doubleValue(), b.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_LONG:
       return new SchemaLong((long) java.lang.Math.pow(a.doubleValue(), b.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER:
       return new SchemaInteger((long) java.lang.Math.pow(a.doubleValue(), b.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_FLOAT:
       return new SchemaFloat((float) java.lang.Math.pow(a.doubleValue(), b.doubleValue()));
     case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE:
       return new SchemaDouble(java.lang.Math.pow(a.doubleValue(), b.doubleValue()));
   }
   return new SchemaDecimal(java.lang.Math.pow(a.doubleValue(), b.doubleValue()));
 }
Esempio n. 14
0
 /* Returns the absolute value. If the argument is not negative, the argument is returned. If the argument is negative, the negation of the argument is returned.
  */
 public static SchemaTypeNumber abs(SchemaTypeNumber value) {
   if (negative(value).booleanValue()) return unaryMinus(value);
   return getCommonNumberInstance(value.numericType(), value);
 }