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

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

Introduction

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

Prototype

public static void checkState(boolean expression, @Nullable Object errorMessage) 

Source Link

Document

Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.

Usage

From source file:alluxio.master.journal.AbstractJournalSystem.java

@Override
public synchronized void start() throws InterruptedException, IOException {
    Preconditions.checkState(!mRunning, "Journal is already running");
    startInternal();/*from   w w w  .  j a v a2  s.  c o  m*/
    mRunning = true;
}

From source file:com.google.inject.internal.DelegatingInvocationHandler.java

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {//from   w  w w  .j a v  a  2  s .  c  o m
        // checking volatile field for synchronization
        Preconditions.checkState(initialized,
                "This is a proxy used to support" + " circular references. The object we're"
                        + " proxying is not constructed yet. Please wait until after"
                        + " injection has completed to use this object.");
        Preconditions.checkNotNull(delegate,
                "This is a proxy used to support" + " circular references. The object we're "
                        + " proxying is initialized to null." + " No methods can be called.");

        // TODO: method.setAccessible(true); ?
        // this would fix visibility errors when we proxy a
        // non-public interface.
        return method.invoke(delegate, args);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (IllegalArgumentException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        throw e.getTargetException();
    }
}

From source file:org.locationtech.geogig.plumbing.ResolveBranchId.java

@Override
protected Optional<Ref> _call() {
    Preconditions.checkState(id != null, "id has not been set.");
    Predicate<Ref> filter = new Predicate<Ref>() {

        private ObjectId id = ResolveBranchId.this.id;

        @Override/*  ww  w  . j  a  v  a2 s .  c o  m*/
        public boolean apply(@Nullable Ref ref) {
            String refName = ref.getName();
            ObjectId refId = ref.getObjectId();
            return refName.startsWith(Ref.HEADS_PREFIX) && refId.equals(this.id);
        }
    };
    ImmutableSet<Ref> refs = command(ForEachRef.class).setFilter(filter).call();
    if (refs.isEmpty()) {
        return Optional.absent();
    } else {
        return Optional.of(refs.iterator().next());
    }
}

From source file:com.facebook.buck.apple.xcode.xcodeproj.SourceTreePath.java

public SourceTreePath(PBXReference.SourceTree sourceTree, Path path) {
    this.sourceTree = Preconditions.checkNotNull(sourceTree);
    Preconditions.checkState(path != null && path.toString().length() > 0,
            "A path to a file cannot be null or empty");
    path = path.normalize();/*from   ww w .j  a v a2 s .  c o m*/
    Preconditions.checkState(path.toString().length() > 0, "A path to a file cannot be empty");
    this.path = path;
}

From source file:org.geogit.api.plumbing.DescribeFeatureType.java

/**
 * Retrieves the set of property descriptors for the given feature type.
 * //w  w  w .  j  a  v  a 2  s . c om
 * @return a sorted set of all the property descriptors of the feature type.
 */
@Override
public ImmutableSet<PropertyDescriptor> call() {
    Preconditions.checkState(featureType != null, "FeatureType has not been set.");

    FeatureType type = featureType.type();

    ImmutableSet.Builder<PropertyDescriptor> propertySetBuilder = new ImmutableSet.Builder<PropertyDescriptor>();

    propertySetBuilder.addAll(type.getDescriptors());

    return propertySetBuilder.build();
}

From source file:com.google.gerrit.sshd.PluginCommandModule.java

@Override
protected final void configure() {
    Preconditions.checkState(command != null, "@PluginName must be provided");
    bind(Commands.key(command)).toProvider(new DispatchCommandProvider(command));
    configureCommands();//from w  ww.j a  va 2 s. co  m
}

From source file:com.github.jcustenborder.kafka.connect.utils.config.ValidPort.java

ValidPort(int start, int end) {
    Preconditions.checkState(start > 0, "start must be greater than 0.");
    Preconditions.checkState(end > 0, "end must be greater than 0.");
    Preconditions.checkState(start <= 65535, "start must be less than or equal to 65535.");
    Preconditions.checkState(end <= 65535, "end must be less than or equal to 65535.");
    Preconditions.checkState(end > start, "end must be less than or equal to 65535.");

    this.start = start;
    this.end = end;
}

From source file:org.apache.spark.tez.utils.ClassPathUtils.java

/**
 * //from ww w .  j a  va  2 s.c  o m
 * @param resource
 */
public static void addResourceToClassPath(File resource) {
    try {
        Preconditions.checkState(resource != null && resource.exists(),
                "'resource' must not be null and it must exist: " + resource);
        URLClassLoader cl = (URLClassLoader) Thread.currentThread().getContextClassLoader();
        Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
        addUrlMethod.setAccessible(true);
        addUrlMethod.invoke(cl, resource.toURI().toURL());
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}

From source file:com.facebook.buck.graph.DirectedAcyclicGraph.java

public DirectedAcyclicGraph(MutableDirectedGraph<T> graph) {
    Preconditions.checkState(graph.isAcyclic(), "Graph must by acyclic");
    this.nodes = graph.createImmutableCopyOfNodes();
    this.outgoingEdges = graph.createImmutableCopyOfOutgoingEdges();
    this.incomingEdges = graph.createImmutableCopyOfIncomingEdges();
}

From source file:org.seedstack.samples.ddd.domain.model.location.UnLocode.java

/**
 * Constructor.//w w w .  j  a  va 2s. co m
 *
 * @param countryAndLocation Location string.
 */
public UnLocode(final String countryAndLocation) {
    Preconditions.checkNotNull(countryAndLocation, "Country and location may not be null");
    Preconditions.checkState(VALID_PATTERN.matcher(countryAndLocation).matches(),
            countryAndLocation + " is not a valid UN/LOCODE (does not match pattern)");

    this.unlocode = countryAndLocation.toUpperCase();
}