Search-340, move logic into RangeParm class

This commit is contained in:
Michael Suzuki
2017-05-25 13:21:17 +01:00
parent 47ae4fbaaf
commit 84ea1a8460
2 changed files with 109 additions and 0 deletions

View File

@@ -25,6 +25,7 @@
*/
package org.alfresco.service.cmr.search;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -121,4 +122,65 @@ public class RangeParameters
{
return excludeFilters;
}
public boolean isRangeStartInclusive()
{
List<String> options = new ArrayList<String>();
if(include != null && !include.isEmpty())
{
options.addAll(include);
}
if(other != null && !other.isEmpty())
{
options.addAll(other);
}
if(!options.isEmpty())
{
for(String startInc : options)
{
switch (startInc)
{
case "before":
return false;
case "outer":
return false;
default:
break;
}
}
}
return true;
}
public boolean isRangeEndInclusive()
{
List<String> options = new ArrayList<String>();
if(include != null && !include.isEmpty())
{
options.addAll(include);
}
if(other != null && !other.isEmpty())
{
options.addAll(other);
}
if(!options.isEmpty())
{
for(String endInc : options)
{
switch (endInc)
{
case "upper":
return true;
case "edge":
return true;
case "outer":
return true;
case "all":
return true;
default:
break;
}
}
}
return false;
}
}

View File

@@ -0,0 +1,47 @@
package org.alfresco.repo.search.cmr.search;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.alfresco.service.cmr.search.RangeParameters;
import org.junit.Assert;
import org.junit.Test;
public class RangeParametersTest
{
@Test
public void startInclusiveTest()
{
RangeParameters p = new RangeParameters("test", "0", "10", "1", true, null, null, null, null);
Assert.assertTrue(p.isRangeStartInclusive());
p = new RangeParameters("test", "0", "10", "1", true, Collections.emptyList(), Collections.emptyList(), null, null);
Assert.assertTrue(p.isRangeStartInclusive());
List<String> includes = new ArrayList<String>();
List<String> other = new ArrayList<String>();
includes.add("upper");
p = new RangeParameters("test", "0", "10", "1", true, Collections.emptyList(), includes, null, null);
Assert.assertTrue(p.isRangeStartInclusive());
other.add("before");
p = new RangeParameters("test", "0", "10", "1", true, other, null, null, null);
Assert.assertFalse(p.isRangeStartInclusive());
p = new RangeParameters("test", "0", "10", "1", true, other, includes, null, null);
Assert.assertFalse(p.isRangeStartInclusive());
}
@Test
public void endInclusiveTest()
{
RangeParameters p = new RangeParameters("test", "0", "10", "1", true, null, null, null, null);
Assert.assertFalse(p.isRangeEndInclusive());
p = new RangeParameters("test", "0", "10", "1", true, Collections.emptyList(), Collections.emptyList(), null, null);
Assert.assertFalse(p.isRangeEndInclusive());
List<String> includes = new ArrayList<String>();
List<String> other = new ArrayList<String>();
includes.add("upper");
p = new RangeParameters("test", "0", "10", "1", true, Collections.emptyList(), includes, null, null);
Assert.assertTrue(p.isRangeEndInclusive());
other.add("before");
p = new RangeParameters("test", "0", "10", "1", true, other, null, null, null);
Assert.assertFalse(p.isRangeEndInclusive());
}
}