List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
From source file:org.apache.james.jmap.utils.DownloadPath.java
public static DownloadPath from(String path) { Preconditions.checkArgument(!Strings.isNullOrEmpty(path), "'path' is mandatory"); // path = /blobId/name // idx = 0 1 2 List<String> pathVariables = Splitter.on('/').splitToList(path); Preconditions.checkArgument(pathVariables.size() >= 1 && pathVariables.size() <= 3, "'blobId' is mandatory"); String blobId = Iterables.get(pathVariables, 1, null); Preconditions.checkArgument(!Strings.isNullOrEmpty(blobId), "'blobId' is mandatory"); return new DownloadPath(blobId, name(pathVariables)); }
From source file:net.sf.derquinsej.Types.java
/** * Returns the actual type arguments of the generic superclass of the * provided class./*from www . j a v a 2 s.c om*/ * @param subclass Class to process. * @return The type arguments of the generic superclass. * @throws IllegalArgumentException if the superclass is not a parametrized * type. */ public static Type[] getSuperclassTypeArguments(Class<?> subclass) { final Type superclass = subclass.getGenericSuperclass(); Preconditions.checkArgument(superclass instanceof ParameterizedType, "Missing type parameter."); final ParameterizedType parameterized = (ParameterizedType) superclass; return parameterized.getActualTypeArguments(); }
From source file:com.zaradai.kunzite.optimizer.control.OptimizeRequest.java
public static OptimizeRequest newRequest(Class<? extends OptimizerTactic> tactic, String target, boolean lookForMaxima, InputRow start) { Preconditions.checkNotNull(tactic, "Invalid tactic specified"); Preconditions.checkArgument(!Strings.isNullOrEmpty(target), "No target specified"); Preconditions.checkNotNull(start, "No start position specified"); return new OptimizeRequest(tactic, target, lookForMaxima, start); }
From source file:org.bigmouth.nvwa.spring.boot.SpringBootstrap.java
public static ClassPathXmlApplicationContext bootUsingSpring(String systemFlag, String[] contextFilePathes, String[] systemParameters) { Preconditions.checkArgument(StringUtils.isNotBlank(systemFlag), "systemFlag is blank."); Preconditions.checkArgument((!ArrayUtils.isEmpty(contextFilePathes)) && (contextFilePathes.length > 0), "contextFilePathes is empty."); long beginMTime = System.currentTimeMillis(); JVMUtils.setProperties(systemParameters); try {/*w ww .j av a 2 s.com*/ ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(contextFilePathes); // ctx.registerShutdownHook(); LOGGER.info(systemFlag + " boot in " + (System.currentTimeMillis() - beginMTime) + " ms"); return ctx; } catch (Exception e) { LOGGER.error(systemFlag + " boot occur error:", e); System.exit(-1); return null; } }
From source file:com.google.copybara.util.DiffUtil.java
/** * Calculates the diff between two sibling directory trees. * * <p>Returns the diff as an encoding-independent {@code byte[]} that can be write to a file or * fed directly into {@link DiffUtil#patch}. *//*from w w w . j a v a 2 s . c o m*/ public static byte[] diff(Path one, Path other, boolean verbose) throws IOException { Preconditions.checkArgument(one.getParent().equals(other.getParent()), "Paths 'one' and 'other' must be sibling directories."); Path root = one.getParent(); String[] params = new String[] { "git", "diff", "--no-color", root.relativize(one).toString(), root.relativize(other).toString() }; Command cmd = new Command(params, /*envVars*/ null, root.toFile()); try { CommandUtil.executeCommand(cmd, verbose); return EMPTY_DIFF; } catch (BadExitStatusWithOutputException e) { CommandOutput output = e.getOutput(); // git diff returns exit status 0 when contents are identical, or 1 when they are different if (!Strings.isNullOrEmpty(output.getStderr())) { throw new IOException( "Error executing 'git diff': " + e.getMessage() + ". Stderr: \n" + output.getStderr(), e); } return output.getStdoutBytes(); } catch (CommandException e) { throw new IOException("Error executing 'patch'", e); } }
From source file:com.facebook.buck.jvm.java.intellij.DependencyType.java
public static DependencyType merge(DependencyType left, DependencyType right) { if (left.equals(right)) { return left; }//from w w w. j a va 2s.c om Preconditions.checkArgument(!left.equals(COMPILED_SHADOW) && !right.equals(COMPILED_SHADOW), "The COMPILED_SHADOW type cannot be merged with other types."); return DependencyType.PROD; }
From source file:com.qcadoo.mes.orders.constants.OrderType.java
public static OrderType of(final Entity orderEntity) { Preconditions.checkArgument(orderEntity != null, "Missing entity"); return parseString(orderEntity.getStringField(OrderFields.ORDER_TYPE)); }
From source file:org.apache.james.mdn.fields.Text.java
public static Text fromRawText(String rawText) { Preconditions.checkNotNull(rawText); String trimmedText = rawText.trim(); Preconditions.checkArgument(!trimmedText.isEmpty(), "Text should not be empty"); return new Text(replaceLineBreaksByContinuation(trimmedText)); }
From source file:org.opendaylight.protocol.pcep.impl.subobject.AsNumberCaseParser.java
static AsNumberCase parseSubobject(final ByteBuf buffer) throws PCEPDeserializerException { Preconditions.checkArgument(buffer != null && buffer.isReadable(), "Array of bytes is mandatory. Can't be null or empty."); if (buffer.readableBytes() != CONTENT_LENGTH) { throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + buffer.readableBytes() + "; Expected: " + CONTENT_LENGTH + "."); }//ww w . j a va2 s . c o m return new AsNumberCaseBuilder() .setAsNumber( new AsNumberBuilder().setAsNumber(new AsNumber((long) buffer.readUnsignedShort())).build()) .build(); }
From source file:org.voltdb.utils.Digester.java
final public static String sha1AsBase64(final String str) { Preconditions.checkArgument(str != null, "specified null string"); return sha1AsBase64(str.getBytes(Charsets.UTF_8)); }