提交 2b38907d 编写于 作者: M Mathieu Bastian

Fix import container factory and add addTimestamps() and addIntervals() methods to ElementDraft

上级 daafd56b
......@@ -42,6 +42,7 @@
package org.gephi.io.importer.api;
import java.awt.Color;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.types.TimeSet;
/**
......@@ -370,10 +371,14 @@ public interface ElementDraft {
public void addTimestamp(String dateTime);
public void addTimestamps(String timestamps);
public void addInterval(double start, double end);
public void addInterval(String startDateTime, String endDateTime);
public void addIntervals(String intervals);
public TimeSet getTimeSet();
public Iterable<ColumnDraft> getColumns();
......
......@@ -45,6 +45,7 @@ package org.gephi.io.importer.impl;
import java.awt.Color;
import org.gephi.graph.api.AttributeUtils;
import org.gephi.graph.api.Interval;
import org.gephi.graph.api.TimeFormat;
import org.gephi.graph.api.TimeRepresentation;
import org.gephi.graph.api.types.IntervalMap;
import org.gephi.graph.api.types.IntervalSet;
......@@ -230,7 +231,7 @@ public abstract class ElementDraftImpl implements ElementDraft {
@Override
public void setValue(String key, Object value, String dateTime) {
setValue(key, value, AttributeUtils.parseDateTime(dateTime));
setValue(key, value, container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(dateTime) : AttributeUtils.parseDateTime(dateTime));
}
@Override
......@@ -246,7 +247,18 @@ public abstract class ElementDraftImpl implements ElementDraft {
@Override
public void setValue(String key, Object value, String startDateTime, String endDateTime) {
setValue(key, value, AttributeUtils.parseDateTime(startDateTime), AttributeUtils.parseDateTime(endDateTime));
double start, end;
if (startDateTime == null || startDateTime.isEmpty() || "-inf".equalsIgnoreCase(startDateTime) || "-infinity".equalsIgnoreCase(startDateTime)) {
start = Double.NEGATIVE_INFINITY;
} else {
start = container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(startDateTime) : AttributeUtils.parseDateTime(startDateTime);
}
if (endDateTime == null || endDateTime.isEmpty() || "inf".equalsIgnoreCase(endDateTime) || "infinity".equalsIgnoreCase(endDateTime)) {
end = Double.POSITIVE_INFINITY;
} else {
end = container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(endDateTime) : AttributeUtils.parseDateTime(endDateTime);
}
setValue(key, value, start, end);
}
@Override
......@@ -264,13 +276,23 @@ public abstract class ElementDraftImpl implements ElementDraft {
@Override
public void parseAndSetValue(String key, String value) {
ColumnDraft column = getColumn(key);
Object val = AttributeUtils.parse(value, column.getTypeClass());
Class typeClass;
if (column.isDynamic()) {
if (container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
typeClass = AttributeUtils.getIntervalMapType(column.getTypeClass());
} else {
typeClass = AttributeUtils.getTimestampMapType(column.getTypeClass());
}
} else {
typeClass = column.getTypeClass();
}
Object val = AttributeUtils.parse(value, typeClass);
setValue(key, val);
}
@Override
public void parseAndSetValue(String key, String value, String dateTime) {
parseAndSetValue(key, value, AttributeUtils.parseDateTime(dateTime));
parseAndSetValue(key, value, container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(dateTime) : AttributeUtils.parseDateTime(dateTime));
}
@Override
......@@ -283,15 +305,15 @@ public abstract class ElementDraftImpl implements ElementDraft {
@Override
public void parseAndSetValue(String key, String value, String startDateTime, String endDateTime) {
double start, end;
if (startDateTime == null || "-inf".equalsIgnoreCase(startDateTime)) {
if (startDateTime == null || startDateTime.isEmpty() || "-inf".equalsIgnoreCase(startDateTime) || "-infinity".equalsIgnoreCase(startDateTime)) {
start = Double.NEGATIVE_INFINITY;
} else {
start = AttributeUtils.parseDateTime(startDateTime);
start = container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(startDateTime) : AttributeUtils.parseDateTime(startDateTime);
}
if (endDateTime == null || "inf".equalsIgnoreCase(endDateTime)) {
if (endDateTime == null || endDateTime.isEmpty() || "inf".equalsIgnoreCase(endDateTime) || "infinity".equalsIgnoreCase(endDateTime)) {
end = Double.POSITIVE_INFINITY;
} else {
end = AttributeUtils.parseDateTime(endDateTime);
end = container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(endDateTime) : AttributeUtils.parseDateTime(endDateTime);
}
parseAndSetValue(key, value, start, end);
}
......@@ -305,7 +327,7 @@ public abstract class ElementDraftImpl implements ElementDraft {
@Override
public void addTimestamp(String dateTime) {
addTimestamp(AttributeUtils.parseDateTime(dateTime));
addTimestamp(container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(dateTime) : AttributeUtils.parseDateTime(dateTime));
}
@Override
......@@ -321,6 +343,23 @@ public abstract class ElementDraftImpl implements ElementDraft {
timeSet.add(timestamp);
}
@Override
public void addTimestamps(String timestamps) {
if (!container.getTimeRepresentation().equals(TimeRepresentation.TIMESTAMP)) {
String message = NbBundle.getMessage(ElementDraftImpl.class, "ElementDraftException_NotTimestampRepresentation", id);
container.getReport().logIssue(new Issue(message, Issue.Level.SEVERE));
return;
}
TimestampSet t = (TimestampSet) AttributeUtils.parse(timestamps, TimestampSet.class);
if (timeSet == null) {
timeSet = t;
} else {
for (Double d : t.toArray()) {
timeSet.add(d);
}
}
}
@Override
public TimeSet getTimeSet() {
return timeSet;
......@@ -329,19 +368,36 @@ public abstract class ElementDraftImpl implements ElementDraft {
@Override
public void addInterval(String intervalStartDateTime, String intervalEndDateTime) {
double start, end;
if (intervalStartDateTime == null || "-inf".equalsIgnoreCase(intervalStartDateTime)) {
if (intervalStartDateTime == null || intervalStartDateTime.isEmpty() || "-inf".equalsIgnoreCase(intervalStartDateTime) || "-infinity".equalsIgnoreCase(intervalStartDateTime)) {
start = Double.NEGATIVE_INFINITY;
} else {
start = AttributeUtils.parseDateTime(intervalStartDateTime);
start = container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(intervalStartDateTime) : AttributeUtils.parseDateTime(intervalStartDateTime);
}
if (intervalEndDateTime == null || "inf".equalsIgnoreCase(intervalEndDateTime)) {
if (intervalEndDateTime == null || intervalEndDateTime.isEmpty() || "inf".equalsIgnoreCase(intervalEndDateTime) || "infinity".equalsIgnoreCase(intervalEndDateTime)) {
end = Double.POSITIVE_INFINITY;
} else {
end = AttributeUtils.parseDateTime(intervalStartDateTime);
end = container.getTimeFormat().equals(TimeFormat.DOUBLE) ? Double.parseDouble(intervalEndDateTime) : AttributeUtils.parseDateTime(intervalStartDateTime);
}
addInterval(start, end);
}
@Override
public void addIntervals(String intervals) {
if (!container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
String message = NbBundle.getMessage(ElementDraftImpl.class, "ElementDraftException_NotIntervalRepresentation", id);
container.getReport().logIssue(new Issue(message, Issue.Level.SEVERE));
return;
}
IntervalSet s = (IntervalSet) AttributeUtils.parse(intervals, IntervalSet.class);
if (timeSet == null) {
timeSet = s;
} else {
for (Interval i : s.toArray()) {
timeSet.add(i);
}
}
}
@Override
public void addInterval(double intervalStart, double intervalEnd) {
if (!container.getTimeRepresentation().equals(TimeRepresentation.INTERVAL)) {
......@@ -401,7 +457,7 @@ public abstract class ElementDraftImpl implements ElementDraft {
throw new RuntimeException("The expected value class was " + typeClass.getSimpleName() + " and " + value.getClass().getSimpleName() + " was found");
}
if (!column.isDynamic()) {
//TODO
throw new RuntimeException("Can't set a dynamic value to a static column");
}
if (index >= attributes.length) {
Object[] newArray = new Object[index + 1];
......@@ -423,6 +479,9 @@ public abstract class ElementDraftImpl implements ElementDraft {
if (!value.getClass().equals(typeClass)) {
throw new RuntimeException("The expected value class was " + typeClass.getSimpleName() + " and " + value.getClass().getSimpleName() + " was found");
}
if (!column.isDynamic()) {
throw new RuntimeException("Can't set a dynamic value to a static column");
}
Interval interval = new Interval(start, end);
if (index >= attributes.length) {
Object[] newArray = new Object[index + 1];
......
......@@ -58,7 +58,7 @@ public class ElementFactoryImpl implements ElementDraft.Factory {
@Override
public NodeDraftImpl newNodeDraft() {
NodeDraftImpl node = new NodeDraftImpl(container, "n" + NODE_IDS.getAndIncrement());
NodeDraftImpl node = new NodeDraftImpl(container, String.valueOf(NODE_IDS.getAndIncrement()));
return node;
}
......@@ -74,7 +74,7 @@ public class ElementFactoryImpl implements ElementDraft.Factory {
@Override
public EdgeDraftImpl newEdgeDraft() {
EdgeDraftImpl edge = new EdgeDraftImpl(container, "e" + EDGE_IDS.getAndIncrement());
EdgeDraftImpl edge = new EdgeDraftImpl(container, String.valueOf(EDGE_IDS.getAndIncrement()));
return edge;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册