List of usage examples for com.google.common.base Preconditions checkState
public static void checkState(boolean expression, @Nullable Object errorMessage)
From source file:graph.features.cpp.ClosedCPP.java
public static <T> ClosedCPP<T> from(final UndirectedGraph<T> graph, final MatchingAlgorithmInterface matchingAlgorithm) { Preconditions.checkArgument(graph != null); Preconditions.checkArgument(matchingAlgorithm != null); final ConnectivityInterface<T> feature = graph.fetch(ConnectivityFeature.class).up(); Preconditions.checkState(feature.isConnected(), "Graph must be connected."); return new ClosedCPP<T>(graph, matchingAlgorithm); }
From source file:org.locationtech.geogig.plumbing.TransactionResolve.java
/** * @return the resolved {@link GeogigTransaction}, or {@link Optional#absent()} if it could not * be resolved/*from w w w . j ava 2s . com*/ */ @Override protected Optional<GeogigTransaction> _call() { Preconditions.checkState(!(context instanceof GeogigTransaction), "Cannot resolve a transaction within a transaction!"); Preconditions.checkArgument(id != null, "No id was specified to resolve!"); final String transactionNamespace = TransactionRefDatabase.buildTransactionNamespace(id); GeogigTransaction transaction = null; if (!context.refDatabase().getAll(transactionNamespace).isEmpty()) { transaction = new GeogigTransaction(context, id); } return Optional.fromNullable(transaction); }
From source file:com.talvish.tales.services.http.servlets.AdministrationServlet.java
/** * Override for initialization to ensure we have a service. *///from w w w . j a v a 2 s. c o m @Override public void init() throws ServletException { super.init(); service = (Service) this.getServletContext().getAttribute(AttributeConstants.SERVICE_SERVLET_CONTEXT); Preconditions.checkState(getService() != null, "Must have a service to use administrative servlets."); }
From source file:org.apache.tez.mapreduce.examples.helpers.SplitsInClientOptionParser.java
public String[] getRemainingArgs() { Preconditions.checkState(parsed, "Cannot get remaining args without parsing"); return otherArgs.clone(); }
From source file:name.marcelomorales.siqisiqi.openjpa.guice.EntityManagerProvider.java
public EntityManager get() { if (!isWorking()) { begin();//w w w . j av a 2 s . c o m } EntityManager em = entityManager.get(); Preconditions.checkState(null != em, "Requested EntityManager outside work unit."); return em; }
From source file:com.google.enterprise.adaptor.secmgr.saml.GroupImpl.java
@Override public String getNamespace() { Preconditions.checkState(namespace != null, "Namespace must be non-null"); return namespace; }
From source file:org.geogit.api.plumbing.RebuildGraphOp.java
/** * Executes the {@code RebuildGraphOp} operation. * // ww w . j a v a2s .c o m * @return a list of {@link ObjectId}s that were found to be missing or incomplete */ @Override public ImmutableList<ObjectId> call() { Preconditions.checkState(!repository.isSparse(), "Cannot rebuild the graph of a sparse repository."); List<ObjectId> updated = new LinkedList<ObjectId>(); ImmutableList<Ref> branches = command(BranchListOp.class).setLocal(true).setRemotes(true).call(); GraphDatabase graphDb = repository.getGraphDatabase(); for (Ref ref : branches) { Iterator<RevCommit> commits = command(LogOp.class).setUntil(ref.getObjectId()).call(); while (commits.hasNext()) { RevCommit next = commits.next(); if (graphDb.put(next.getId(), next.getParentIds())) { updated.add(next.getId()); } } } return ImmutableList.copyOf(updated); }
From source file:com.github.jcustenborder.kafka.connect.cdc.docker.DockerExtension.java
public static DockerCompose findDockerComposeAnnotation(ExtensionContext extensionContext) { Class<?> testClass = extensionContext.getTestClass().get(); log.trace("Looking for DockerCompose extension on {}", testClass.getName()); DockerCompose dockerCompose = testClass.getAnnotation(DockerCompose.class); Preconditions.checkNotNull(dockerCompose, "DockerCompose annotation not found on %s", testClass.getName()); Preconditions.checkState(!Strings.isNullOrEmpty(dockerCompose.dockerComposePath()), "dockerCompose.dockerComposePath() cannot be null or empty."); Preconditions.checkState(!Strings.isNullOrEmpty(dockerCompose.logPath()), "dockerCompose.logPath() cannot be null or empty."); return dockerCompose; }
From source file:com.turn.griffin.utils.GriffinConsumer.java
public GriffinConsumer(String zkPath, String groupId, String topicRegEx, int consolidationThreadCount, Properties props, BlockingQueue<byte[]> msgQueue) { Preconditions.checkState(!StringUtils.isBlank(zkPath), "Zookeeper path is not defined"); Preconditions.checkState(!StringUtils.isBlank(groupId), "Group id is not defined"); Preconditions.checkState(!StringUtils.isBlank(topicRegEx), "Topic is not defined"); Preconditions.checkNotNull(msgQueue); this.zkPath = zkPath; this.groupId = groupId; this.consumer = kafka.consumer.Consumer .createJavaConsumerConnector(createConsumerConfig(this.zkPath, this.groupId, props)); Preconditions.checkNotNull(this.consumer); this.topicRegEx = topicRegEx; this.msgQueue = msgQueue; this.run(consolidationThreadCount); }
From source file:org.apache.druid.sql.calcite.rel.DruidUnionRel.java
public static DruidUnionRel create(final QueryMaker queryMaker, final RelDataType rowType, final List<RelNode> rels, final int limit) { Preconditions.checkState(rels.size() > 0, "rels must be nonempty"); return new DruidUnionRel(rels.get(0).getCluster(), rels.get(0).getTraitSet(), queryMaker, rowType, new ArrayList<>(rels), limit); }