/* 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; }
/* Result is the numeric value of the smallest value. */ public static SchemaTypeNumber min(SchemaTypeNumber value1, SchemaTypeNumber value2) { switch (java.lang.Math.max(value1.numericType(), value2.numericType())) { case SchemaTypeNumber.NUMERIC_VALUE_INT: return new SchemaInt(java.lang.Math.min(value1.intValue(), value2.intValue())); case SchemaTypeNumber.NUMERIC_VALUE_LONG: return new SchemaLong(java.lang.Math.min(value1.longValue(), value2.longValue())); case SchemaTypeNumber.NUMERIC_VALUE_BIGINTEGER: return new SchemaInteger(value1.bigIntegerValue().min(value2.bigIntegerValue())); case SchemaTypeNumber.NUMERIC_VALUE_FLOAT: return new SchemaFloat(java.lang.Math.min(value1.floatValue(), value2.floatValue())); case SchemaTypeNumber.NUMERIC_VALUE_DOUBLE: return new SchemaDouble(java.lang.Math.min(value1.doubleValue(), value2.doubleValue())); } return new SchemaDecimal(value1.bigDecimalValue().min(value2.bigDecimalValue())); }
/* 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); } }
/* 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); }
/* 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); } }
/* 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); }
/* 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()); }
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; }
/* 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; }
/* 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()); }
/* 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()); }