本文整理了Java中org.apache.brooklyn.util.text.Strings.removeFromEnd()
方法的一些代码示例,展示了Strings.removeFromEnd()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Strings.removeFromEnd()
方法的具体详情如下:
包路径:org.apache.brooklyn.util.text.Strings
类名称:Strings
方法名:removeFromEnd
[英]Removes suffix from the end of the string. Returns string if it does not end with suffix.
[中]删除字符串末尾的后缀。如果字符串不以后缀结尾,则返回字符串。
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-webapp
/** e.g. editRecord("foo", "A", "1.2.3.4"), which assuming this domain is "bar.com", will create A record for foo.bar.com.
* <p>
* or editRecord("*.foo", "CNAME", "foo.bar.com") to map everything at *.foo.bar.com to foo.bar.com
*/
public void editRecord(String subdomainPart, String type, String content) {
subdomainPart = Strings.removeFromEnd(subdomainPart, "."+name);
editSubdomainRecord(id, subdomainPart, type, content);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) {
String driverInterfaceName = driverInterface.getName();
if (!(location instanceof SshMachineLocation)) return null;
if (!driverInterfaceName.endsWith("Driver")) {
throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect SshDriver class name", driverInterfaceName));
}
return Strings.removeFromEnd(driverInterfaceName, "Driver")+"SshDriver";
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) {
if (driverInterface.getSimpleName().equals(expectedPattern)) {
// i'd like to do away with drivers altogether, but if people *really* need to use this and suppress the warning,
// they can use the full class rename
LOG.warn("Using discouraged driver simple class rename to find "+replacement+" for "+expectedPattern+"; it is recommended to set getDriverInterface() or newDriver() appropriately");
return Strings.removeFromEnd(driverInterface.getName(), expectedPattern)+replacement;
}
return null;
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) {
String driverInterfaceName = driverInterface.getName();
if (!(location instanceof PaasLocation)) return null;
if (!driverInterfaceName.endsWith("Driver")) {
throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect PaasDriver class name", driverInterfaceName));
}
return Strings.removeFromEnd(driverInterfaceName, "Driver") + ((PaasLocation) location).getPaasProviderName() + "Driver";
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common
/** fails if the dir is not "safe" for deletion, currently length <= 2 or the home directory */
protected static void checkSafe(File dir) throws IOException {
String dp = dir.getAbsolutePath();
dp = Strings.removeFromEnd(dp, "/");
if (dp.length()<=2)
throw new IOException("Refusing instruction to delete "+dir+": name too short");
if (Os.home().equals(dp))
throw new IOException("Refusing instruction to delete "+dir+": it's the home directory");
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common
public void testRemoveFromEnd() {
assertEquals(Strings.removeFromEnd("", "bar"), "");
assertEquals(Strings.removeFromEnd(null, "bar"), null);
assertEquals(Strings.removeFromEnd("foobar", "bar"), "foo");
assertEquals(Strings.removeFromEnd("foo", "bar"), "foo");
// test they are applied in order
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common
public void testRemoveFromEnd2() {
assertEquals(Strings.removeFromEnd("xyz", "z"), "xy");
assertEquals(Strings.removeFromEnd("xyz", "."), "xyz");
assertEquals(Strings.removeFromEnd("http://foo.com/", "/"), "http://foo.com");
}
代码示例来源:origin: io.brooklyn.clocker/brooklyn-clocker-docker
public static String getContainerName(Entity target) {
String unique = getUniqueContainerName(target);
String suffix = "_" + target.getId();
return Strings.removeFromEnd(unique, suffix);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Override
public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) {
String driverInterfaceName = driverInterface.getName();
// TODO: use a proper registry later on
try {
Class<?> winRmLocationClass = new ClassLoaderUtils(this, entity).loadClass("org.apache.brooklyn.software-winrm", BrooklynVersion.get(), "org.apache.brooklyn.location.winrm.WinRmMachineLocation");
if (!winRmLocationClass.isInstance(location)) return null;
} catch (ClassNotFoundException ex) {
return null;
}
if (!driverInterfaceName.endsWith("Driver")) {
throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect WinRmDriver class name", driverInterfaceName));
}
return Strings.removeFromEnd(driverInterfaceName, "Driver")+"WinRmDriver";
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-cm-salt
@Override
public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) {
String driverInterfaceName = driverInterface.getName();
if (!(location instanceof SimulatedLocation)) {
return null;
}
if (!driverInterfaceName.endsWith("Driver")) {
throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect SshDriver class name", driverInterfaceName));
}
return Strings.removeFromEnd(driverInterfaceName, "Driver") + "SimulatedDriver";
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base
@Override
public String getArchiveNameFormat() {
String subpath = entity.getConfig(BrooklynNode.SUBPATH_IN_ARCHIVE);
if (subpath==null) {
// assume the dir name is `basename-VERSION` where download link is `basename-VERSION-dist.tar.gz`
String uploadUrl = entity.getConfig(BrooklynNode.DISTRO_UPLOAD_URL);
String origDownloadName = uploadUrl;
if (origDownloadName==null)
origDownloadName = entity.getAttribute(BrooklynNode.DOWNLOAD_URL);
if (origDownloadName!=null) {
// BasicDownloadResolver makes it crazy hard to get the template-evaluated value of DOWNLOAD_URL
origDownloadName = DownloadSubstituters.substitute(origDownloadName, DownloadSubstituters.getBasicEntitySubstitutions(this));
origDownloadName = Urls.decode(origDownloadName);
origDownloadName = Urls.getBasename(origDownloadName);
String downloadName = origDownloadName;
downloadName = Strings.removeFromEnd(downloadName, ".tar.gz");
downloadName = Strings.removeFromEnd(downloadName, ".tgz");
downloadName = Strings.removeFromEnd(downloadName, ".zip");
if (!downloadName.equals(origDownloadName)) {
downloadName = Strings.removeFromEnd(downloadName, "-dist");
subpath = downloadName;
}
}
}
if (subpath==null) subpath = "brooklyn-dist-%s";
return subpath;
}
内容来源于网络,如有侵权,请联系作者删除!