@Override public Dictionary<String> build() throws IOException { if (datePattern == null) datePattern = DATE_PATTERNS[0]; return new DateStrDictionary(datePattern, baseId); }
private void checkPair(String dateStr) { int id = dict.getIdFromValue(dateStr); String dateStrBack = dict.getValueFromId(id); assertEquals(dateStr, dateStrBack); }
@Override final protected int getIdFromValueImpl(String value, int roundFlag) { Date date = stringToDate(value, pattern); int id = calcIdFromSeqNo((int) DateDimEnc.getNumOfDaysSince0000FromMillis(date.getTime())); if (id < baseId || id > maxId) throw new IllegalArgumentException("'" + value + "' encodes to '" + id + "' which is out of range [" + baseId + "," + maxId + "]"); return id; }
@Test public void testNull() { int nullId = dict.getIdFromValue(null); assertNull(dict.getValueFromId(nullId)); int nullId2 = dict.getIdFromValueBytes(null, 0, 0); assertEquals(dict.getValueBytesFromId(nullId2, null, 0), -1); assertEquals(nullId, nullId2); }
@Override final protected int getIdFromValueImpl(String value, int roundFlag) { Date date = stringToDate(value, pattern); int id = calcIdFromSeqNo(getNumOfDaysSince0000(date)); if (id < baseId || id > maxId) throw new IllegalArgumentException("'" + value + "' encodes to '" + id + "' which is out of range [" + baseId + "," + maxId + "]"); return id; }
public DateStrDictionary(String datePattern, int baseId) { init(datePattern, baseId); }
@Override final protected String getValueFromIdImpl(int id) { if (id < baseId || id > maxId) throw new IllegalArgumentException("ID '" + id + "' is out of range [" + baseId + "," + maxId + "]"); Date d = getDateFromNumOfDaysSince0000(calcSeqNoFromId(id)); return dateToString(d, pattern); }
Date dateValue = DateStrDictionary.stringToDate(strValue); // NOTE: forces GMT timezone long millis = dateValue.getTime(); long days = millis / (1000 * 3600 * 24); return new BigDecimal(strValue); } else if ("timestamp".equals(dataType)) { return Long.valueOf(DateStrDictionary.stringToMillis(strValue)); } else if ("float".equals(dataType)){ return Float.valueOf(strValue);
@Override final protected int getValueBytesFromIdImpl(int id, byte[] returnValue, int offset) { String date = getValueFromId(id); byte bytes[]; try { bytes = date.getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // never happen } System.arraycopy(bytes, 0, returnValue, offset, bytes.length); return bytes.length; }
@Override final protected int getIdFromValueBytesImpl(byte[] value, int offset, int len, int roundingFlag) { try { return getIdFromValue(new String(value, offset, len, "ISO-8859-1")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // never happen } }
@Override public void dump(PrintStream out) { out.println(this.toString()); }
public static Date stringToDate(String str) { return stringToDate(str, DEFAULT_DATE_PATTERN); }
@Override final protected String getValueFromIdImpl(int id) { if (id < baseId || id > maxId) throw new IllegalArgumentException("ID '" + id + "' is out of range [" + baseId + "," + maxId + "]"); Date d = getDateFromNumOfDaysSince0000(calcSeqNoFromId(id)); return DateFormat.dateToString(d, pattern); }
@Override final protected int getIdFromValueImpl(String value, int roundFlag) { Date date = DateFormat.stringToDate(value, pattern); int id = calcIdFromSeqNo(getNumOfDaysSince0000(date)); if (id < baseId || id > maxId) throw new IllegalArgumentException("'" + value + "' encodes to '" + id + "' which is out of range [" + baseId + "," + maxId + "]"); return id; }
@Override final protected String getValueFromIdImpl(int id) { if (id < baseId || id > maxId) throw new IllegalArgumentException("ID '" + id + "' is out of range [" + baseId + "," + maxId + "]"); long millis = DateDimEnc.getMillisFromNumOfDaysSince0000(calcSeqNoFromId(id)); return dateToString(new Date(millis), pattern); }
public long getTimestamp() { String str = getValueString(info.getTimestampColumn()); return DateStrDictionary.stringToMillis(str); }
public DateStrDictionary() { init(DEFAULT_DATE_PATTERN, 0); }
@Override final protected int getValueBytesFromIdImpl(int id, byte[] returnValue, int offset) { String date = getValueFromId(id); byte bytes[]; try { bytes = date.getBytes("ISO-8859-1"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // never happen } System.arraycopy(bytes, 0, returnValue, offset, bytes.length); return bytes.length; }
@Override final protected int getIdFromValueBytesImpl(byte[] value, int offset, int len, int roundingFlag) { try { return getIdFromValue(new String(value, offset, len, "ISO-8859-1")); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); // never happen } }
@Override public void dump(PrintStream out) { out.println(this.toString()); }