Example usage for com.google.common.base Strings isNullOrEmpty

List of usage examples for com.google.common.base Strings isNullOrEmpty

Introduction

In this page you can find the example usage for com.google.common.base Strings isNullOrEmpty.

Prototype

public static boolean isNullOrEmpty(@Nullable String string) 

Source Link

Document

Returns true if the given string is null or is the empty string.

Usage

From source file:org.haiku.haikudepotserver.dataobjects.UserRating.java

public static Optional<UserRating> tryGetByCode(ObjectContext context, String code) {
    Preconditions.checkArgument(null != context, "the context must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "the code must be supplied");
    return Optional.ofNullable(ObjectSelect.query(UserRating.class).where(CODE.eq(code)).selectOne(context));
}

From source file:org.haiku.haikudepotserver.dataobjects.PkgCategory.java

public static Optional<PkgCategory> getByCode(ObjectContext context, final String code) {
    Preconditions.checkArgument(null != context, "the context must be provided");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "the code must be supplied");
    return getAll(context).stream().filter(pc -> pc.getCode().equals(code)).collect(SingleCollector.optional());
}

From source file:com.bccriskadvisory.link.utility.Utilities.java

public static boolean isNullOrEmpty(String input) {
    return Strings.isNullOrEmpty(input);
}

From source file:com.google.gerrit.testutil.SshMode.java

public static SshMode get() {
    String value = System.getenv(ENV_VAR);
    if (Strings.isNullOrEmpty(value)) {
        value = System.getProperty(SYS_PROP);
    }//from   ww  w .j a  va 2 s.co  m
    if (Strings.isNullOrEmpty(value)) {
        return YES;
    }
    value = value.toUpperCase();
    SshMode mode = Enums.getIfPresent(SshMode.class, value).orNull();
    if (!Strings.isNullOrEmpty(System.getenv(ENV_VAR))) {
        checkArgument(mode != null, "Invalid value for env variable %s: %s", ENV_VAR, System.getenv(ENV_VAR));
    } else {
        checkArgument(mode != null, "Invalid value for system property %s: %s", SYS_PROP,
                System.getProperty(SYS_PROP));
    }
    return mode;
}

From source file:com.palantir.lock.AtlasRowLockDescriptor.java

/** Returns a {@code LockDescriptor} instance for the given table and row. */
public static LockDescriptor of(String tableName, byte[] rowName) {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(tableName));
    Preconditions.checkNotNull(rowName);
    byte[] tableBytes = tableName.getBytes();
    byte[] bytes = new byte[tableBytes.length + 1 + rowName.length];
    System.arraycopy(tableBytes, 0, bytes, 0, tableBytes.length);
    System.arraycopy(rowName, 0, bytes, tableBytes.length + 1, rowName.length);
    return new LockDescriptor(bytes);
}

From source file:com.microsoftopentechnologies.auth.utils.EncodingHelper.java

public static Map<String, String> parseKeyValueList(String input, char delimiter, boolean urlDecode) {
    if (Strings.isNullOrEmpty(input)) {
        return null;
    }//from  w w w  .ja va 2 s . c  o m

    Map<String, String> response = Splitter.on(delimiter).trimResults().omitEmptyStrings()
            .withKeyValueSeparator('=').split(input);

    if (urlDecode) {
        return Maps.transformValues(response, new Function<String, String>() {
            @Override
            public String apply(String s) {
                try {
                    return URLDecoder.decode(s, Charsets.UTF_8.name());
                } catch (UnsupportedEncodingException e) {
                    return s;
                }
            }
        });
    } else {
        return response;
    }
}

From source file:it.anyplace.sync.core.utils.PathUtils.java

public static boolean isRoot(String path) {
    return Strings.isNullOrEmpty(path);
}

From source file:com.vip.saturn.job.utils.ItemUtils.java

/**
 * ??./*from   ww  w .  ja va 2s .c om*/
 * 
 * @param itemsString 
 * @return 
 */
public static List<Integer> toItemList(final String itemsString) {
    if (Strings.isNullOrEmpty(itemsString)) {
        return Collections.emptyList();
    }
    String[] items = itemsString.split(DELIMITER);
    List<Integer> result = new ArrayList<>(items.length);
    for (String each : items) {
        int item = Integer.parseInt(each);
        if (!result.contains(item)) {
            result.add(item);
        }
    }
    return result;
}

