Example usage for org.springframework.util Assert isTrue

List of usage examples for org.springframework.util Assert isTrue

Introduction

In this page you can find the example usage for org.springframework.util Assert isTrue.

Prototype

public static void isTrue(boolean expression, Supplier<String> messageSupplier) 

Source Link

Document

Assert a boolean expression, throwing an IllegalArgumentException if the expression evaluates to false .

Usage

From source file:org.spring.data.gemfire.config.DiskStoreBeanPostProcessor.java

private void createIfNotExists(final DiskDir diskDirectory) {
    String location = readField(diskDirectory, "location");
    File diskDirectoryFile = new File(location);

    Assert.isTrue(diskDirectoryFile.isDirectory() || diskDirectoryFile.mkdirs(),
            String.format("Failed to create Disk Directory (%1$s)%n!", location));

    System.out.printf("The Disk Directory exists @ Location (%1$s).%n", location);
}

From source file:com.baidu.fsg.uid.BitsAllocator.java

/**
 * Constructor with timestampBits, workerIdBits, sequenceBits<br>
 * The highest bit used for sign, so <code>63</code> bits for timestampBits, workerIdBits, sequenceBits
 *///from  ww  w .j  a  va 2 s.  co  m
public BitsAllocator(int timestampBits, int workerIdBits, int sequenceBits) {
    // make sure allocated 64 bits
    int allocateTotalBits = signBits + timestampBits + workerIdBits + sequenceBits;
    Assert.isTrue(allocateTotalBits == TOTAL_BITS, "allocate not enough 64 bits");

    // initialize bits
    this.timestampBits = timestampBits;
    this.workerIdBits = workerIdBits;
    this.sequenceBits = sequenceBits;

    // initialize max value
    this.maxDeltaSeconds = ~(-1L << timestampBits);
    this.maxWorkerId = ~(-1L << workerIdBits);
    this.maxSequence = ~(-1L << sequenceBits);

    // initialize shift
    this.timestampShift = workerIdBits + sequenceBits;
    this.workerIdShift = sequenceBits;
}

From source file:sample.mybatis.conf.DatabaseDriver.java

