Search in sources :

Example 1 with AbstractSource

use of com.baidu.hugegraph.loader.source.AbstractSource in project incubator-hugegraph-toolchain by apache.

the class DataTypeUtil method split.

private static List<Object> split(String key, String rawValue, InputSource source) {
    List<Object> valueColl = new ArrayList<>();
    if (rawValue.isEmpty()) {
        return valueColl;
    }
    E.checkState(AbstractSource.class.isAssignableFrom(source.getClass()), "Only accept AbstractSource when parse multi values, " + "but got '%s'", source.getClass().getName());
    ListFormat listFormat = ((AbstractSource) source).listFormat();
    E.checkArgumentNotNull(listFormat, "The list_format must be set when " + "parse list or set values");
    String startSymbol = listFormat.startSymbol();
    String endSymbol = listFormat.endSymbol();
    E.checkArgument(rawValue.length() >= startSymbol.length() + endSymbol.length(), "The value(key='%s') '%s' length(%s) must be >= " + "start symbol '%s' + end symbol '%s' length", key, rawValue, rawValue.length(), startSymbol, endSymbol);
    E.checkArgument(rawValue.startsWith(startSymbol) && rawValue.endsWith(endSymbol), "The value(key='%s') must start with '%s' and " + "end with '%s', but got '%s'", key, startSymbol, endSymbol, rawValue);
    rawValue = rawValue.substring(startSymbol.length(), rawValue.length() - endSymbol.length());
    String elemDelimiter = listFormat.elemDelimiter();
    Splitter.on(elemDelimiter).split(rawValue).forEach(value -> {
        if (!listFormat.ignoredElems().contains(value)) {
            valueColl.add(value);
        }
    });
    return valueColl;
}
Also used : ArrayList(java.util.ArrayList) AbstractSource(com.baidu.hugegraph.loader.source.AbstractSource) ListFormat(com.baidu.hugegraph.loader.source.file.ListFormat)

Aggregations

AbstractSource (com.baidu.hugegraph.loader.source.AbstractSource)1 ListFormat (com.baidu.hugegraph.loader.source.file.ListFormat)1 ArrayList (java.util.ArrayList)1