private Object getValueInternal(String key, Object timeObj) { TimeMap valueSet = (TimeMap) attributes.get(key); if (valueSet != null) { return valueSet.get(timeObj, null); } return null; }
@Override public void setEstimator(Estimator estimator) { if (!dynamic) { throw new IllegalStateException("The column must have a dynamic type"); } if (TimeMap.class.isAssignableFrom(typeClass)) { TimeMap vs = null; try { vs = (TimeMap) typeClass.newInstance(); } catch (InstantiationException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } if (!vs.isSupported(estimator)) { throw new IllegalArgumentException("The column doesnt't support this estimator"); } this.estimator = estimator; } }
valueSet = (TimeMap) attributes.get(key); if (!value.getClass().equals(valueSet.getTypeClass())) { throw new IllegalArgumentException( "The value type " + value.getClass().getName() + " doesn't match with the expected type " + valueSet .getTypeClass().getName()); valueSet.put(timeObj, value);
@Override public Object getAttribute(Column column, GraphView view) { checkColumn(column); if (!column.isDynamic()) { return getAttribute(column); } else { Interval interval = view.getTimeInterval(); checkViewExist((GraphView) view); int index = column.getIndex(); synchronized (this) { TimeMap dynamicValue = null; if (index < attributes.length) { dynamicValue = (TimeMap) attributes[index]; } if (dynamicValue != null && !dynamicValue.isEmpty()) { Estimator estimator = column.getEstimator(); if (estimator == null) { estimator = GraphStoreConfiguration.DEFAULT_ESTIMATOR; } return dynamicValue.get(interval, estimator); } } } return null; }
@Override protected void refresh() { if (graph != null) { parts.clear(); elements = 0; ElementIterable<? extends Element> iterable = AttributeUtils.isNodeColumn(column) ? graph.getNodes() : graph.getEdges(); for (Element el : iterable) { TimeMap val = (TimeMap) el.getAttribute(column); if (val != null) { Object[] va = val.toValuesArray(); for (Object v : va) { Integer count = parts.get(v); if (count == null) { count = 0; } parts.put(v, ++count); elements++; } } } } }
private Object removeTimeAttribute(Column column, Object timeObject) { checkColumn(column); checkColumnDynamic(column); checkReadOnlyColumn(column); int index = column.getIndex(); Object oldValue = null; boolean res = false; synchronized (this) { TimeMap dynamicValue = (TimeMap) attributes[index]; if (dynamicValue != null) { oldValue = dynamicValue.get(timeObject, null); res = dynamicValue.remove(timeObject); } } if (res && isValid()) { TimeIndexStore timeIndexStore = getTimeIndexStore(); if (timeIndexStore != null) { timeIndexStore.remove(timeObject); } ((ColumnImpl) column).incrementVersion(this); } return oldValue; }
/** * Returns the string representation of the given value. * * @param value value * @param timeFormat time format * @param timeZone time zone * @return string representation */ public static String print(Object value, TimeFormat timeFormat, DateTimeZone timeZone) { if (value == null) { return "null"; } if (value instanceof TimeSet) { return ((TimeSet) value).toString(timeFormat, timeZone); } if (value instanceof TimeMap) { return ((TimeMap) value).toString(timeFormat, timeZone); } if (value.getClass().isArray()) { return printArray(value); } return value.toString(); }
if (parsed instanceof TimeMap && ((TimeMap) parsed).isEmpty()) {
public void add(TimeMap<K, ?> timeMap) { for (K timeKey : timeMap.toKeysArray()) { add(timeKey); } }
private void setTimeWeight(double weight, Object timeObject) { checkWeightDynamicType(); boolean res; synchronized (this) { Object oldValue = attributes[GraphStoreConfiguration.EDGE_WEIGHT_INDEX]; TimeMap dynamicValue = null; if (oldValue == null) { try { attributes[GraphStoreConfiguration.EDGE_WEIGHT_INDEX] = dynamicValue = (TimeMap) graphStore.configuration .getEdgeWeightType().newInstance(); } catch (InstantiationException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } } else { dynamicValue = (TimeMap) oldValue; } res = dynamicValue.put(timeObject, weight); } TimeIndexStore timeIndexStore = getTimeIndexStore(); if (res && timeIndexStore != null && isValid()) { timeIndexStore.add(timeObject); } ColumnStore columnStore = getColumnStore(); if (res && columnStore != null && isValid()) { Column column = columnStore.getColumnByIndex(GraphStoreConfiguration.EDGE_WEIGHT_INDEX); ((ColumnImpl) column).incrementVersion(this); } }
@Override public Object getAttribute(Column column, GraphView view) { checkColumn(column); if (!column.isDynamic()) { return getAttribute(column); } else { Interval interval = view.getTimeInterval(); checkViewExist((GraphView) view); int index = column.getIndex(); synchronized (this) { TimeMap dynamicValue = null; if (index < attributes.length) { dynamicValue = (TimeMap) attributes[index]; } if (dynamicValue != null && !dynamicValue.isEmpty()) { Estimator estimator = column.getEstimator(); if (estimator == null) { estimator = GraphStoreConfiguration.DEFAULT_ESTIMATOR; } return dynamicValue.get(interval, estimator); } } } return null; }
@Override public Iterable<Map.Entry> getWeights() { synchronized (this) { Object weightValue = attributes[GraphStoreConfiguration.EDGE_WEIGHT_INDEX]; if (weightValue instanceof Double) { throw new IllegalStateException("The weight is static, call getWeight() instead"); } TimeMap dynamicValue = (TimeMap) weightValue; Object[] values = dynamicValue.toValuesArray(); if (dynamicValue instanceof TimestampMap) { return new TimeAttributeIterable(((TimestampMap) dynamicValue).getTimestamps(), values); } else if (dynamicValue instanceof IntervalMap) { return new TimeAttributeIterable(((IntervalMap) dynamicValue).toKeysArray(), values); } } return TimeAttributeIterable.EMPTY_ITERABLE; }
private Object removeTimeAttribute(Column column, Object timeObject) { checkColumn(column); checkColumnDynamic(column); checkReadOnlyColumn(column); int index = column.getIndex(); Object oldValue = null; boolean res = false; synchronized (this) { TimeMap dynamicValue = (TimeMap) attributes[index]; if (dynamicValue != null) { oldValue = dynamicValue.get(timeObject, null); res = dynamicValue.remove(timeObject); } } if (res && isValid()) { TimeIndexStore timeIndexStore = getTimeIndexStore(); if (timeIndexStore != null) { timeIndexStore.remove(timeObject); } ((ColumnImpl) column).incrementVersion(this); } return oldValue; }
/** * Returns the string representation of the given value. * * @param value value * @param timeFormat time format * @param timeZone time zone * @return string representation */ public static String print(Object value, TimeFormat timeFormat, DateTimeZone timeZone) { if (value == null) { return "null"; } if (value instanceof TimeSet) { return ((TimeSet) value).toString(timeFormat, timeZone); } if (value instanceof TimeMap) { return ((TimeMap) value).toString(timeFormat, timeZone); } if (value.getClass().isArray()) { return printArray(value); } return value.toString(); }
valueSet = (TimeMap) attributes.get(key); if (!value.getClass().equals(valueSet.getTypeClass())) { throw new IllegalArgumentException( "The value type " + value.getClass().getName() + " doesn't match with the expected type " + valueSet .getTypeClass().getName()); valueSet.put(timeObj, value);
public void remove(M timeMap) { for (K timeKey : timeMap.toKeysArray()) { remove(timeKey); } }
private void setTimeWeight(double weight, Object timeObject) { checkWeightDynamicType(); boolean res; synchronized (this) { Object oldValue = attributes[GraphStoreConfiguration.EDGE_WEIGHT_INDEX]; TimeMap dynamicValue = null; if (oldValue == null) { try { attributes[GraphStoreConfiguration.EDGE_WEIGHT_INDEX] = dynamicValue = (TimeMap) graphStore.configuration .getEdgeWeightType().newInstance(); } catch (InstantiationException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); } } else { dynamicValue = (TimeMap) oldValue; } res = dynamicValue.put(timeObject, weight); } TimeIndexStore timeIndexStore = getTimeIndexStore(); if (res && timeIndexStore != null && isValid()) { timeIndexStore.add(timeObject); } ColumnStore columnStore = getColumnStore(); if (res && columnStore != null && isValid()) { Column column = columnStore.getColumnByIndex(GraphStoreConfiguration.EDGE_WEIGHT_INDEX); ((ColumnImpl) column).incrementVersion(this); } }
private Object getValueInternal(String key, Object timeObj) { TimeMap valueSet = (TimeMap) attributes.get(key); if (valueSet != null) { return valueSet.get(timeObj, null); } return null; }
@Override public Iterable<Map.Entry> getWeights() { synchronized (this) { Object weightValue = attributes[GraphStoreConfiguration.EDGE_WEIGHT_INDEX]; if (weightValue instanceof Double) { throw new IllegalStateException("The weight is static, call getWeight() instead"); } TimeMap dynamicValue = (TimeMap) weightValue; Object[] values = dynamicValue.toValuesArray(); if (dynamicValue instanceof TimestampMap) { return new TimeAttributeIterable(((TimestampMap) dynamicValue).getTimestamps(), values); } else if (dynamicValue instanceof IntervalMap) { return new TimeAttributeIterable(((IntervalMap) dynamicValue).toKeysArray(), values); } } return TimeAttributeIterable.EMPTY_ITERABLE; }