List of usage examples for com.google.common.base Strings isNullOrEmpty
public static boolean isNullOrEmpty(@Nullable String string)
From source file:org.imsglobal.caliper.validators.TimeValidator.java
/** * Check duration String format//from w ww . j a va 2 s . com * @param duration * @throws IllegalArgumentException */ public static void checkDuration(String duration) throws IllegalArgumentException { if (!(Strings.isNullOrEmpty(duration))) { checkArgument(checkPeriodFormat(duration), "%s duration format does not conform to ISO 8601 format P[n]Y[n]M[n]DT[n]H[n]M[n]S or P[n]W"); } }
From source file:com.talvish.tales.parts.RegularExpressionHelper.java
/** * Helper method that makes sure a user supplied regular expression * doesn't contain capturing groups, which would otherwise cause problems * if the regex is being used for needs where other capturing groups are * important/*w w w . j a v a 2s . c o m*/ * @param theRegEx the regex to escape * @return the non-capturing regex */ public final static String toNoncapturingExpression(String theRegEx) { Preconditions.checkArgument(!Strings.isNullOrEmpty(theRegEx), "need a regex"); // I feel there is a better way, but this is good enough for now ... StringBuilder builder = new StringBuilder(); int charClassCount = 0; int startOffset = 0; char currentChar; for (int offset = 0; offset < theRegEx.length(); offset += 1) { currentChar = theRegEx.charAt(offset); if (currentChar == '\\') { // ignore escaping character offset += 1; } else if (currentChar == '[') { // we are in a capturing group (java supports some nesting, though I don't fully here) charClassCount += 1; } else if (currentChar == ']') { // we are leaving one charClassCount -= 1; } else if (currentChar == '(' && charClassCount == 0) { if ((offset == theRegEx.length() - 1) || (theRegEx.charAt(offset + 1) != '?')) { // found at the end or next character isn't a quote/meaning non-capturing already builder.append(theRegEx.substring(startOffset, offset + 1)); builder.append("?:"); // turn into a non capturing group startOffset = offset + 1; } } } builder.append(theRegEx.substring(startOffset, theRegEx.length())); return builder.toString(); }
From source file:io.sarl.eclipse.util.AttributeUtil.java
/** Read a boolean value from the given attributes. * * @param attributes - the attributes.//from w w w . ja v a2 s .co m * @param name - the name of the attribute. * @param defaultValue - the default value. * @return the value of the attribute. */ public static boolean get(Map<String, ?> attributes, String name, boolean defaultValue) { if (attributes != null && !Strings.isNullOrEmpty(name)) { Object value = attributes.get(name); if (value != null) { if ("true".equalsIgnoreCase(value.toString())) { //$NON-NLS-1$ return true; } if ("false".equalsIgnoreCase(value.toString())) { //$NON-NLS-1$ return false; } } } return defaultValue; }
From source file:org.fenixedu.academic.domain.TeacherCategory.java
public static Optional<TeacherCategory> findByCode(String code) { if (Strings.isNullOrEmpty(code)) { return Optional.empty(); }/*from w w w . jav a2 s .c o m*/ return Bennu.getInstance().getTeacherCategorySet().stream().filter(c -> code.equals(c.getCode())).findAny(); }
From source file:org.haiku.pkg.model.PkgVersion.java
public PkgVersion(String major, String minor, String micro, String preRelease, Integer revision) { Preconditions.checkState(!Strings.isNullOrEmpty(major)); this.major = major; this.minor = minor; this.micro = micro; this.preRelease = preRelease; this.revision = revision; }
From source file:buildcraftAdditions.compat.imc.IMCHandler.java
public static void handleIMC(List<FMLInterModComms.IMCMessage> messages) { for (FMLInterModComms.IMCMessage message : messages) { String type = message.key; if (Strings.isNullOrEmpty(type)) continue; if (type.equalsIgnoreCase("addDustingRecipe")) { if (!message.isNBTMessage()) { logNotNBT(message);/*from www . j a v a 2 s . co m*/ continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Input", "Output", Constants.NBT.TAG_COMPOUND)) continue; ItemStack output = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Output")); if (output == null) { logWrongNBT(message); continue; } if (tag.hasKey("Input", Constants.NBT.TAG_STRING)) { String oreInput = tag.getString("Input"); if (!Strings.isNullOrEmpty(oreInput)) BCARecipeManager.duster.addRecipe(oreInput, output); else logWrongNBT(message); } else if (tag.hasKey("Input", Constants.NBT.TAG_COMPOUND)) { ItemStack input = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Input")); if (input != null) BCARecipeManager.duster.addRecipe(input, output); else logWrongNBT(message); } else logError(message, "Missing required NBT Tag 'Input' of type STRING or TAG_COMPOUND!"); } else if (type.equalsIgnoreCase("addCoolingTowerRecipe")) { if (!message.isNBTMessage()) { logNotNBT(message); continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Input", Constants.NBT.TAG_COMPOUND, "Output", Constants.NBT.TAG_COMPOUND, "Heat", Constants.NBT.TAG_FLOAT)) continue; FluidStack input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Input")); if (input == null) { logNotNBT(message); continue; } FluidStack output = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Output")); if (output == null) { logNotNBT(message); continue; } BCARecipeManager.cooling.addRecipe(input, output, tag.getFloat("Heat")); } else if (type.equalsIgnoreCase("addRefineryRecipe")) { if (!message.isNBTMessage()) { logNotNBT(message); continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Input", Constants.NBT.TAG_COMPOUND, "Output", Constants.NBT.TAG_COMPOUND, "RequiredHeat", Constants.NBT.TAG_INT)) continue; FluidStack input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Input")); if (input == null) { logNotNBT(message); continue; } FluidStack output = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Output")); if (output == null) { logNotNBT(message); continue; } BCARecipeManager.refinery.addRecipe(input, output, tag.getInteger("RequiredHeat")); } else if (type.equalsIgnoreCase("removeDustingRecipe")) { if (!message.isNBTMessage()) { logNotNBT(message); continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Input", Constants.NBT.TAG_COMPOUND)) continue; ItemStack input = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Input")); if (input == null) { logNotNBT(message); continue; } BCARecipeManager.duster.removeRecipe(input); } else if (type.equalsIgnoreCase("removeCoolingRecipe")) { if (!message.isNBTMessage()) { logNotNBT(message); continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Input", Constants.NBT.TAG_COMPOUND)) continue; FluidStack input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Input")); if (input == null) { logNotNBT(message); continue; } BCARecipeManager.cooling.removeRecipe(input); } else if (type.equalsIgnoreCase("removeRefineryRecipe")) { if (!message.isNBTMessage()) { logNotNBT(message); continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Input", Constants.NBT.TAG_COMPOUND)) continue; FluidStack input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Input")); if (input == null) { logNotNBT(message); continue; } BCARecipeManager.refinery.removeRecipe(input); } else if (type.equalsIgnoreCase("addMetalDust")) { if (!message.isNBTMessage()) { logNotNBT(message); continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Meta", Constants.NBT.TAG_INT, "Name", Constants.NBT.TAG_STRING, "ColorMultiplier", Constants.NBT.TAG_INT)) continue; BCAItemManager.dusts.addDust(tag.getInteger("Meta"), tag.getString("Name"), tag.getInteger("ColorMultiplier"), DustTypes.METAL_DUST); } else if (type.equalsIgnoreCase("addGemDust")) { if (!message.isNBTMessage()) { logNotNBT(message); continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Meta", Constants.NBT.TAG_INT, "Name", Constants.NBT.TAG_STRING, "ColorMultiplier", Constants.NBT.TAG_INT)) continue; BCAItemManager.dusts.addDust(tag.getInteger("Meta"), tag.getString("Name"), tag.getInteger("ColorMultiplier"), DustTypes.GEM_DUST); } else if (type.equalsIgnoreCase("addDust")) { if (!message.isNBTMessage()) { logNotNBT(message); continue; } NBTTagCompound tag = message.getNBTValue(); if (hasNotAllRequiredTags(message, tag, "Meta", Constants.NBT.TAG_INT, "Name", Constants.NBT.TAG_STRING, "ColorMultiplier", Constants.NBT.TAG_INT, "DustType", Constants.NBT.TAG_STRING)) continue; String className = tag.getString("DustType"); if (Strings.isNullOrEmpty(className)) { logWrongNBT(message); continue; } IDustType iDustType; try { iDustType = (IDustType) Class.forName(className).newInstance(); } catch (Throwable t) { logWrongNBT(message); continue; } BCAItemManager.dusts.addDust(tag.getInteger("Meta"), tag.getString("Name"), tag.getInteger("ColorMultiplier"), iDustType); } else if (type.equalsIgnoreCase("removeDust")) { if (!message.isStringMessage()) { logNotString(message); continue; } String string = message.getStringValue(); if (Strings.isNullOrEmpty(string)) { logError(message, "The string is null or empty!"); continue; } try { BCAItemManager.dusts.removeDust(Integer.valueOf(string)); } catch (NumberFormatException e) { BCAItemManager.dusts.removeDust(string); } } else { logError(message, "Message type not supported!"); } } }
From source file:com.google.idea.blaze.base.sync.data.BlazeDataStorage.java
public static File getProjectCacheDir(Project project, BlazeImportSettings importSettings) { String locationHash = importSettings.getLocationHash(); // Legacy support: The location hash used to be just the project hash if (Strings.isNullOrEmpty(locationHash)) { locationHash = project.getLocationHash(); }/* w w w .j av a 2s. c om*/ return new File(getProjectConfigurationDir(), locationHash); }
From source file:co.cask.cdap.template.etl.common.ETLUtils.java
/** * Parses a duration String to its long value. * Frequency string consists of a number followed by an unit, with 's' for seconds, 'm' for minutes, 'h' for hours * and 'd' for days. For example, an input of '5m' means 5 minutes which will be parsed to 300000 milliseconds. * * @param durationStr the duration string (ex: 5m, 5h etc). * @return long which is milliseconds equivalent of the duration string *//*from www . j a va 2 s . com*/ public static long parseDuration(String durationStr) { //TODO: replace with TimeMathParser (available only internal to cdap) Preconditions.checkArgument(!Strings.isNullOrEmpty(durationStr)); durationStr = durationStr.toLowerCase(); String value = durationStr.substring(0, durationStr.length() - 1); int parsedValue = 0; try { parsedValue = Integer.parseInt(value); } catch (NumberFormatException nfe) { Throwables.propagate(nfe); } Preconditions.checkArgument(parsedValue >= 0); char lastChar = durationStr.charAt(durationStr.length() - 1); switch (lastChar) { case 's': return TimeUnit.SECONDS.toMillis(parsedValue); case 'm': return TimeUnit.MINUTES.toMillis(parsedValue); case 'h': return TimeUnit.HOURS.toMillis(parsedValue); case 'd': return TimeUnit.DAYS.toMillis(parsedValue); } throw new IllegalArgumentException(String.format("Time unit not supported: %s", lastChar)); }
From source file:com.zaradai.kunzite.trader.events.TradeEvent.java
public static TradeEvent newTrade(String portfolioId, String instrumentId, long quantity, double price, DateTime timestamp) {/*w w w .j a v a 2 s.c o m*/ checkArgument(!Strings.isNullOrEmpty(portfolioId), "Invalid portfolio"); checkArgument(!Strings.isNullOrEmpty(instrumentId), "Invalid instrument"); checkArgument(!Double.isNaN(price), "Invalid price"); checkNotNull(timestamp, "Invalid timestamp"); return new TradeEvent(portfolioId, instrumentId, quantity, price, timestamp); }
From source file:org.imsglobal.caliper.validators.SensorValidator.java
/** * Check if Client identifier is null or empty. * @param id/* ww w .j ava2 s . c om*/ * @throws IllegalArgumentException */ public static void checkClientId(String id) throws IllegalArgumentException { checkArgument(!(Strings.isNullOrEmpty(id)), "Client identifier must be specified"); }