Search in sources :

Example 1 with FunctionNameFilterAll

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll 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 FunctionNameFilterAll

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll 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 FunctionNameFilterAll

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll 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 FunctionNameFilterAll

use of com.sldeditor.filter.v2.function.namefilter.FunctionNameFilterAll 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

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