List of usage examples for com.google.common.base Preconditions checkState
public static void checkState(boolean expression, @Nullable Object errorMessage)
From source file:org.basepom.mojo.propertyhelper.macros.DemoMacro.java
@Override public Optional<String> getValue(@Nonnull final MacroDefinition macroDefinition, @Nonnull final ValueProvider valueProvider, @Nonnull final AbstractPropertyHelperMojo mojo) { Preconditions.checkState(mojo != null, "inserted mojo is null!"); final String type = Objects.firstNonNull(macroDefinition.getProperties().get("type"), "static"); if ("static".equals(type)) { return Optional.of("static-value"); } else if ("property".equals(type)) { return valueProvider.getValue(); } else {// w w w .java 2s.c o m return Optional.fromNullable(macroDefinition.getProperties().get("value")); } }
From source file:org.opendaylight.controller.datastore.internal.ClusteredDataStoreManager.java
@Override public DataCommitTransaction<InstanceIdentifier<? extends Object>, Object> requestCommit( DataModification<InstanceIdentifier<? extends Object>, Object> modification) { Preconditions.checkState(clusteredDataStore != null, "clusteredDataStore cannot be null"); return clusteredDataStore.requestCommit(modification); }
From source file:org.opendaylight.controller.yang.parser.util.TopologicalSort.java
private static void detectCycles(Set<Node> nodes) { // Detect cycles boolean cycle = false; Node cycledNode = null;/*from w w w . java 2s . c om*/ for (Node n : nodes) { if (!n.getOutEdges().isEmpty()) { cycle = true; cycledNode = n; break; } } Preconditions.checkState(cycle == false, "Cycle detected in graph around node: " + cycledNode); }
From source file:com.google.enterprise.adaptor.secmgr.saml.GroupImpl.java
@Override public String getName() { Preconditions.checkState(name != null, "Name must be non-null"); return name; }
From source file:com.continuuity.weave.internal.zookeeper.KillZKSession.java
/** * Kills a Zookeeper client to simulate failure scenarious during testing. * Callee will provide the amount of time to wait before it's considered failure * to kill a client./*from w ww .jav a2 s .c om*/ * * @param client that needs to be killed. * @param connectionString of Quorum * @param maxMs time in millisecond specifying the max time to kill a client. * @throws IOException When there is IO error * @throws InterruptedException When call has been interrupted. */ public static void kill(ZooKeeper client, String connectionString, int maxMs) throws IOException, InterruptedException { final CountDownLatch latch = new CountDownLatch(1); ZooKeeper zk = new ZooKeeper(connectionString, maxMs, new Watcher() { @Override public void process(WatchedEvent event) { if (event.getState() == Event.KeeperState.SyncConnected) { latch.countDown(); } } }, client.getSessionId(), client.getSessionPasswd()); try { Preconditions.checkState(latch.await(maxMs, TimeUnit.MILLISECONDS), "Fail to kill ZK connection."); } finally { zk.close(); } }
From source file:edu.umn.msi.tropix.common.jobqueue.deployer.DeployerProperties.java
public String get() { Preconditions.checkState(properties.size() == 1, "Expected to have exactly one property when get() is called, actual number " + properties.size()); return apply(Iterables.getOnlyElement(properties.keySet())); }
From source file:org.opendaylight.controller.netconf.confignetconfconnector.mapping.attributes.fromxml.ObjectNameAttributeReadingStrategy.java
@Override AttributeConfigElement readElementHook(List<XmlElement> configNodes) throws NetconfDocumentedException { XmlElement firstChild = configNodes.get(0); Preconditions.checkState(configNodes.size() == 1, "This element should be present only once " + firstChild + " but was " + configNodes.size()); Preconditions.checkNotNull(firstChild, "Element %s should be present", firstChild); return AttributeConfigElement.create(getNullableDefault(), resolve(firstChild)); }
From source file:com.facebook.buck.core.cell.impl.RootCellFactory.java
public static Cell create(CellProvider cellProvider, CellPathResolver rootCellCellPathResolver, CellPathResolver rootCellPathResolver, ProjectFilesystem rootFilesystem, BuckModuleManager moduleManager, PluginManager pluginManager, BuckConfig rootConfig, ImmutableMap<String, String> environment, ProcessExecutor processExecutor, ExecutableFinder executableFinder) { Preconditions.checkState( !rootCellCellPathResolver.getCanonicalCellName(rootFilesystem.getRootPath()).isPresent(), "Root cell should be nameless"); RuleKeyConfiguration ruleKeyConfiguration = ConfigRuleKeyConfigurationFactory.create(rootConfig, moduleManager);/* w ww . j a v a 2s. co m*/ ToolchainProvider toolchainProvider = new DefaultToolchainProvider(pluginManager, environment, rootConfig, rootFilesystem, processExecutor, executableFinder, ruleKeyConfiguration); return ImmutableCell.of(rootCellCellPathResolver.getKnownRoots(), Optional.empty(), rootFilesystem, rootConfig, cellProvider, toolchainProvider, ruleKeyConfiguration, rootCellPathResolver); }
From source file:org.xacml4j.spring.DecisionCombiningAlgorithmProviderBean.java
public void setClass(Class<?> clazz) { Preconditions.checkNotNull(clazz);//from w w w . j a v a 2 s . com Preconditions.checkState(providerInstance == null, "Either provider instance or class can be specified, NOT both"); this.providerClass = clazz; }
From source file:org.sonar.javascript.cfg.ForwardingBlock.java
@Override public MutableBlock successor() { Preconditions.checkState(successor != null, "No successor was set on " + this); return successor; }