Java Code Examples for org.elasticsearch.common.util.CollectionUtils#isEmpty()

The following examples show how to use org.elasticsearch.common.util.CollectionUtils#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonXContentGenerator.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public JsonXContentGenerator(JsonGenerator jsonGenerator, OutputStream os, String... filters) {
    if (jsonGenerator instanceof GeneratorBase) {
        this.base = (GeneratorBase) jsonGenerator;
    } else {
        this.base = null;
    }

    if (CollectionUtils.isEmpty(filters)) {
        this.generator = jsonGenerator;
        this.filter = null;
    } else {
        this.filter = new FilteringGeneratorDelegate(jsonGenerator, new FilterPathBasedFilter(filters), true, true);
        this.generator = this.filter;
    }

    this.os = os;
}
 
Example 2
Source File: FilterPath.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
public static FilterPath[] compile(String... filters) {
    if (CollectionUtils.isEmpty(filters)) {
        return null;
    }

    List<FilterPath> paths = new ArrayList<>();
    for (String filter : filters) {
        if (filter != null) {
            filter = filter.trim();
            if (filter.length() > 0) {
                paths.add(parse(filter, filter));
            }
        }
    }
    return paths.toArray(new FilterPath[paths.size()]);
}
 
Example 3
Source File: IndicesAliasesRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    ActionRequestValidationException validationException = null;
    if (allAliasActions.isEmpty()) {
        return addValidationError("Must specify at least one alias action", validationException);
    }
    for (AliasActions aliasAction : allAliasActions) {
        if (CollectionUtils.isEmpty(aliasAction.aliases)) {
            validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
                    + "]: Property [alias/aliases] is either missing or null", validationException);
        } else {
            for (String alias : aliasAction.aliases) {
                if (!Strings.hasText(alias)) {
                    validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
                        + "]: [alias/aliases] may not be empty string", validationException);
                }
            }
        }
        if (CollectionUtils.isEmpty(aliasAction.indices)) {
            validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
                    + "]: Property [index/indices] is either missing or null", validationException);
        } else {
            for (String index : aliasAction.indices) {
                if (!Strings.hasText(index)) {
                    validationException = addValidationError("Alias action [" + aliasAction.actionType().name().toLowerCase(Locale.ENGLISH)
                            + "]: [index/indices] may not be empty string", validationException);
                }
            }
        }
    }
    return validationException;
}
 
Example 4
Source File: CloseIndexRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    ActionRequestValidationException validationException = null;
    if (CollectionUtils.isEmpty(indices)) {
        validationException = addValidationError("index is missing", validationException);
    }
    return validationException;
}
 
Example 5
Source File: DeleteIndexRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    ActionRequestValidationException validationException = null;
    if (CollectionUtils.isEmpty(indices)) {
        validationException = addValidationError("index / indices is missing", validationException);
    }
    return validationException;
}
 
Example 6
Source File: DeleteWarmerRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    ActionRequestValidationException validationException = null;
    if (CollectionUtils.isEmpty(names)) {
        validationException = addValidationError("warmer names are missing", validationException);
    } else {
        validationException = checkForEmptyString(validationException, names);
    }
    if (CollectionUtils.isEmpty(indices)) {
        validationException = addValidationError("indices are missing", validationException);
    } else {
        validationException = checkForEmptyString(validationException, indices);
    }
    return validationException;
}
 
Example 7
Source File: OpenIndexRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ActionRequestValidationException validate() {
    ActionRequestValidationException validationException = null;
    if (CollectionUtils.isEmpty(indices)) {
        validationException = addValidationError("index is missing", validationException);
    }
    return validationException;
}
 
Example 8
Source File: TransportGetSettingsAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
protected void masterOperation(GetSettingsRequest request, ClusterState state, ActionListener<GetSettingsResponse> listener) {
    String[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
    ImmutableOpenMap.Builder<String, Settings> indexToSettingsBuilder = ImmutableOpenMap.builder();
    for (String concreteIndex : concreteIndices) {
        IndexMetaData indexMetaData = state.getMetaData().index(concreteIndex);
        if (indexMetaData == null) {
            continue;
        }

        Settings settings = SettingsFilter.filterSettings(settingsFilter.getPatterns(), indexMetaData.getSettings());
        if (request.humanReadable()) {
            settings = IndexMetaData.addHumanReadableSettings(settings);
        }
        if (!CollectionUtils.isEmpty(request.names())) {
            Settings.Builder settingsBuilder = Settings.builder();
            for (Map.Entry<String, String> entry : settings.getAsMap().entrySet()) {
                if (Regex.simpleMatch(request.names(), entry.getKey())) {
                    settingsBuilder.put(entry.getKey(), entry.getValue());
                }
            }
            settings = settingsBuilder.build();
        }
        indexToSettingsBuilder.put(concreteIndex, settings);
    }
    listener.onResponse(new GetSettingsResponse(indexToSettingsBuilder.build()));
}
 
Example 9
Source File: FilterPathBasedFilter.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public FilterPathBasedFilter(FilterPath[] filters) {
    if (CollectionUtils.isEmpty(filters)) {
        throw new IllegalArgumentException("filters cannot be null or empty");
    }
    this.filters = filters;
}
 
Example 10
Source File: Strings.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * If an array only consists of zero or one element, which is "*" or "_all" return an empty array
 * which is usually used as everything
 */
public static boolean isAllOrWildcard(String[] data) {
    return CollectionUtils.isEmpty(data) ||
           data.length == 1 && ("_all".equals(data[0]) || "*".equals(data[0]));
}
 
Example 11
Source File: Strings.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * If an array only consists of zero or one element, which is "*" or "_all" return an empty array
 * which is usually used as everything
 */
public static boolean isAllOrWildcard(String[] data) {
    return CollectionUtils.isEmpty(data) ||
           data.length == 1 && ("_all".equals(data[0]) || "*".equals(data[0]));
}