Search in sources :

Example 1 with FunctionNameFilterInterface

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface in project sldeditor by robward-scisys.

the class FunctionManagerTest method testGetFunctionType.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.function.FunctionManager#getFunctionType(java.lang.String)}.
 */
@Test
public void testGetFunctionType() {
    Class<?> returnType = FunctionManager.getInstance().getFunctionType(null);
    assertNull(returnType);
    List<FunctionNameFilterInterface> functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
    FunctionNameFilterAll allFilter = new FunctionNameFilterAll();
    allFilter.accept(null);
    functionNameFilterList.add(allFilter);
    List<FunctionName> functionNameList = FunctionManager.getInstance().getFunctionNameList(null, null);
    for (FunctionName functionName : functionNameList) {
        returnType = FunctionManager.getInstance().getFunctionType(functionName.getName());
        assertEquals(functionName.getName(), functionName.getReturn().getType(), returnType);
    }
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionNameFilterAll(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll) FunctionNameFilterInterface(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with FunctionNameFilterInterface

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface in project sldeditor by robward-scisys.

the class FunctionField method setDataType.

/**
 * Sets the field data types.
 *
 * @param fieldType the new data type
 * @param isRasterSymbol the is raster symbol
 */
public void setDataType(Class<?> fieldType, boolean isRasterSymbol) {
    functionNameMap.clear();
    List<FunctionNameFilterInterface> functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
    if (isRasterSymbol) {
        functionNameFilterList.add(new FunctionNameFilterRaster());
    } else {
        functionNameFilterList.add(new FunctionNameFilterAll());
    }
    List<FunctionName> functionNameList = functionNameMgr.getFunctionNameList(fieldType, functionNameFilterList);
    for (FunctionName functionName : functionNameList) {
        String functionNameString = functionName.getName();
        functionNameMap.put(functionNameString, functionName);
    }
    populateFunctionComboBox();
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionNameFilterAll(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll) FunctionNameFilterInterface(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface) ArrayList(java.util.ArrayList) FunctionNameFilterRaster(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterRaster)

Example 3 with FunctionNameFilterInterface

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface in project sldeditor by robward-scisys.

the class FunctionManager method getFunctionNameList.

/**
 * Gets the function name list for the given parameter type A
 * expectedType of null returns all functions.
 *
 * @param expectedType the expected type, restrict functions with this return type
 * @param functionNameFilterList the function name filter list
 * @return the function name list
 */
@Override
public List<FunctionName> getFunctionNameList(Class<?> expectedType, List<FunctionNameFilterInterface> functionNameFilterList) {
    if (expectedType == null) {
        return functionNameList;
    }
    if (functionNameFilterList == null) {
        functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
        functionNameFilterList.add(new FunctionNameFilterAll());
    }
    List<FunctionName> list = new ArrayList<FunctionName>();
    List<Class<?>> allowedTypes = allowedTypeMap.get(expectedType);
    if (allowedTypes != null) {
        for (FunctionName functionName : functionNameList) {
            Class<?> returnType = functionName.getReturn().getType();
            if (allowedTypes.contains(returnType) && matchesFilter(functionName, functionNameFilterList)) {
                list.add(functionName);
            }
        }
    }
    return list;
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionNameFilterAll(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll) FunctionNameFilterInterface(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface) ArrayList(java.util.ArrayList)

Example 4 with FunctionNameFilterInterface

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface in project sldeditor by robward-scisys.

the class FunctionManagerTest method testGetFunctionNameList2.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.function.FunctionManager#getFunctionNameList(java.lang.Class)}.
 * Testing FunctionNameFilterRaster
 */
@Test
public void testGetFunctionNameList2() {
    Class<?> returnType = FunctionManager.getInstance().getFunctionType(null);
    assertNull(returnType);
    List<FunctionName> functionNameList = FunctionManager.getInstance().getFunctionNameList(Object.class, null);
    FunctionName propertyFunction = null;
    FunctionName idFunction = null;
    FunctionName areaFunction = null;
    FunctionName ceilFunction = null;
    for (FunctionName functionName : functionNameList) {
        if (functionName.getName().compareTo("property") == 0) {
            propertyFunction = functionName;
        } else if (functionName.getName().compareTo("id") == 0) {
            idFunction = functionName;
        } else if (functionName.getName().compareTo("Area") == 0) {
            areaFunction = functionName;
        } else if (functionName.getName().compareTo("ceil") == 0) {
            ceilFunction = functionName;
        }
    }
    assertNotNull(propertyFunction);
    assertNotNull(areaFunction);
    assertNotNull(ceilFunction);
    assertNotNull(idFunction);
    List<FunctionNameFilterInterface> functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
    FunctionNameFilterRaster rasterFilter = new FunctionNameFilterRaster();
    rasterFilter.accept(null);
    functionNameFilterList.add(rasterFilter);
    List<FunctionName> rasterFunctionNameList = FunctionManager.getInstance().getFunctionNameList(Object.class, functionNameFilterList);
    assertFalse(rasterFunctionNameList.contains(propertyFunction));
    assertFalse(rasterFunctionNameList.contains(areaFunction));
    assertFalse(rasterFunctionNameList.contains(idFunction));
    assertTrue(rasterFunctionNameList.contains(ceilFunction));
}
Also used : FunctionName(org.opengis.filter.capability.FunctionName) FunctionNameFilterInterface(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface) ArrayList(java.util.ArrayList) FunctionNameFilterRaster(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterRaster) Test(org.junit.Test)

Example 5 with FunctionNameFilterInterface

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface in project sldeditor by robward-scisys.

the class FunctionManagerTest method testGetFunctionNameList.

/**
 * Test method for
 * {@link com.sldeditor.filter.v2.function.FunctionManager#getFunctionNameList(java.lang.Class)}.
 */
@Test
public void testGetFunctionNameList() {
    DefaultFunctionFactory functionFactory = new DefaultFunctionFactory();
    List<FunctionName> functionNameList = functionFactory.getFunctionNames();
    // CHECKSTYLE:OFF
    Class<?>[] allowedNumberTypes = { Number.class, Double.class, Float.class, Integer.class, Long.class, Object.class };
    // CHECKSTYLE:ON
    List<Class<?>> allowedNumberTypesList = Arrays.asList(allowedNumberTypes);
    int count = 0;
    for (FunctionName functionName : functionNameList) {
        Class<?> type = functionName.getReturn().getType();
        if (allowedNumberTypesList.contains(type)) {
            count++;
        }
    }
    List<FunctionNameFilterInterface> functionNameFilterList = new ArrayList<FunctionNameFilterInterface>();
    functionNameFilterList.add(new FunctionNameFilterAll());
    List<FunctionName> actualList = FunctionManager.getInstance().getFunctionNameList(Number.class, functionNameFilterList);
    assertEquals(count, actualList.size());
    // Try with null
    actualList = FunctionManager.getInstance().getFunctionNameList(null, null);
    assertEquals(functionNameList.size(), actualList.size());
    // Try with non-matching class
    actualList = FunctionManager.getInstance().getFunctionNameList(FunctionManagerTest.class, functionNameFilterList);
    assertTrue(actualList.isEmpty());
}
Also used : FunctionNameFilterAll(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll) ArrayList(java.util.ArrayList) FunctionName(org.opengis.filter.capability.FunctionName) DefaultFunctionFactory(org.geotools.filter.function.DefaultFunctionFactory) FunctionNameFilterInterface(com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface) Test(org.junit.Test)

Aggregations

FunctionNameFilterInterface (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterInterface)5 ArrayList (java.util.ArrayList)5 FunctionName (org.opengis.filter.capability.FunctionName)5 FunctionNameFilterAll (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll)4 Test (org.junit.Test)3 FunctionNameFilterRaster (com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterRaster)2 DefaultFunctionFactory (org.geotools.filter.function.DefaultFunctionFactory)1