EndpointBuilder addPathPartAsIs(String... parts) { for (String part : parts) { if (Strings.hasLength(part)) { joiner.add(part); } } return this; }
EndpointBuilder addPathPart(String... parts) { for (String part : parts) { if (Strings.hasLength(part)) { joiner.add(encodePart(part)); } } return this; }
Params putParam(String name, String value) { if (Strings.hasLength(value)) { request.addParameter(name, value); } return this; }
/** * Check that the given String is neither <code>null</code> nor of length 0. * Note: Will return <code>true</code> for a String that purely consists of whitespace. * * @param str the String to check (may be <code>null</code>) * @return <code>true</code> if the String is not null and has length * @see #hasLength(CharSequence) */ public static boolean hasLength(String str) { return hasLength((CharSequence) str); }
/** * Check that the given CharSequence is either <code>null</code> or of length 0. * Note: Will return <code>false</code> for a CharSequence that purely consists of whitespace. * <pre> * StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("Hello") = false * </pre> * * @param str the CharSequence to check (may be <code>null</code>) * @return <code>true</code> if the CharSequence is either null or has a zero length */ public static boolean isEmpty(CharSequence str) { return !hasLength(str); }
/** * Set the index this action is operating on. */ public AliasActions index(String index) { if (false == Strings.hasLength(index)) { throw new IllegalArgumentException("[index] can't be empty string"); } this.indices = new String[] {index}; return this; }
if (Strings.hasLength(action.index())) { metadata.field("_index", action.index()); if (Strings.hasLength(action.type())) { metadata.field("_type", action.type()); if (Strings.hasLength(action.id())) { metadata.field("_id", action.id()); if (Strings.hasLength(action.routing())) { metadata.field("routing", action.routing()); if (Strings.hasLength(indexRequest.getPipeline())) { metadata.field("pipeline", indexRequest.getPipeline());
@Override public AliasActions indices(String... indices) { if (indices == null || indices.length == 0) { throw new IllegalArgumentException("[indices] can't be empty"); } for (String index : indices) { if (false == Strings.hasLength(index)) { throw new IllegalArgumentException("[indices] can't contain empty string"); } } this.indices = indices; return this; }
/** * Set the alias this action is operating on. */ public AliasActions alias(String alias) { if (type == AliasActions.Type.REMOVE_INDEX) { throw new IllegalArgumentException("[alias] is unsupported for [" + type + "]"); } if (false == Strings.hasLength(alias)) { throw new IllegalArgumentException("[alias] can't be empty string"); } this.aliases = new String[] {alias}; return this; }
/** * Aliases to use with this action. */ public AliasActions aliases(String... aliases) { if (type == AliasActions.Type.REMOVE_INDEX) { throw new IllegalArgumentException("[aliases] is unsupported for [" + type + "]"); } if (aliases == null || aliases.length == 0) { throw new IllegalArgumentException("[aliases] can't be empty"); } for (String alias : aliases) { if (false == Strings.hasLength(alias)) { throw new IllegalArgumentException("[aliases] can't contain empty string"); } } this.aliases = aliases; return this; }
/** * Returns group settings for the given setting prefix. */ public Map<String, Settings> getGroups(String settingPrefix, boolean ignoreNonGrouped) throws SettingsException { if (!Strings.hasLength(settingPrefix)) { throw new IllegalArgumentException("illegal setting prefix " + settingPrefix); } if (settingPrefix.charAt(settingPrefix.length() - 1) != '.') { settingPrefix = settingPrefix + "."; } return getGroupsInternal(settingPrefix, ignoreNonGrouped); }
public static Version parse(String toParse, Version defaultValue) { if (Strings.hasLength(toParse)) { try { return Version.parseLeniently(toParse); } catch (ParseException e) { // pass to default } } return defaultValue; } }
/** * Trim all occurrences of the supplied leading character from the given String. * * @param str the String to check * @param leadingCharacter the leading character to be trimmed * @return the trimmed String */ public static String trimLeadingCharacter(String str, char leadingCharacter) { if (!hasLength(str)) { return str; } StringBuilder sb = new StringBuilder(str); while (sb.length() > 0 && sb.charAt(0) == leadingCharacter) { sb.deleteCharAt(0); } return sb.toString(); }
public TaskId(String taskId) { if (Strings.hasLength(taskId) && "unset".equals(taskId) == false) { String[] s = Strings.split(taskId, ":"); if (s == null || s.length != 2) { throw new IllegalArgumentException("malformed task id " + taskId); } this.nodeId = s[0]; try { this.id = Long.parseLong(s[1]); } catch (NumberFormatException ex) { throw new IllegalArgumentException("malformed task id " + taskId, ex); } } else { nodeId = ""; id = -1L; } }
public static Request index(IndexRequest indexRequest) { String method = Strings.hasLength(indexRequest.id()) ? HttpMethod.PUT.name() : HttpMethod.POST.name(); boolean isCreate = (indexRequest.opType() == DocWriteRequest.OpType.CREATE); String endpoint = endpoint(indexRequest.index(), indexRequest.type(), indexRequest.id(), isCreate ? "_create" : null); Request request = new Request(method, endpoint); Params parameters = new Params(request); parameters.withRouting(indexRequest.routing()); parameters.withTimeout(indexRequest.timeout()); parameters.withVersion(indexRequest.version()); parameters.withVersionType(indexRequest.versionType()); parameters.withPipeline(indexRequest.getPipeline()); parameters.withRefreshPolicy(indexRequest.getRefreshPolicy()); parameters.withWaitForActiveShards(indexRequest.waitForActiveShards()); BytesRef source = indexRequest.source().toBytesRef(); ContentType contentType = createContentType(indexRequest.getContentType()); request.setEntity(new ByteArrayEntity(source.bytes, source.offset, source.length, contentType)); return request; }
void updateRemoteCluster( final String clusterAlias, final List<String> addresses, final String proxyAddress, final ActionListener<Void> connectionListener) { final List<Tuple<String, Supplier<DiscoveryNode>>> nodes = addresses.stream().<Tuple<String, Supplier<DiscoveryNode>>>map(address -> Tuple.tuple(address, () -> buildSeedNode(clusterAlias, address, Strings.hasLength(proxyAddress))) ).collect(Collectors.toList()); updateRemoteClusters(Collections.singletonMap(clusterAlias, new Tuple<>(proxyAddress, nodes)), connectionListener); }
public final void close(Runnable onCompletion) { String scrollId = this.scrollId.get(); if (Strings.hasLength(scrollId)) { clearScroll(scrollId, () -> cleanup(onCompletion)); } else { cleanup(onCompletion); } }
public Builder filter(String filter) { if (!Strings.hasLength(filter)) { this.filter = null; return this; } return filter(XContentHelper.convertToMap(XContentFactory.xContent(filter), filter, true)); }
/** * Allows to partially validate an alias, without knowing which index it'll get applied to. * Useful with index templates containing aliases. Checks also that it is possible to parse * the alias filter via {@link org.elasticsearch.common.xcontent.XContentParser}, * without validating it as a filter though. * @throws IllegalArgumentException if the alias is not valid */ public void validateAliasStandalone(Alias alias) { validateAliasStandalone(alias.name(), alias.indexRouting()); if (Strings.hasLength(alias.filter())) { try { XContentHelper.convertToMap(XContentFactory.xContent(alias.filter()), alias.filter(), false); } catch (Exception e) { throw new IllegalArgumentException("failed to parse filter for alias [" + alias.name() + "]", e); } } }
private Table buildTable(RestRequest request, GetAliasesResponse response) { Table table = getTableWithHeader(request); for (ObjectObjectCursor<String, List<AliasMetaData>> cursor : response.getAliases()) { String indexName = cursor.key; for (AliasMetaData aliasMetaData : cursor.value) { table.startRow(); table.addCell(aliasMetaData.alias()); table.addCell(indexName); table.addCell(aliasMetaData.filteringRequired() ? "*" : "-"); String indexRouting = Strings.hasLength(aliasMetaData.indexRouting()) ? aliasMetaData.indexRouting() : "-"; table.addCell(indexRouting); String searchRouting = Strings.hasLength(aliasMetaData.searchRouting()) ? aliasMetaData.searchRouting() : "-"; table.addCell(searchRouting); table.endRow(); } } return table; }