Skip to content

Commit 9d94be4

Browse files
authored
Merge pull request #16 from appform-io/map_getters_setters
Added Getter and Setters for DataSet for backward compatibility of projects using com.flipkart artifact
2 parents 3fec01a + 1230b44 commit 9d94be4

3 files changed

Lines changed: 68 additions & 1 deletion

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55

66
<groupId>io.appform.databuilderframework</groupId>
7-
<version>1.1.1</version>
7+
<version>1.1.2</version>
88
<modelVersion>4.0.0</modelVersion>
99

1010
<artifactId>databuilderframework</artifactId>

src/main/java/io/appform/databuilderframework/model/DataSet.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.fasterxml.jackson.annotation.JsonProperty;
44
import com.google.common.base.Predicates;
55
import com.google.common.base.Strings;
6+
import com.google.common.collect.ImmutableSet;
67
import com.google.common.collect.Maps;
78
import io.appform.databuilderframework.engine.DataSetAccessor;
89
import io.appform.databuilderframework.engine.Utils;
@@ -58,6 +59,14 @@ public <T extends Data> DataSet add(T data) {
5859
return add(Utils.name(data.getClass()), data);
5960
}
6061

62+
public Data remove(final String dataName) {
63+
return safeWriteOp(() -> availableData.remove(dataName));
64+
}
65+
66+
public Data remove(final Class<?> dataClass) {
67+
return safeWriteOp(() -> availableData.remove(Utils.name(dataClass)));
68+
}
69+
6170
public Map<String, Data> filter(final Collection<String> requiredKeys) {
6271
if (null == requiredKeys || requiredKeys.isEmpty()) {
6372
return Collections.emptyMap();
@@ -103,6 +112,10 @@ public DataSetAccessor accessor() {
103112
return accessor(this);
104113
}
105114

115+
public Set<String> keySet() {
116+
return safeOp(() -> ImmutableSet.copyOf(availableData.keySet()));
117+
}
118+
106119
private <T> T safeOp(Supplier<T> operation) {
107120
val stamp = lock.readLock();
108121
try {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.appform.databuilderframework.model;
2+
3+
import io.appform.databuilderframework.engine.Utils;
4+
import junit.framework.TestCase;
5+
import org.junit.Test;
6+
7+
import java.util.Set;
8+
9+
public class DataSetTest extends TestCase {
10+
11+
public class TestData extends Data {
12+
protected TestData() {
13+
super(Utils.name(TestData.class));
14+
}
15+
}
16+
17+
@Test
18+
public void testKeyRemovalFromDataSetKeyExists() {
19+
DataSet ds = new DataSet();
20+
ds.add(new TestData());
21+
assertNotNull(ds.get(Utils.name(TestData.class)));
22+
Data removedData = ds.remove(Utils.name(TestData.class));
23+
assertNotNull(removedData);
24+
assertNull(ds.get(Utils.name(TestData.class)));
25+
}
26+
27+
@Test
28+
public void testKeyRemovalFromDataSetKeyDoesNotExist() {
29+
DataSet ds = new DataSet();
30+
assertNull(ds.get(Utils.name(TestData.class)));
31+
assertNull(ds.remove(Utils.name(TestData.class)));
32+
assertNull(ds.get(Utils.name(TestData.class)));
33+
}
34+
35+
@Test
36+
public void testKeyRemovalFromDataSetWithClassAsParameter() {
37+
DataSet ds = new DataSet();
38+
ds.add(new TestData());
39+
assertNotNull(ds.get(Utils.name(TestData.class)));
40+
Data removedData = ds.remove(TestData.class);
41+
assertNotNull(removedData);
42+
assertNull(ds.get(Utils.name(TestData.class)));
43+
}
44+
45+
@Test
46+
public void testKeySetFetch() {
47+
DataSet ds = new DataSet();
48+
ds.add(new TestData());
49+
Set<String> dataKeys = ds.keySet();
50+
assertNotNull(dataKeys);
51+
assertEquals(1, dataKeys.size());
52+
}
53+
54+
}

0 commit comments

Comments
 (0)