本文整理汇总了Java中org.elasticsearch.common.Strings.hasLength方法的典型用法代码示例。如果您正苦于以下问题:Java Strings.hasLength方法的具体用法?Java Strings.hasLength怎么用?Java Strings.hasLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.common.Strings
的用法示例。
在下文中一共展示了Strings.hasLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildTable
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
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;
}
示例2: validate
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private static void validate(final String repositoryName, final String snapshotName) {
if (Strings.hasLength(snapshotName) == false) {
throw new InvalidSnapshotNameException(repositoryName, snapshotName, "cannot be empty");
}
if (snapshotName.contains(" ")) {
throw new InvalidSnapshotNameException(repositoryName, snapshotName, "must not contain whitespace");
}
if (snapshotName.contains(",")) {
throw new InvalidSnapshotNameException(repositoryName, snapshotName, "must not contain ','");
}
if (snapshotName.contains("#")) {
throw new InvalidSnapshotNameException(repositoryName, snapshotName, "must not contain '#'");
}
if (snapshotName.charAt(0) == '_') {
throw new InvalidSnapshotNameException(repositoryName, snapshotName, "must not start with '_'");
}
if (snapshotName.toLowerCase(Locale.ROOT).equals(snapshotName) == false) {
throw new InvalidSnapshotNameException(repositoryName, snapshotName, "must be lowercase");
}
if (Strings.validFileName(snapshotName) == false) {
throw new InvalidSnapshotNameException(repositoryName,
snapshotName,
"must not contain the following characters " + Strings.INVALID_FILENAME_CHARS);
}
}
示例3: appendOpt
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
/**
* Append a single VM option.
*/
@Override
public ReproduceErrorMessageBuilder appendOpt(String sysPropName, String value) {
if (sysPropName.equals(SYSPROP_ITERATIONS())) { // we don't want the iters to be in there!
return this;
}
if (sysPropName.equals(SYSPROP_TESTMETHOD())) {
//don't print out the test method, we print it ourselves in appendAllOpts
//without filtering out the parameters (needed for REST tests)
return this;
}
if (sysPropName.equals(SYSPROP_PREFIX())) {
// we always use the default prefix
return this;
}
if (Strings.hasLength(value)) {
return super.appendOpt(sysPropName, value);
}
return this;
}
示例4: TaskId
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
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;
}
}
示例5: execute
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
@Override
public void execute(IngestDocument ingestDocument) throws Exception {
String content = ingestDocument.getFieldValue(field, String.class);
if (Strings.hasLength(content)) {
CsvParser parser = new CsvParser(this.csvSettings);
String[] values = parser.parseLine(content);
if (values.length != this.columns.size()) {
// TODO should be error?
throw new IllegalArgumentException("field[" + this.field + "] size ["
+ values.length + "] doesn't match header size [" + columns.size() + "].");
}
for (int i = 0; i < columns.size(); i++) {
ingestDocument.setFieldValue(columns.get(i), values[i]);
}
} else {
// TODO should we have ignoreMissing flag?
throw new IllegalArgumentException("field[" + this.field + "] is empty string.");
}
}
示例6: parse
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
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;
}
示例7: appendProperties
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
protected ReproduceErrorMessageBuilder appendProperties(String... properties) {
for (String sysPropName : properties) {
if (Strings.hasLength(System.getProperty(sysPropName))) {
appendOpt(sysPropName, System.getProperty(sysPropName));
}
}
return this;
}
示例8: findResource
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private static URL findResource(String path, String optionalFileSuffix) {
URL resource = FileUtils.class.getResource(path);
if (resource == null) {
//if not found we append the file suffix to the path (as it is optional)
if (Strings.hasLength(optionalFileSuffix) && !path.endsWith(optionalFileSuffix)) {
resource = FileUtils.class.getResource(path + optionalFileSuffix);
}
}
return resource;
}
示例9: apply
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
@Override
public PlainBlobMetaData apply(StorageObject storageObject) {
String blobName = storageObject.getName();
if (Strings.hasLength(pathToRemove)) {
blobName = blobName.substring(pathToRemove.length());
}
return new PlainBlobMetaData(blobName, storageObject.getSize().longValue());
}
示例10: Plugin
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
/**
* Creates a new custom scripts based operation exposed via plugin.
* The name of the plugin combined with the operation name can be used to enable/disable scripts via fine-grained settings.
*
* @param pluginName the name of the plugin
* @param operation the name of the operation
*/
public Plugin(String pluginName, String operation) {
if (Strings.hasLength(pluginName) == false) {
throw new IllegalArgumentException("plugin name cannot be empty when registering a custom script context");
}
if (Strings.hasLength(operation) == false) {
throw new IllegalArgumentException("operation name cannot be empty when registering a custom script context");
}
this.pluginName = pluginName;
this.operation = operation;
this.key = pluginName + "_" + operation;
}
示例11: PatternReplaceCharFilterFactory
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
public PatternReplaceCharFilterFactory(IndexSettings indexSettings, Environment env, String name, Settings settings) {
super(indexSettings, name);
String sPattern = settings.get("pattern");
if (!Strings.hasLength(sPattern)) {
throw new IllegalArgumentException("pattern is missing for [" + name + "] char filter of type 'pattern_replace'");
}
pattern = Regex.compile(sPattern, settings.get("flags"));
replacement = settings.get("replacement", ""); // when not set or set to "", use "".
}
示例12: doStart
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
@Override
protected void doStart() {
String uriSetting = getMetadata().settings().get("uri");
if (Strings.hasText(uriSetting) == false) {
throw new IllegalArgumentException("No 'uri' defined for hdfs snapshot/restore");
}
URI uri = URI.create(uriSetting);
if ("hdfs".equalsIgnoreCase(uri.getScheme()) == false) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Invalid scheme [%s] specified in uri [%s]; only 'hdfs' uri allowed for hdfs snapshot/restore", uri.getScheme(), uriSetting));
}
if (Strings.hasLength(uri.getPath()) && uri.getPath().equals("/") == false) {
throw new IllegalArgumentException(String.format(Locale.ROOT,
"Use 'path' option to specify a path [%s], not the uri [%s] for hdfs snapshot/restore", uri.getPath(), uriSetting));
}
String pathSetting = getMetadata().settings().get("path");
// get configuration
if (pathSetting == null) {
throw new IllegalArgumentException("No 'path' defined for hdfs snapshot/restore");
}
int bufferSize = getMetadata().settings().getAsBytesSize("buffer_size", DEFAULT_BUFFER_SIZE).bytesAsInt();
try {
// initialize our filecontext
SpecialPermission.check();
FileContext fileContext = AccessController.doPrivileged((PrivilegedAction<FileContext>)
() -> createContext(uri, getMetadata().settings()));
blobStore = new HdfsBlobStore(fileContext, pathSetting, bufferSize);
logger.debug("Using file-system [{}] for URI [{}], path [{}]", fileContext.getDefaultFileSystem(), fileContext.getDefaultFileSystem().getUri(), pathSetting);
} catch (IOException e) {
throw new ElasticsearchGenerationException(String.format(Locale.ROOT, "Cannot create HDFS repository for uri [%s]", uri), e);
}
super.doStart();
}
示例13: processSourceBasedGlobalSettings
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
private static void processSourceBasedGlobalSettings(Settings settings, Map<String, ScriptEngineService> scriptEngines, ScriptContextRegistry scriptContextRegistry, Map<String, ScriptMode> scriptModes) {
//read custom source based settings for all operations (e.g. script.indexed: on)
for (ScriptType scriptType : ScriptType.values()) {
String scriptTypeSetting = settings.get(SCRIPT_SETTINGS_PREFIX + scriptType);
if (Strings.hasLength(scriptTypeSetting)) {
ScriptMode scriptTypeMode = ScriptMode.parse(scriptTypeSetting);
addGlobalScriptTypeModes(scriptEngines.keySet(), scriptContextRegistry, scriptType, scriptTypeMode, scriptModes);
}
}
}
示例14: validateAliasStandalone
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
/**
* 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);
}
}
}
示例15: getSelectedClient
import org.elasticsearch.common.Strings; //导入方法依赖的package包/类
CloudBlobClient getSelectedClient(String account, LocationMode mode) {
logger.trace("selecting a client for account [{}], mode [{}]", account, mode.name());
AzureStorageSettings azureStorageSettings = null;
if (this.primaryStorageSettings == null) {
throw new IllegalArgumentException("No primary azure storage can be found. Check your elasticsearch.yml.");
}
if (Strings.hasLength(account)) {
azureStorageSettings = this.secondariesStorageSettings.get(account);
}
// if account is not secondary, it's the primary
if (azureStorageSettings == null) {
if (Strings.hasLength(account) == false || primaryStorageSettings.getName() == null || account.equals(primaryStorageSettings.getName())) {
azureStorageSettings = primaryStorageSettings;
}
}
if (azureStorageSettings == null) {
// We did not get an account. That's bad.
throw new IllegalArgumentException("Can not find azure account [" + account + "]. Check your elasticsearch.yml.");
}
CloudBlobClient client = this.clients.get(azureStorageSettings.getAccount());
if (client == null) {
throw new IllegalArgumentException("Can not find an azure client for account [" + account + "]");
}
// NOTE: for now, just set the location mode in case it is different;
// only one mode per storage account can be active at a time
client.getDefaultRequestOptions().setLocationMode(mode);
// Set timeout option if the user sets cloud.azure.storage.timeout or cloud.azure.storage.xxx.timeout (it's negative by default)
if (azureStorageSettings.getTimeout().getSeconds() > 0) {
try {
int timeout = (int) azureStorageSettings.getTimeout().getMillis();
client.getDefaultRequestOptions().setTimeoutIntervalInMs(timeout);
} catch (ClassCastException e) {
throw new IllegalArgumentException("Can not convert [" + azureStorageSettings.getTimeout() +
"]. It can not be longer than 2,147,483,647ms.");
}
}
return client;
}