mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Search-340, move logic into RangeParm class
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.alfresco.service.cmr.search;
|
package org.alfresco.service.cmr.search;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -121,4 +122,65 @@ public class RangeParameters
|
|||||||
{
|
{
|
||||||
return excludeFilters;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user