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:org.opendaylight.controller.cluster.datastore.shardstrategy.ShardStrategyFactory.java

public ShardStrategyFactory(final Configuration configuration) {
    Preconditions.checkState(configuration != null, "configuration should not be missing");
    this.configuration = configuration;
}

From source file:org.eclipse.jdt.ls.core.internal.JDTEnvironmentUtils.java

/**
 * Returns with the client port if set. Otherwise, returns with {@code null}.
 * Throw an {@link IllegalStateException} if the port is set but it has an
 * invalid port number.//from www .j  a  v a 2s.co m
 *
 * When the client port environment variable is set to a valid port number, then
 * plain socket communication will be used between the language client and the
 * server instead of the standard IO stream one.
 */
public static Integer getClientPort() {
    final String port = Environment.get(CLIENT_PORT);
    if (port != null) {
        int clientPort = Integer.parseInt(port);
        Preconditions.checkState(clientPort >= 1 && clientPort <= 65535,
                "The port must be an integer between 1 and 65535. It was: '" + port + "'.");
        return clientPort;
    }
    return null;
}

From source file:me.lucko.luckperms.common.api.delegates.model.ApiTrack.java

public static me.lucko.luckperms.common.model.Track cast(Track g) {
    Preconditions.checkState(g instanceof ApiTrack,
            "Illegal instance " + g.getClass() + " cannot be handled by this implementation.");
    return ((ApiTrack) g).getHandle();
}

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

@Override
public Optional<Ref> call() {
    Preconditions.checkState(id != null, "id has not been set.");
    Predicate<Ref> filter = new Predicate<Ref>() {
        @Override//from  w  w  w  .  jav  a2  s  .  c  o m
        public boolean apply(@Nullable Ref ref) {
            return ref.getObjectId().equals(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:gobblin.commit.DeliverySemantics.java

/**
 * Get the devliery semantics type from {@link ConfigurationKeys#DELIVERY_SEMANTICS}.
 * The default value is {@link Type#AT_LEAST_ONCE}.
 *//* w w  w.  ja v  a  2  s. co m*/
public static DeliverySemantics parse(State state) {
    String value = state.getProp(ConfigurationKeys.GOBBLIN_RUNTIME_DELIVERY_SEMANTICS, AT_LEAST_ONCE.toString())
            .toUpperCase();
    Optional<DeliverySemantics> semantics = Enums.getIfPresent(DeliverySemantics.class, value);
    Preconditions.checkState(semantics.isPresent(), value + " is not a valid delivery semantics");
    return semantics.get();
}

From source file:com.gradleware.tooling.toolingmodel.repository.internal.DefaultOmniEclipseGradleBuild.java

public static DefaultOmniEclipseGradleBuild from(EclipseProject eclipseRootProject,
        boolean enforceAllTasksPublic) {
    Preconditions.checkState(eclipseRootProject.getParent() == null,
            "Provided Eclipse project is not the root project.");
    return new DefaultOmniEclipseGradleBuild(DefaultOmniEclipseProject.from(eclipseRootProject),
            DefaultOmniGradleProject.from(eclipseRootProject.getGradleProject(), enforceAllTasksPublic));
}

From source file:codecrafter47.bungeetablistplus.api.bukkit.BungeeTabListPlusBukkitAPI.java

/**
 * Unregisters a variable/*  w ww .  j  a  v a 2  s . com*/
 *
 * @param variable the variable
 */
public static void unregisterVariable(Variable variable) {
    Preconditions.checkState(instance != null, "instance is null, is the plugin enabled?");
    instance.unregisterVariable0(variable);
}

From source file:com.aliyun.odps.ogg.handler.datahub.util.BucketPath.java

public static String escapeString(String in, long timestamp, Map rowMap) {
    Matcher matcher = tagPattern.matcher(in);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        String replacement = "";
        if (matcher.group(2) != null) {
            replacement = (String) rowMap.get(matcher.group(2).toLowerCase());
            if (replacement == null) {
                replacement = "";
            }//from w  ww. j ava2 s.c  o m
        } else {
            Preconditions.checkState(matcher.group(1) != null && matcher.group(1).length() == 1,
                    "Expected to match single character tag in string " + in);
            char c = matcher.group(1).charAt(0);
            replacement = replaceShorthand(c, timestamp);
        }

        replacement = replacement.replaceAll("\\\\", "\\\\\\\\");
        replacement = replacement.replaceAll("\\$", "\\\\\\$");

        matcher.appendReplacement(sb, replacement);
    }
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:org.opendaylight.coretutorials.clustering.singleton.hs.topo.HighSacalabilitySampleTopoProvider.java

/**
 * Method called when the blueprint container is created.
 *
 * @param dataBroker : reference to the MD-SAL DataBroker
 * @param rpcProviderRegistry : reference to MD-SAL RPC Provider Registry
 * @param clusterSingletonServiceProvider : reference to MD-SAL Cluster Singleton Service
 * @param sampleServiceProvider : All device RPCs holder
 *//*from  www.j  a v a  2s  . c o m*/
public static void init(final DataBroker dataBroker, final RpcProviderRegistry rpcProviderRegistry,
        final ClusterSingletonServiceProvider clusterSingletonServiceProvider,
        final SampleServicesProvider sampleServiceProvider) {
    LOG.info("HighSacalabilitySampleTopoProvider Session Initiated");
    Preconditions.checkState(sampleDeviceTopologyDiscoveryManager == null, "we have instance of SFRM");
    sampleDeviceTopologyDiscoveryManager = new SampleDeviceTopologyDiscoveryManager(dataBroker,
            rpcProviderRegistry, clusterSingletonServiceProvider, sampleServiceProvider);
}

From source file:app.philm.in.controllers.BaseController.java

public final void init() {
    Preconditions.checkState(mInited == false, "Already inited");
    mInited = true;
    onInited();
}