/**
 * Find a {@link DatabaseDriver} for the given URL.
 * @param url JDBC URL/*from   www . j av a2  s.  com*/
 * @return driver class name or {@link #UNKNOWN} if not found
 */
public static DatabaseDriver fromJdbcUrl(String url) {
    if (StringUtils.hasLength(url)) {
        Assert.isTrue(url.startsWith("jdbc"), "URL must start with 'jdbc'");
        String urlWithoutPrefix = url.substring("jdbc".length()).toLowerCase();
        for (DatabaseDriver driver : values()) {
            String prefix = ":" + driver.name().toLowerCase() + ":";
            if (driver != UNKNOWN && urlWithoutPrefix.startsWith(prefix)) {
                return driver;
            }
        }
    }
    return UNKNOWN;
}

From source file:cn.edu.ahpu.common.dao.key.impl.DefaultUniqueTableApp.java

public CacheValue getCacheValue(int cacheNum, String name) {
    Assert.isTrue(TransactionSynchronizationManager.isSynchronizationActive(), "Transaction must be running");

    CacheValue cache = null;/* w  ww. j  ava  2s. co m*/
    try {
        cache = getCurrCode(name);

        if (cache == null) {
            insert(name);
            cache = getCurrCode(name);
        }

        update(cacheNum, name);
        cache.setMaxVal(cache.getMinVal() + cacheNum);
    } catch (Exception e) {
        logger.error("?", e);
    }
    return cache;
}

From source file:org.broadleafcommerce.payment.service.gateway.PayPalExpressReportingServiceImpl.java

@Override
public PaymentResponseDTO findDetailsByTransaction(PaymentRequestDTO paymentRequestDTO)
        throws PaymentException {
    Assert.isTrue(paymentRequestDTO.getAdditionalFields().containsKey(MessageConstants.TOKEN),
            "The RequestDTO must contain a TOKEN");

    PayPalDetailsRequest detailsRequest = new PayPalDetailsRequest();
    detailsRequest.setMethodType(PayPalMethodType.DETAILS);
    detailsRequest.setToken((String) paymentRequestDTO.getAdditionalFields().get(MessageConstants.TOKEN));

    PayPalDetailsResponse response = (PayPalDetailsResponse) process(detailsRequest);
    PaymentResponseDTO responseDTO = new PaymentResponseDTO(PaymentType.THIRD_PARTY_ACCOUNT,
            PayPalExpressPaymentGatewayType.PAYPAL_EXPRESS);
    setCommonDetailsResponse(response, responseDTO);
    return responseDTO;
}

From source file:xolpoc.core.ModuleRunner.java

private ModuleDescriptor descriptorFor(String moduleDefinition, Properties options) {
    String[] tokens = moduleDefinition.split("\\.");
    Assert.isTrue(tokens.length == 4,
            "required module property format: streamname.moduletype.modulename.moduleindex");
    String streamName = tokens[0];
    ModuleType moduleType = ModuleType.valueOf(tokens[1]);
    String moduleName = tokens[2];
    int moduleIndex = Integer.parseInt(tokens[3]);

    ModuleDefinition definition = registry.findDefinition(moduleName, moduleType);

    ModuleDescriptor.Builder builder = new ModuleDescriptor.Builder().setModuleDefinition(definition)
            .setModuleName(moduleName).setType(moduleType).setGroup(streamName).setIndex(moduleIndex);
    builder.setSourceChannelName(input);
    builder.setSinkChannelName(output);/*from  www.  ja v  a  2 s .  c  o  m*/
    for (String key : options.stringPropertyNames()) {
        builder.setParameter(key, options.getProperty(key));
    }
    return builder.build();
}

From source file:com.gdn.iam.spring.security.IamUserDetails.java

public IamUserDetails(String[] attributes) {
    Assert.notNull(attributes, "attributes cannot be null.");
    Assert.isTrue(attributes.length > 0, "At least one attribute is required to retrieve roles from.");
    this.attributes = attributes;
    try {//from ww  w .j a  va  2  s .co m
        context = JAXBContext.newInstance(Session.class);
    } catch (JAXBException e) {
        LOG.error("can not creating jaxb unmarshaller", e);
    }
}

From source file:com.oreilly.springdata.gemfire.core.Product.java

/**
 * Creates a new {@link Product} from the given name and description.
 * @param id a unique Id//  ww  w. j ava2 s. c  o m
 * @param name must not be {@literal null} or empty.
 * @param price must not be {@literal null} or less than or equal to zero.
 * @param description
 */
@PersistenceConstructor
public Product(Long id, String name, BigDecimal price, String description) {
    super(id);
    Assert.hasText(name, "Name must not be null or empty!");
    Assert.isTrue(BigDecimal.ZERO.compareTo(price) < 0, "Price must be greater than zero!");

    this.name = name;
    this.price = price;
    this.description = description;
}

From source file:de.extrastandard.persistence.model.ProcedureTypeIT.java

@Test
public void testIsProcedureEndPhase() {
    final Procedure procedureSendFetch = procedureRepository
            .findByName(PersistenceTestSetup.PROCEDURE_DATA_MATCH_NAME);
    Assert.notNull(procedureSendFetch,/* w  ww .  ja v a2 s. c o  m*/
            "Procedure not found: " + PersistenceTestSetup.PROCEDURE_DATA_MATCH_NAME);
    Assert.isTrue(procedureSendFetch.isProcedureEndPhase(PhaseQualifier.PHASE3.getName()),
            "Unexpected EndPhase.");
    Assert.isTrue(!procedureSendFetch.isProcedureEndPhase(PhaseQualifier.PHASE2.getName()),
            "Unexpected EndPhase.");
    Assert.isTrue(!procedureSendFetch.isProcedureEndPhase(PhaseQualifier.PHASE1.getName()),
            "Unexpected EndPhase.");
}

From source file:com.nestorledon.employeedirectory.rest.Resource.java

/**
 * Creates a new {@link Resource} with the given content and {@link Link}s.
 * //from  w w  w.j a  va2 s. c  om
 * @param content must not be {@literal null}.
 * @param links the links to add to the {@link Resource}.
 */
public Resource(T content, Iterable<Link> links) {

    Assert.notNull(content, "Content must not be null!");
    Assert.isTrue(!(content instanceof Collection), "Content must not be a collection! Use Resources instead!");
    this.content = content;
    this.add(links);
    this.page = null;
}