List of usage examples for com.google.common.base Preconditions checkArgument
public static void checkArgument(boolean expression, @Nullable Object errorMessage)
From source file:com.nesscomputing.mojo.numbers.beans.IWFCEnum.java
public static IWFCEnum forString(final String value) { Preconditions.checkArgument(value != null, "the value can not be null"); return valueOf(IWFCEnum.class, value.toUpperCase(Locale.ENGLISH)); }
From source file:org.haiku.haikudepotserver.dataobjects.Permission.java
public static Optional<Permission> getByCode(ObjectContext context, final String code) { Preconditions.checkArgument(null != context, "the context must be provided"); Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "the permission code must be provided"); return getAll(context).stream().filter(p -> p.getCode().equals(code)).collect(SingleCollector.optional()); }
From source file:org.haiku.haikudepotserver.dataobjects.UserRatingStability.java
public static Optional<UserRatingStability> getByCode(ObjectContext context, String code) { Preconditions.checkArgument(null != context, "the context must be supplied"); Preconditions.checkArgument(!Strings.isNullOrEmpty(code), "the code must be supplied"); return getAll(context).stream().filter((urs) -> urs.getCode().equals(code)).findFirst(); }
From source file:org.basepom.mojo.propertyhelper.beans.IgnoreWarnFailCreate.java
public static IgnoreWarnFailCreate forString(final String value) { Preconditions.checkArgument(value != null, "the value can not be null"); return Enum.valueOf(IgnoreWarnFailCreate.class, value.toUpperCase(Locale.ENGLISH)); }
From source file:org.eclipse.viatra.query.runtime.util.IncQueryLoggingUtil.java
public static void setExternalLogger(Logger externalLogger) { Preconditions.checkArgument(externalLogger != null, "Must not set up null logger"); IncQueryLoggingUtil.externalLogger = externalLogger; }
From source file:org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil.java
public static void setExternalLogger(Logger externalLogger) { Preconditions.checkArgument(externalLogger != null, "Must not set up null logger"); ViatraQueryLoggingUtil.externalLogger = externalLogger; }
From source file:org.eclipse.viatra.modelobfuscator.util.ObfuscatorUtil.java
public static String generateHexSeed(int length) { Preconditions.checkArgument(length > 0, "Length must be positive"); // each fragment is 3 characters and we need an additional one int noOfFragments = (length / 3) + 1; StringBuilder sb = new StringBuilder(noOfFragments * 3); for (int i = 0; i < noOfFragments; i++) { // randomized string but first 3 chars not too random (typically "3fd") String fragment = Long.toHexString(Double.doubleToLongBits(Math.random())); // take only last 3 characters sb.append(fragment.substring(3, 6)); }/*from w w w. j ava2 s . c o m*/ return sb.substring(0, length); }
From source file:model.utilities.pid.ControllerFactory.java
/** * The factory creates the controller of specified type by drawing parameters at random from the model class * @param controllerType the type of controller you want * @return the controller object you get *///from w ww.jav a 2 s. com public static <C extends Controller> C buildController(Class<C> controllerType, MacroII model) { Preconditions.checkArgument(controllerType != null && model != null, "Don't pass nulls!"); //if it's a PID controller if (controllerType.equals(PIDController.class)) { return (C) new PIDController(model.drawProportionalGain(), model.drawIntegrativeGain(), model.drawDerivativeGain(), model.drawPIDSpeed()); } else if (controllerType.equals(CascadePIDController.class)) { return (C) new CascadePIDController(model.drawProportionalGain(), model.drawIntegrativeGain(), model.drawDerivativeGain(), model.drawProportionalGain(), 0, 0, model.getRandom()); } else if (controllerType.equals(CascadePToPIDController.class)) { return (C) new CascadePToPIDController(model); } else throw new IllegalArgumentException("The Controller factory doesn't recognize: " + controllerType); }
From source file:com.zaradai.kunzite.optimizer.model.InputSpec.java
public static InputSpec newInstance(int position, Series series) { Preconditions.checkArgument(position >= 0, "Invalid input position specified"); Preconditions.checkNotNull(series, "Invalid Series supplied"); return new InputSpec(position, series); }
From source file:org.haiku.haikudepotserver.dataobjects.Prominence.java
public static List<Prominence> getAll(ObjectContext context) { Preconditions.checkArgument(null != context, "the context must be supplied"); return ObjectSelect.query(Prominence.class).orderBy(ORDERING.asc()).sharedCache().select(context); }