From source file:buildcraftAdditions.ModIntegration.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.equals("addDustingRecipe")) {
            if (!message.isNBTMessage()) {
                logNotNBT(message);/*www  . j av a 2 s  .  c  om*/
                continue;
            }

            NBTTagCompound tag = message.getNBTValue();
            if (!checkRequiredNBTTags("Dusting", tag, "Input", "Output"))
                continue;

            if (tag.hasKey("Output", Constants.NBT.TAG_COMPOUND)) {
                ItemStack output = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Output"));
                if (output == null)
                    continue;
                if (tag.hasKey("Input", Constants.NBT.TAG_STRING)) {
                    String oreInput = tag.getString("Input");
                    if (!Strings.isNullOrEmpty(oreInput))
                        BCARecipeManager.duster.addRecipe(oreInput, output);
                } 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 if (type.equals("addCoolingTowerRecipe")) {
            if (!message.isNBTMessage()) {
                logNotNBT(message);
                continue;
            }

            NBTTagCompound tag = message.getNBTValue();
            if (!checkRequiredNBTTags("Cooling Tower", tag, "Input", "Output", "Heat"))
                continue;

            if (tag.hasKey("Input", Constants.NBT.TAG_COMPOUND)
                    && tag.hasKey("Output", Constants.NBT.TAG_COMPOUND)
                    && tag.hasKey("Heat", Constants.NBT.TAG_FLOAT)) {
                FluidStack input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Input"));
                if (input == null)
                    continue;
                FluidStack output = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Output"));
                if (output == null)
                    continue;
                BCARecipeManager.cooling.addRecipe(input, output, tag.getFloat("Heat"));
            }
        } else if (type.equals("addRefineryRecipe")) {
            if (!message.isNBTMessage()) {
                logNotNBT(message);
                continue;
            }

            NBTTagCompound tag = message.getNBTValue();
            if (!checkRequiredNBTTags("Refinery", tag, "Input", "Output", "RequiredHeat"))
                continue;

            if (tag.hasKey("Input", Constants.NBT.TAG_COMPOUND)
                    && tag.hasKey("Output", Constants.NBT.TAG_COMPOUND)
                    && tag.hasKey("RequiredHeat", Constants.NBT.TAG_INT)) {
                FluidStack input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Input"));
                if (input == null)
                    continue;
                FluidStack output = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Output"));
                if (output == null)
                    continue;
                BCARecipeManager.refinery.addRecipe(input, output, tag.getInteger("RequiredHeat"));
            }
        } else if (type.equals("removeDustingRecipe")) {
            if (!message.isNBTMessage()) {
                logNotNBT(message);
                continue;
            }

            NBTTagCompound tag = message.getNBTValue();
            if (!checkRequiredNBTTags("Dusting", tag, "Input"))
                continue;

            if (tag.hasKey("Input", Constants.NBT.TAG_COMPOUND)) {
                ItemStack input = ItemStack.loadItemStackFromNBT(tag.getCompoundTag("Input"));
                if (input == null)
                    continue;
                BCARecipeManager.duster.removeRecipe(input);
            }
        } else if (type.equals("removeCoolingRecipe")) {
            if (!message.isNBTMessage()) {
                logNotNBT(message);
                continue;
            }

            NBTTagCompound tag = message.getNBTValue();
            if (!checkRequiredNBTTags("Cooling Tower", tag, "Input"))
                continue;

            if (tag.hasKey("Input", Constants.NBT.TAG_COMPOUND)) {
                FluidStack input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Input"));
                if (input == null)
                    continue;
                BCARecipeManager.cooling.removeRecipe(input);
            }
        } else if (type.equals("removeRefineryRecipe")) {
            if (!message.isNBTMessage()) {
                logNotNBT(message);
                continue;
            }

            NBTTagCompound tag = message.getNBTValue();
            if (!checkRequiredNBTTags("Refinery", tag, "Input"))
                continue;

            if (tag.hasKey("Input", Constants.NBT.TAG_COMPOUND)) {
                FluidStack input = FluidStack.loadFluidStackFromNBT(tag.getCompoundTag("Input"));
                if (input == null)
                    continue;
                BCARecipeManager.refinery.removeRecipe(input);
            }
        }
    }
}

From source file:be.ohatv.btclients.Transmission.java

public static boolean addTorrent(String url, String magnet, String downloadpath) {
    try {//from   ww  w.j  a  va2  s.co m
        if (Strings.isNullOrEmpty(sessiontoken)) {
            getsessiontoken(url);
        }
        if (Strings.isNullOrEmpty(sessiontoken) == false) {
            JSONObject arg = new JSONObject();
            arg.put("filename", magnet);
            arg.put("download-dir", downloadpath);
            JSONObject json = new JSONObject();
            json.put("method", "torrent-add");
            json.put("arguments", arg);
            if (sendPost(url, json.toString(), "X-Transmission-Session-Id", sessiontoken) == false) {
                sessiontoken = null;
                return false;
            }
            return true;
        } else {
            DbFunctions.addNotifications(3, "Can't open session with Transmission.");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return false;
}