Example usage for com.google.common.base Preconditions checkArgument

List of usage examples for com.google.common.base Preconditions checkArgument

Introduction

In this page you can find the example usage for com.google.common.base Preconditions checkArgument.

Prototype

public static void checkArgument(boolean expression) 

Source Link

Document

Ensures the truth of an expression involving one or more parameters to the calling method.

Usage

From source file:org.haiku.haikudepotserver.metrics.model.RequestStart.java

public RequestStart(String name, Instant start) {
    Preconditions.checkArgument(StringUtils.isNotBlank(name));
    this.name = name;
    this.start = Preconditions.checkNotNull(start);
}

From source file:org.opendaylight.controller.remote.rpc.RemoteRpcInput.java

protected static RemoteRpcInput from(final Node node) {
    if (node == null) {
        return null;
    }//w w w. j a  v  a  2 s .c  o m
    final NormalizedNode<?, ?> deserialized = NormalizedNodeSerializer.deSerialize(node);
    Preconditions.checkArgument(deserialized instanceof ContainerNode);
    return new RemoteRpcInput((ContainerNode) deserialized);
}

From source file:org.easy.ldap.importer.CvsRow.java

public static boolean validateHeader(String line) {
    if (line == null)
        return false;

    String[] tokens = line.split(",");
    Column[] column = Column.values();/*w  w  w.ja v  a2  s .  c o  m*/
    Preconditions.checkNotNull(tokens);
    Preconditions.checkArgument(tokens.length == column.length);

    for (int i = 0; i < tokens.length; i++) {
        if (!(tokens[i].trim().equals(column[i].toString()))) {
            return false;
        }
    }

    return true;
}

From source file:org.apache.myriad.scheduler.SchedulerUtils.java

public static boolean isUniqueHostname(Protos.OfferOrBuilder offer, NodeTask taskToLaunch,
        Collection<NodeTask> tasks) {
    Preconditions.checkArgument(offer != null);
    String offerHostname = offer.getHostname();

    if (!CollectionUtils.isEmpty(tasks)) {
        for (NodeTask task : tasks) {
            if (offerHostname.equalsIgnoreCase(task.getHostname())) {
                LOGGER.debug("Offer's hostname {} is not unique", offerHostname);
                return false;
            }/* w ww .  ja va 2 s .c om*/
        }
    }
    LOGGER.debug("Offer's hostname {} is unique", offerHostname);
    return true;
}

From source file:com.google.template.soy.data.SoyValueConverterUtility.java

/**
 * Creates a new SoyDict initialized from the given keys and values. Values are converted eagerly.
 * Recognizes dotted-name syntax: adding {@code ("foo.goo", value)} will automatically create
 * {@code ['foo': ['goo': value]]}.// ww w  .  j  ava  2s .  c  o m
 *
 * @param alternatingKeysAndValues An alternating list of keys and values.
 * @return A new SoyDict initialized from the given keys and values.
 */
public static SoyDict newDict(Object... alternatingKeysAndValues) {
    Preconditions.checkArgument(alternatingKeysAndValues.length % 2 == 0);

    Map<String, Object> map = new HashMap<>();
    for (int i = 0, n = alternatingKeysAndValues.length / 2; i < n; i++) {
        String key = (String) alternatingKeysAndValues[2 * i];
        SoyValueProvider value = INSTANCE.convert(alternatingKeysAndValues[2 * i + 1]); // convert eagerly
        insertIntoNestedMap(map, key, value);
    }
    return INSTANCE.newDictFromMap(map);
}

From source file:org.openqa.selenium.build.InProject.java

/**
 * Locates a file in the current project
 *
 * @param paths path to file to locate from root of project
 * @return file being sought, if it exists
 * @throws org.openqa.selenium.WebDriverException wrapped FileNotFoundException if file could not
 *         be found/*from   www . j av  a 2  s .  c  o  m*/
 */
public static Path locate(String... paths) {
    Preconditions.checkArgument(paths.length > 0);
    return Stream.of(paths).map(path -> Paths.get(path)).filter(path -> Files.exists(path)).findFirst()
            .map(path -> path.toAbsolutePath()).orElseGet(() -> {
                Path root = findProjectRoot();
                return Stream.of(paths).map(path -> {
                    Path needle = root.resolve(path);
                    return Files.exists(needle) ? needle : null;
                }).filter(Objects::nonNull).findFirst()
                        .orElseThrow(() -> new WebDriverException(new FileNotFoundException(
                                String.format("Could not find any of %s in the project",
                                        Stream.of(paths).collect(Collectors.joining(","))))));
            });
}

From source file:com.facebook.buck.macho.LinkEditDataCommandUtils.java

public static void updateLinkEditDataCommand(ByteBuffer buffer, LinkEditDataCommand old,
        LinkEditDataCommand updated) {/*from   w  w  w .j  ava 2  s  .c o m*/
    Preconditions.checkArgument(old.getLoadCommandCommonFields().getOffsetInBinary() == updated
            .getLoadCommandCommonFields().getOffsetInBinary());
    buffer.position(updated.getLoadCommandCommonFields().getOffsetInBinary());
    writeCommandToBuffer(updated, buffer);
}

From source file:net.sourceforge.cilib.functions.continuous.moo.wfg.Problems.java

public static Vector WFG_normalise_z(Vector z) {
    Vector.Builder result = Vector.newBuilder();

    for (int i = 0; i < z.size(); i++) {
        double bound = 2.0 * (i + 1);
        Preconditions.checkArgument(z.doubleValueOf(i) >= 0.0);
        Preconditions.checkArgument(z.doubleValueOf(i) <= bound);
        result.add(z.doubleValueOf(i) / bound);
    }/*from  ww w . j a  va  2  s.  c o  m*/

    return result.build();
}

From source file:io.opencensus.tags.TagValueString.java

/**
 * Constructs a {@code TagValueString} from the given string. The string must meet the following
 * requirements://from  ww w  . j  av a 2  s .  com
 *
 * <ol>
 *   <li>It cannot be longer than {@link #MAX_LENGTH}.
 *   <li>It can only contain printable ASCII characters.
 * </ol>
 *
 * @param value the tag value.
 * @throws IllegalArgumentException if the {@code String} is not valid.
 */
public static TagValueString create(String value) {
    Preconditions.checkArgument(StringUtil.isValid(value));
    return new AutoValue_TagValueString(value);
}

From source file:com.anhth12.lambda.ml.param.Unordered.java

Unordered(Collection<T> values) {
    Preconditions.checkNotNull(values);
    Preconditions.checkArgument(!values.isEmpty());
    this.values = new ArrayList<>(values);
}