Permalink
Browse files

Update MaskTree#getOperations method to handle array range attributes.

RB=1173612
G=si-dev
R=kbalasub,mnchen
A=kbalasub
  • Loading branch information...
Arun Ponniah Sethuramalingam
Arun Ponniah Sethuramalingam committed Dec 5, 2017
1 parent 9479cac commit b42054898c434ca43bbaaad549e46214c76cfd4b
View
@@ -1,7 +1,12 @@
17.0.3
17.0.4
------
17.0.3
------
(RB=1173612)
Update MaskTree#getOperations method to handle array range attributes.
17.0.2
------
(RB=1172849)
@@ -31,6 +31,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @author Josh Walker
@@ -147,6 +149,12 @@ private void getOperationsImpl(DataMap data, PathSpec path, Map<PathSpec, MaskOp
for (Map.Entry<String, Object> entry : data.entrySet())
{
String segment = Escaper.unescapePathSegment(entry.getKey());
// Ignore if the segment is $start or $count, as we have already taken care of the array ranges
if (FilterConstants.START.equals(segment) || FilterConstants.COUNT.equals(segment))
{
continue;
}
PathSpec subpath = new PathSpec(path.getPathComponents(), segment);
Object value = entry.getValue();
if (value instanceof Integer)
@@ -166,7 +174,12 @@ else if (value.equals(MaskOperation.POSITIVE_MASK_OP.getRepresentation()))
}
else if (value.getClass() == DataMap.class)
{
getOperationsImpl((DataMap) value, subpath, result);
DataMap subMask = (DataMap) value;
Optional<PathSpec> pathWithAttributes = addArrayRangeAttributes(subMask, subpath);
pathWithAttributes.ifPresent(p -> result.put(p, MaskOperation.POSITIVE_MASK_OP));
getOperationsImpl(subMask, subpath, result);
}
else
{
@@ -175,6 +188,27 @@ else if (value.getClass() == DataMap.class)
}
}
/**
* If the specified mask contains array range attributes, add them to the pathSpec parameter and return the updated
* pathSpec. If the mask doesn't have any array range attributes return an empty Optional.
*/
private Optional<PathSpec> addArrayRangeAttributes(DataMap mask, PathSpec pathSpec)
{
Object start = mask.get(FilterConstants.START);
if (start != null)
{
pathSpec.setAttribute(PathSpec.ATTR_ARRAY_START, start);
}
Object count = mask.get(FilterConstants.COUNT);
if (count != null)
{
pathSpec.setAttribute(PathSpec.ATTR_ARRAY_COUNT, count);
}
return (start != null || count != null) ? Optional.of(pathSpec) : Optional.empty();
}
@Override
public String toString()
{
@@ -30,6 +30,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -100,6 +101,11 @@ public void testPositiveMaskWithArrayRange()
expectedMaskMap.put("parent", parentMap);
Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
Map<PathSpec, MaskOperation> operations = mask.getOperations();
Assert.assertEquals(operations.size(), 2);
Assert.assertEquals(operations.get(childPath), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(operations.get(grandChildPath), MaskOperation.POSITIVE_MASK_OP);
}
@Test
@@ -123,6 +129,10 @@ public void testPositiveMaskWithDefaultArrayRangeValues()
expectedMaskMap.put("parent", parentMap);
Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
Map<PathSpec, MaskOperation> operations = mask.getOperations();
Assert.assertEquals(operations.size(), 1);
Assert.assertEquals(operations.get(grandChildPath), MaskOperation.POSITIVE_MASK_OP);
}
@Test
@@ -148,6 +158,11 @@ public void testPositiveMaskWithArrayWildcardAndRange()
expectedMaskMap.put("parent", parentMap);
Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
Map<PathSpec, MaskOperation> operations = mask.getOperations();
Assert.assertEquals(operations.size(), 2);
Assert.assertEquals(operations.get(childPath), MaskOperation.POSITIVE_MASK_OP);
Assert.assertEquals(operations.get(grandChildrenPath), MaskOperation.POSITIVE_MASK_OP);
}
@Test
@@ -168,6 +183,14 @@ public void testPositiveMaskWithRandomAttributes()
expectedMaskMap.put("parent", parentMap);
Assert.assertEquals(mask.getDataMap(), expectedMaskMap);
// Create a copy of the childPath without the random attribute as the generated mask won't include those attributes
PathSpec childPathCopy = new PathSpec(childPath.getPathComponents().toArray(new String[0]));
childPathCopy.setAttribute(PathSpec.ATTR_ARRAY_COUNT, 5);
Map<PathSpec, MaskOperation> operations = mask.getOperations();
Assert.assertEquals(operations.size(), 1);
Assert.assertEquals(operations.get(childPathCopy), MaskOperation.POSITIVE_MASK_OP);
}
@Test
@@ -174,7 +174,7 @@ public boolean equals(Object obj)
@Override
public int hashCode()
{
return _path.hashCode();
return Objects.hash(_path, _attributes);
}
private final List<String> _path;
View
@@ -1,4 +1,4 @@
version=17.0.2
version=17.0.3
sonatypeUsername=please_set_in_home_dir_if_uploading_to_maven_central
sonatypePassword=please_set_in_home_dir_if_uploading_to_maven_central
org.gradle.configureondemand=true

0 comments on commit b420548

Please sign in to comment.