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) 

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.netconf.util.NetconfUtil.java

public static Document checkIsMessageOk(Document response) throws DocumentedException {
    XmlElement element = XmlElement.fromDomDocument(response);
    Preconditions.checkState(element.getName().equals(XmlMappingConstants.RPC_REPLY_KEY));
    element = element.getOnlyChildElement();
    if (element.getName().equals(XmlNetconfConstants.OK)) {
        return response;
    }//  w w  w .  ja  v  a 2  s .c o m
    LOG.warn("Can not load last configuration. Operation failed.");
    throw new IllegalStateException(
            "Can not load last configuration. Operation failed: " + XmlUtil.toString(response));
}

From source file:model.utilities.scheduler.FutureAction.java

/**
 * Decrease days away by 1//from w ww  . j ava2  s  .  co  m
 * @return true if days away are 0
 */
public boolean spendOneDay() {
    daysAway--;
    Preconditions.checkState(daysAway >= 0);
    return daysAway == 0;

}

From source file:google.registry.flows.contact.ContactFlowUtils.java

/** Check that an internationalized postal info has only ascii characters. */
static void validateAsciiPostalInfo(@Nullable PostalInfo internationalized) throws EppException {
    if (internationalized != null) {
        Preconditions.checkState(INTERNATIONALIZED.equals(internationalized.getType()));
        ContactAddress address = internationalized.getAddress();
        Set<String> fields = Sets.newHashSet(internationalized.getName(), internationalized.getOrg(),
                address.getCity(), address.getCountryCode(), address.getState(), address.getZip());
        fields.addAll(address.getStreet());
        for (String field : fields) {
            if (field != null && !CharMatcher.ascii().matchesAllOf(field)) {
                throw new BadInternationalizedPostalInfoException();
            }//from  ww  w  .j  av a2  s .com
        }
    }
}

From source file:org.opendaylight.protocol.bgp.openconfig.spi.AbstractBGPTableTypeRegistryProviderActivator.java

@Override
public final synchronized void startBGPTableTypeRegistryProvider(final BGPTableTypeRegistryProvider provider) {
    Preconditions.checkState(this.registrations == null);
    this.registrations = Preconditions.checkNotNull(startBGPTableTypeRegistryProviderImpl(provider));
}

From source file:org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator.java

@Override
public final synchronized void start(final BGPExtensionProviderContext context) {
    Preconditions.checkState(this.registrations == null);

    this.registrations = Preconditions.checkNotNull(startImpl(context));
}

From source file:com.facebook.buck.rules.modern.CustomBehaviorUtils.java

/** Returns the class behavior of the requested type (if there is one). */
public static <C extends CustomClassBehaviorTag> Optional<CustomClassBehaviorTag> getBehavior(Class<?> clazz,
        Class<C> behaviorClass) {
    CustomClassBehavior behavior = clazz.getAnnotation(CustomClassBehavior.class);
    if (behavior == null) {
        return Optional.empty();
    }/* ww  w.j  av a  2s.  c  o m*/

    List<Class<? extends CustomClassBehaviorTag>> matches = RichStream.from(behavior.value())
            .filter(behaviorClass::isAssignableFrom).collect(Collectors.toList());
    if (matches.isEmpty()) {
        return Optional.empty();
    }
    Preconditions.checkState(matches.size() == 1);
    Class<? extends CustomClassBehaviorTag> tag = matches.get(0);

    try {
        Constructor<? extends CustomClassBehaviorTag> constructor = tag.getDeclaredConstructor();
        constructor.setAccessible(true);
        return Optional.of(constructor.newInstance());
    } catch (NoSuchMethodException | IllegalAccessException | InstantiationException
            | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.opendaylight.protocol.rsvp.parser.spi.AbstractRSVPExtensionProviderActivator.java

@Override
public final synchronized void start(final RSVPExtensionProviderContext context) {
    Preconditions.checkState(this.registrations == null);

    this.registrations = Preconditions.checkNotNull(startImpl(context));
}

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

@Override
protected Optional<RevCommit> _call() {
    Preconditions.checkState(date != null);
    long time = date.getTime();
    Iterator<RevCommit> iter = command(LogOp.class).setFirstParentOnly(true).call();
    while (iter.hasNext()) {
        RevCommit commit = iter.next();//ww  w.  j  a  v  a2 s  . co  m
        if (commit.getCommitter().getTimestamp() < time) {
            return Optional.of(commit);
        }
    }
    return Optional.absent();
}

From source file:model.utilities.DelayBin.java

public DelayBin(int size, N defaultValue) {
    Preconditions.checkState(size >= 0);
    this.size = size;
    this.defaultValue = defaultValue;
    bin = new LinkedList<>();
}

From source file:com.linkedin.pinot.core.io.util.FixedBitIntReaderWriter.java

public FixedBitIntReaderWriter(PinotDataBuffer dataBuffer, int numValues, int numBitsPerValue) {
    Preconditions.checkState(
            dataBuffer.size() == (int) (((long) numValues * numBitsPerValue + Byte.SIZE - 1) / Byte.SIZE));
    _dataBitSet = new PinotDataBitSet(dataBuffer);
    _numBitsPerValue = numBitsPerValue;/*w w  w .j a  v a  2s .c  o  m*/
}