List of usage examples for com.google.common.base Preconditions checkState
public static void checkState(boolean expression, @Nullable Object errorMessage)
From source file:eu.lp0.cursus.db.DatabaseSession.java
void startSession() { Preconditions.checkState(THREADS.get() == null, "Session already open"); //$NON-NLS-1$ synchronized (this) { Preconditions.checkState(emf.isOpen(), "Factory not open"); //$NON-NLS-1$ openCount++;/*from w w w. j a va2 s . com*/ } THREADS.set(emf.createEntityManager()); }
From source file:org.opendaylight.controller.config.manager.impl.osgi.mapping.BindingContextProvider.java
public synchronized BindingRuntimeContext getBindingContext() { Preconditions.checkState(this.current != null, "Binding context not yet initialized"); return this.current; }
From source file:annis.gui.converter.TreeSetConverter.java
@Override public TreeSet convertToModel(Object value, Class<? extends TreeSet> targetType, Locale locale) throws ConversionException { TreeSet result = new TreeSet(CaseSensitiveOrder.INSTANCE); if (value instanceof Collection) { result.addAll((Collection) value); Preconditions.checkState(result.size() == ((Collection) value).size(), "Collection which was used with the TreeSetConverter had duplicate entries."); } else {//from w w w. j a v a 2 s. c o m result.add(value); } return result; }
From source file:org.opendaylight.controller.cluster.datastore.TransactionRateLimitingCallback.java
@Override public void run() { Preconditions.checkState(state == State.STOPPED, "state is not STOPPED"); resume(); }
From source file:co.mitro.core.server.data.RPCLogger.java
public static synchronized void startLoggingWithPrefix(String prefix) throws IOException { Preconditions.checkNotNull(prefix);/*www . j a va 2 s . c o m*/ Preconditions.checkState(RPCLogger.prefix == null, "RPCLogger already started"); RPCLogger.prefix = prefix; // this thread runs as a daemon, so it doesn't stop the JVM from exiting rotator = new Timer(true); // run the log cycler immediately so that it can create the 1st log file. rotator.schedule(new LogRotator(), 0, TimeUnit.HOURS.toMillis(LOG_TIME_HOURS)); }
From source file:com.github.jcustenborder.kafka.connect.utils.config.recommenders.EnumRecommender.java
EnumRecommender(Class<?> enumClass, VisibleCallback visible, String... excludes) { Preconditions.checkNotNull(enumClass, "enumClass cannot be null"); Preconditions.checkState(enumClass.isEnum(), "enumClass must be an enum."); Preconditions.checkNotNull(visible, "visible cannot be null"); this.enumClass = enumClass; this.visible = visible; Set<String> validEnums = new LinkedHashSet<>(); for (Object o : enumClass.getEnumConstants()) { String key = o.toString(); validEnums.add(key);//from ww w . j av a 2 s.c o m } validEnums.removeAll(Arrays.asList(excludes)); this.validEnums = ImmutableSet.copyOf(validEnums); }
From source file:org.apache.flume.source.AbstractSource.java
@Override public synchronized void start() { Preconditions.checkState(channelProcessor != null, "No channel processor configured"); lifecycleState = LifecycleState.START; }
From source file:com.google.template.soy.jssrc.dsl.SwitchBuilder.java
/** * Adds a case clause (one or more {@code case} labels followed by a body) to this switch * statement./*from www . j av a 2 s .co m*/ */ public SwitchBuilder case_(ImmutableList<CodeChunk.WithValue> caseLabels, CodeChunk body) { Preconditions.checkState(!caseLabels.isEmpty(), "at least one case required"); clauses.add(new Switch.CaseClause(caseLabels, body)); return this; }
From source file:com.netflix.paas.cassandra.keys.KeyspaceKey.java
public KeyspaceKey(String schemaName) { String parts[] = StringUtils.split(schemaName, "."); Preconditions.checkState(parts.length == 2, String.format("Schema name must have format <cluster>.<keyspace> ('%s')", schemaName)); this.clusterKey = new ClusterKey(parts[0], null); // TODO this.keyspaceName = parts[1]; this.schemaName = schemaName; }
From source file:model.utilities.stats.collectors.SalesData.java
/** * called when the data gathering is supposed to start. It schedules itself to start at next CLEANUP phase *//*from w w w .j av a2s . c om*/ public void start(MacroII state, SalesDepartment departmentToFollow) { if (!isActive()) return; Preconditions.checkState(this.departmentToFollow == null, " can't start the gatherer twice!"); //schedule yourself this.departmentToFollow = departmentToFollow; //we are going to set the starting day at -1 and then change it at our first step() setStartingDay(-1); state.scheduleSoon(ActionOrder.CLEANUP_DATA_GATHERING, this); }