List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:li.klass.fhem.util.ValueExtractUtil.java
public static double extractLeadingDouble(String text, int digits) { text = extractLeadingNumericText(text, digits); if (Strings.isNullOrEmpty(text)) return 0; return Double.valueOf(text); }
From source file:org.apache.kylin.metrics.property.QueryRPCPropertyEnum.java
public static QueryRPCPropertyEnum getByName(String name) { if (Strings.isNullOrEmpty(name)) { return null; }//from w w w. jav a2 s . c o m for (QueryRPCPropertyEnum property : QueryRPCPropertyEnum.values()) { if (property.propertyName.equals(name.toUpperCase())) { return property; } } return null; }
From source file:org.haiku.haikudepotserver.dataobjects.Country.java
public static Optional<Country> tryGetByCode(ObjectContext context, final String code) { Preconditions.checkNotNull(context, "the context must be provided"); Preconditions.checkState(!Strings.isNullOrEmpty(code)); return getAll(context).stream().filter(a -> a.getCode().equals(code)).collect(SingleCollector.optional()); }
From source file:org.haiku.haikudepotserver.dataobjects.UserPasswordResetToken.java
public static Optional<UserPasswordResetToken> getByCode(ObjectContext context, String code) { Preconditions.checkArgument(null != context, "the context must be supplied"); Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "the code must be provided"); return Optional.ofNullable( ObjectSelect.query(UserPasswordResetToken.class).where(CODE.eq(code)).selectOne(context)); }
From source file:com.pinterest.rocksplicator.controller.util.ZookeeperConfigParser.java
public static String parseEndpoints(String zkHostsFile, String zkCluster) { Yaml yaml = new Yaml(); try {/*from w w w. ja v a2 s. c o m*/ String cluster = "default"; if (!Strings.isNullOrEmpty(zkCluster)) { cluster = zkCluster; } String content = Files.toString(new File(zkHostsFile), Charsets.US_ASCII); Map<String, Map<String, List<String>>> config = (Map) yaml.load(content); List<String> endpoints = config.get("clusters").get(cluster); return String.join(",", endpoints); } catch (Exception e) { LOG.error("Cannot parse Zookeeper endpoints!", e); return null; } }
From source file:org.xacml4j.v30.types.DoubleExp.java
public static DoubleExp of(String v) { Preconditions.checkArgument(!Strings.isNullOrEmpty(v)); if (v.endsWith("INF")) { int infIndex = v.lastIndexOf("INF"); v = v.substring(0, infIndex) + "Infinity"; }// w ww. j av a2 s .co m return new DoubleExp(Double.parseDouble(v)); }
From source file:talkeeg.common.ipc.IpcUtil.java
/** * get network address like `a.b.c.d` or `XX:XX:..:XX` from `tg:[XX:XX:..:XX/net-prefix-len]:port` representation * @param address/* ww w . java 2 s . co m*/ * @return */ public static String getNetworkAddress(String address) { if (Strings.isNullOrEmpty(address)) { return null; } final TgAddress tgAddress = TgAddress.from(address); if (tgAddress == null) { return null; } final int prefixLen = tgAddress.getNetworkPrefixLength(); if (prefixLen == TgAddress.NO_NETWORK_PREFIX || prefixLen == 0) { return null; } String host = tgAddress.getHost(); try { final InetAddress inetAddress = InetAddress.getByName(host); final byte[] value = inetAddress.getAddress(); final int addressLenInBits = value.length * 8; if (addressLenInBits < prefixLen) { throw new RuntimeException("network prefix length " + prefixLen + "bits greater than address " + addressLenInBits + "bits"); } //create network address from host address final int lastNetByte = prefixLen / 8; final int lastNetworkByteBits = prefixLen % 8; if (lastNetworkByteBits != 0) { value[lastNetByte] = (byte) (value[lastNetByte] & (0xff << (8 - lastNetworkByteBits))); } else { value[lastNetByte] = 0; } for (int i = lastNetByte + 1; i < value.length; ++i) { value[i] = 0; } return InetAddress.getByAddress(value).getHostAddress(); } catch (UnknownHostException e) { throw new RuntimeException(" at address: " + address, e); } }
From source file:com.infinities.nova.common.Resource.java
public static void processStack(ContainerRequestContext requestContext, String projectid, NovaRequestContext context) {/* w ww . j a va2 s . co m*/ logger.debug("projectid: {}, context projectid: {}", new Object[] { projectid, context.getProjectId() }); if (!Strings.isNullOrEmpty(projectid) && context != null && !projectid.equals(context.getProjectId())) { String msg = String.format( "Malformed request URL: URL's project_id '%s' doesn't match Context's project_id '%s'", projectid, context.getProjectId()); throw new HTTPBadRequestException(msg); } }
From source file:com.google.apps.easyconnect.easyrp.client.basic.util.IdpUtils.java
/** * Checks if a user name is valid./*from ww w . java 2 s .c om*/ * * @param username the user name to be checked * @return ture for valid, false otherwise */ public static boolean isValidUsername(String username) { if (Strings.isNullOrEmpty(username)) { return false; } return username.matches(USERNAME_REGEX); }
From source file:org.onehippo.cms7.essentials.dashboard.model.TargetPom.java
public static TargetPom pomForName(final String type) { if (Strings.isNullOrEmpty(type)) { return TargetPom.INVALID; }//from w w w . jav a 2s . c om if (type.equals(SITE.name)) { return SITE; } else if (type.equals(CMS.name)) { return CMS; } else if (type.equals(BOOTSTRAP.name)) { return BOOTSTRAP; } else if (type.equals(PROJECT.name)) { return PROJECT; } else if (type.equals(BOOTSTRAP_CONFIG.name)) { return BOOTSTRAP_CONFIG; } else if (type.equals(BOOTSTRAP_CONTENT.name)) { return BOOTSTRAP_CONTENT; } else if (type.equals(ESSENTIALS.name)) { return ESSENTIALS; } return TargetPom.INVALID; }