org.apache.brooklyn.util.text.Strings.removeFromStart()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.apache.brooklyn.util.text.Strings.removeFromStart()方法的一些代码示例,展示了Strings.removeFromStart()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Strings.removeFromStart()方法的具体详情如下:
包路径:org.apache.brooklyn.util.text.Strings
类名称:Strings
方法名:removeFromStart

Strings.removeFromStart介绍

[英]Removes prefix from the beginning of string. Returns string if it does not begin with prefix.
[中]删除字符串开头的前缀。如果字符串不以前缀开头,则返回字符串。

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Beta /** for transitioning away from LocationDefinition */
  public static String unwrapLegacyWrappedReference(String id) {
    return Strings.removeFromStart(id, NAME+":");
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

protected String getLocalType(String type) {
  return Strings.removeFromStart(type, prefix).trim();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-rest-resources

@Deprecated
public static String fixLocation(String locationId) {
  if (locationId.startsWith("/locations/") || locationId.startsWith("/v1/locations/")) {
    log.warn("REST API using legacy URI syntax for location: "+locationId);
    locationId = Strings.removeFromStart(locationId, "/v1/locations/");
    locationId = Strings.removeFromStart(locationId, "/locations/");
  }
  return locationId;
}

代码示例来源:origin: io.brooklyn.clocker/brooklyn-clocker-docker

/** Parse and return the ID returned from a Docker command. */
public static String checkId(String input) {
  // Remove hash type from start and convert to lowercase
  String imageId = Strings.removeFromStart(Strings.trim(input).toLowerCase(Locale.ENGLISH), SHA_256);
  boolean prefix = input.startsWith(SHA_256);
  if (imageId.length() == 64 && DOCKERFILE_CHARACTERS.matchesAllOf(imageId)) {
    return (prefix ? SHA_256 : "") + imageId;
  } else {
    throw new IllegalStateException("Invalid image ID returned: " + imageId);
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/** Records an {@link AbstractEntityAdjunct#HIGHLIGHT_NAME_LAST_ACTION} with the given message,
 * formatted with arguments entity and either 'added', 'changed', or 'removed'.
 * Can be overridden to be no-op if caller wants to manage their own such highlights,
 * or to provide further information. See also {@link #defaultHighlightAction(EventType, Entity)}. */
protected void defaultHighlightAction(EventType type, Entity entity, String formattedMessage) {
  highlightAction(String.format(formattedMessage, entity, Strings.removeFromStart(type.toString().toLowerCase(), "entity_")), null);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/**
   * Look for keys with <code>configPrefix</code> in <code>configBag</code> and
   * those which have <code>configPrefix</code> are added in <code>destinationBucket</code> but without <code>configPrefix</code>.
   * @param configPrefix prefix to look for
   * @param configBag keys to look in
   * @param destinationBucket should not be an ImmutableMap
   */
  public static void addUnprefixedConfigKeyInConfigBack(String configPrefix, ConfigBag configBag, Map<String, Object> destinationBucket) {
    for (Map.Entry<ConfigKey<?>, ?> entry : configBag.getAllConfigAsConfigKeyMap().entrySet()) {
      String keyName = entry.getKey().getName();
      if (keyName.startsWith(configPrefix)) {
        destinationBucket.put(Strings.removeFromStart(keyName, configPrefix), entry.getValue());
      }
    }
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public String getClassLoaderDir(String resourceInThatDir) {
  resourceInThatDir = Strings.removeFromStart(resourceInThatDir, "/");
  URL resourceUrl = getLoader().getResource(resourceInThatDir);
  if (resourceUrl==null) throw new NoSuchElementException("Resource ("+resourceInThatDir+") not found");
  URL containerUrl = getContainerUrl(resourceUrl, resourceInThatDir);
  if (!"file".equals(containerUrl.getProtocol())) throw new IllegalStateException("Resource ("+resourceInThatDir+") not on file system (at "+containerUrl+")");
  //convert from file: URL to File
  File file;
  try {
    file = new File(containerUrl.toURI());
  } catch (URISyntaxException e) {
    throw new IllegalStateException("Resource ("+resourceInThatDir+") found at invalid URI (" + containerUrl + ")", e);
  }
  
  if (!file.exists()) throw new IllegalStateException("Context class url substring ("+containerUrl+") not found on filesystem");
  return file.getPath();
  
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public void testRemoveFromStart2() {
  assertEquals(Strings.removeFromStart("xyz", "x"), "yz");
  assertEquals(Strings.removeFromStart("xyz", "."), "xyz");
  assertEquals(Strings.removeFromStart("http://foo.com", "http://"), "foo.com");
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public void testRemoveFromStart() {
  assertEquals(Strings.removeFromStart("", "foo"), "");
  assertEquals(Strings.removeFromStart(null, "foo"), null);
  assertEquals(Strings.removeFromStart("foobar", "foo"), "bar");
  assertEquals(Strings.removeFromStart("foo", "bar"), "foo");
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
  public HttpExecutor getHttpExecutor(Map<?, ?> props) {
    HttpExecutor httpExecutor;

    String httpExecutorClass = (String) props.get(HTTP_EXECUTOR_CLASS_CONFIG);
    if (httpExecutorClass != null) {
      Map<String,Object> httpExecutorProps = MutableMap.of();
      Map<?, ?> executorProps = Maps.filterKeys(props, StringPredicates.isStringStartingWith(HTTP_EXECUTOR_CLASS_CONFIG_PREFIX));
      if (executorProps.size() > 0) {
        for (Entry<?, ?> entry: executorProps.entrySet()) {
          String keyName = Strings.removeFromStart((String)entry.getKey(), HTTP_EXECUTOR_CLASS_CONFIG_PREFIX);
          httpExecutorProps.put(keyName, entry.getValue());
        }
      }
      try {
        httpExecutor = (HttpExecutor) new ClassLoaderUtils(getClass()).loadClass(httpExecutorClass).getConstructor(Map.class).newInstance(httpExecutorProps);
      } catch (Exception e) {
        throw Exceptions.propagate(e);
      }

    } else {
      LOG.info(HTTP_EXECUTOR_CLASS_CONFIG + " parameter not provided. Using the default implementation " + HttpExecutorImpl.class.getName());
      httpExecutor = HttpExecutorImpl.newInstance();
    }

    return httpExecutor;
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
public TemplateModel get(String key) throws TemplateModelException {
  if (map==null) return null;
  try {
    if (map.containsKey(key)) 
      return wrapAsTemplateModel( map.get(key) );
    
    Map<String,Object> result = MutableMap.of();
    for (Map.Entry<?,?> entry: map.entrySet()) {
      String k = Strings.toString(entry.getKey());
      if (k.startsWith(key+".")) {
        String k2 = Strings.removeFromStart(k, key+".");
        result.put(k2, entry.getValue());
      }
    }
    if (!result.isEmpty()) 
        return wrapAsTemplateModel( result );
    
  } catch (Exception e) {
    Exceptions.propagateIfFatal(e);
    throw new IllegalStateException("Error accessing config '"+key+"'"+": "+e, e);
  }
  
  return null;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
public LocationSpec<? extends Location> newLocationSpecFromString(String spec, Map<?, ?> locationFlags, LocationRegistry registry) {
  String name = spec;
  ConfigBag lfBag = ConfigBag.newInstance(locationFlags).putIfAbsent(LocationInternal.ORIGINAL_SPEC, name);
  name = Strings.removeFromStart(spec, getPrefix()+":");
  if (name.toLowerCase().startsWith(NAMED+":")) {
    // since 0.7.0
    log.warn("Deprecated use of 'named:' prefix with wrong case ("+spec+"); support may be removed in future versions");
    name = spec.substring( (NAMED+":").length() );
  }
  
  LocationDefinition ld = registry.getDefinedLocationByName(name);
  if (ld==null) throw new NoSuchElementException("No named location defined matching '"+name+"'");
  return registry.getLocationSpec(ld, lfBag.getAllConfig()).get();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public PerUserEntitlementManager(BrooklynProperties properties) {
  this(load(properties, properties.getConfig(DEFAULT_MANAGER)));
  
  Set<ConfigKey<?>> users = properties.findKeysPresent(ConfigPredicates.nameStartsWith(PER_USER_ENTITLEMENTS_CONFIG_PREFIX+"."));
  for (ConfigKey<?> key: users) {
    if (key.getName().equals(DEFAULT_MANAGER.getName())) continue;
    String user = Strings.removeFromStart(key.getName(), PER_USER_ENTITLEMENTS_CONFIG_PREFIX+".");
    addUser(user, load(properties, Strings.toString(properties.getConfig(key))));
  }
  
  log.info(getClass().getSimpleName()+" created with "+perUserManagers.size()+" user"+Strings.s(perUserManagers)+" and "
    + "default "+defaultManager+" (users: "+perUserManagers+")");
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-rest-resources

String oldPackage = "brooklyn.web.console.security.";
if (className.startsWith(oldPackage)) {
  className = Strings.removeFromStart(className, oldPackage);
  className = DelegatingSecurityProvider.class.getPackage().getName() + "." + className;
  clazz = (Class<? extends SecurityProvider>) clu.loadClass(className);

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-winrm

String keyName = entry.getKey().getName();
if (keyName.startsWith(WinRmTool.BROOKLYN_CONFIG_KEY_PREFIX)) {
  keyName = Strings.removeFromStart(keyName, WinRmTool.BROOKLYN_CONFIG_KEY_PREFIX);
  include = true;
  keyName = Strings.removeFromStart(keyName, WINRM_TOOL_CLASS_PROPERTIES_PREFIX);
  include = true;

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

String match = yamlExtract.withOriginalIndentation(true).withKeyIncluded(true).getMatchedYamlTextOrWarn();
if (match!=null) {
  if (rootItemYaml.startsWith(match)) rootItemYaml = Strings.removeFromStart(rootItemYaml, match);
  else rootItemYaml = Strings.replaceAllNonRegex(rootItemYaml, "\n"+match, "");

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

@Override
protected String generateNewIdOfLength(ConfigBag setup, int len) {
  Object context = setup.peek(CloudLocationConfig.CALLER_CONTEXT);
  Entity entity = null;
  if (context instanceof Entity) {
    entity = (Entity) context;
  }
  
  String template = setup.get(MACHINE_NAME_TEMPLATE);
  
  String processed;
  if (entity == null) {
    processed = TemplateProcessor.processTemplateContents(template, setup.get(EXTRA_SUBSTITUTIONS));
  } else {
    processed = TemplateProcessor.processTemplateContents(template, (EntityInternal)entity, setup.get(EXTRA_SUBSTITUTIONS));
  }
  
  processed = Strings.removeFromStart(processed, "#ftl\n");
  
  return sanitize(processed);
}

代码示例来源:origin: org.apache.brooklyn.camp/camp-base

@Override
public void applyYamlPrimitive(PlanInterpretationNode node) {
  if (node.matchesLiteral("$sample:foo")) node.setNewValue("bar").exclude();
  if (node.matchesPrefix("$sample:caps:")) {
    node.setNewValue(Strings.removeFromStart(node.getNewValue().toString(), "$sample:caps:").toUpperCase()).exclude();
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

result.add(p);
} else {
  result.add(Strings.removeFromStart(p, subsequentLineIndentationToRemoveS));

代码示例来源:origin: org.apache.brooklyn/brooklyn-rest-resources

ld = mgmt.getLocationRegistry().getDefinedLocationByName(Strings.removeFromStart(spec, "named:"));
if (ld==null) ld = mgmt.getLocationRegistry().getDefinedLocationById(lp.getId());
if (ld!=null) {

相关文章