Implement copyData as copy constructor on IntentData.
Cleaned up javadocs.
Change-Id: I90e6350244991d4f30180fe501fec9e6fd180d43
diff --git a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleIntentStore.java b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleIntentStore.java
index 06da986..7ef6247 100644
--- a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleIntentStore.java
+++ b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleIntentStore.java
@@ -38,6 +38,9 @@
import static org.onosproject.net.intent.IntentState.*;
import static org.slf4j.LoggerFactory.getLogger;
+/**
+ * Simple single-instance implementation of the intent store.
+ */
@Component(immediate = true)
@Service
public class SimpleIntentStore
@@ -49,19 +52,6 @@
private final Map<Key, IntentData> current = Maps.newConcurrentMap();
private final Map<Key, IntentData> pending = Maps.newConcurrentMap();
- private IntentData copyData(IntentData original) {
- if (original == null) {
- return null;
- }
- IntentData result =
- new IntentData(original.intent(), original.state(), original.version());
-
- if (original.installables() != null) {
- result.setInstallables(original.installables());
- }
- return result;
- }
-
@Activate
public void activate() {
log.info("Started");
@@ -99,7 +89,6 @@
return null;
}
-
/**
* Determines whether an intent data update is allowed. The update must
* either have a higher version than the current data, or the state
@@ -174,6 +163,8 @@
@Override
public void write(IntentData newData) {
+ checkNotNull(newData);
+
synchronized (this) {
// TODO this could be refactored/cleaned up
IntentData currentData = current.get(newData.key());
@@ -183,7 +174,7 @@
if (pendingData.state() == PURGE_REQ) {
current.remove(newData.key(), newData);
} else {
- current.put(newData.key(), copyData(newData));
+ current.put(newData.key(), new IntentData(newData));
}
if (pendingData != null
@@ -219,7 +210,11 @@
@Override
public IntentData getIntentData(Key key) {
- return copyData(current.get(key));
+ IntentData currentData = current.get(key);
+ if (currentData == null) {
+ return null;
+ }
+ return new IntentData(currentData);
}
@Override