Example usage for org.apache.commons.lang3 Validate validState

List of usage examples for org.apache.commons.lang3 Validate validState

Introduction

In this page you can find the example usage for org.apache.commons.lang3 Validate validState.

Prototype

public static void validState(final boolean expression, final String message, final Object... values) 

Source Link

Document

Validate that the stateful condition is true ; otherwise throwing an exception with the specified message.

Usage

From source file:de.vandermeer.skb.datatool.backend.BackendLatexAcrLog.java

/**
 * Creates a new backend./*from   ww  w  . j  a  va2  s.c  o m*/
 * @param fileName file name of the LaTeX log file to read
 * @throws IllegalArgumentException if any required argument is not valid
 */
public BackendLatexAcrLog(String fileName) {
    Validate.notBlank(fileName, "input file cannot be null");

    this.file = new File(fileName);
    Validate.validState(file.exists(), "input file <%s> does not exist", fileName);
    Validate.validState(file.canRead(), "input file <%s> not readable", fileName);

    this.fileName = fileName;
    this.acronymsLog = new TreeSet<>();
}

From source file:de.vandermeer.skb.datatool.backend.BackendLoader.java

/**
 * Sets the entry type/* w  ww. ja v a  2  s .  co m*/
 * @param type actual antry type
 * @throws IllegalArgumentException if any required argument is not valid
 */
public void setType(DataEntryType type) {
    Validate.notNull(type, "data entry type cannot be null");
    Validate.validState(this.tlMap.getMap().containsKey(type), "unsupported type <%s>", type.getType());
    this.type = type;
}

From source file:py.una.pol.karaku.dao.entity.interceptors.UriInterceptor.java

private String bySequence(Field f, URI uri) {

    Validate.validState(StringUtils.isValid(uri.sequenceName()),
            "URI with type Sequence without sequence name %s", f.getName());

    return getNextSequence(uri.sequenceName());
}

From source file:ru.mystamps.web.dao.impl.JdbcCategoryDao.java

@Override
public Integer add(AddCategoryDbDto category) {
    Map<String, Object> params = new HashMap<>();
    params.put("name", category.getName());
    params.put("name_ru", category.getNameRu());
    params.put("slug", category.getSlug());
    params.put("created_at", category.getCreatedAt());
    params.put("created_by", category.getCreatedBy());
    params.put("updated_at", category.getUpdatedAt());
    params.put("updated_by", category.getUpdatedBy());

    KeyHolder holder = new GeneratedKeyHolder();

    int affected = jdbcTemplate.update(addCategorySql, new MapSqlParameterSource(params), holder);

    Validate.validState(affected == 1, "Unexpected number of affected rows after creation of category: %d",
            affected);//w  w  w. j  a  v  a  2s .c  om

    return Integer.valueOf(holder.getKey().intValue());
}

From source file:ru.mystamps.web.dao.impl.JdbcCollectionDao.java

/**
 * @author John Shkarin//from w  w  w. ja v  a2 s  .c  om
 * @author Slava Semushin
 */
@Override
public void markAsModified(Integer userId, Date updatedAt) {
    Map<String, Object> params = new HashMap<>();
    params.put("user_id", userId);
    params.put("updated_at", updatedAt);
    params.put("updated_by", userId);

    int affected = jdbcTemplate.update(markAsModifiedSql, params);

    Validate.validState(affected == 1, "Unexpected number of affected rows after updating collection: %d",
            affected);
}

From source file:ru.mystamps.web.dao.impl.JdbcCountryDao.java

@Override
public Integer add(AddCountryDbDto country) {
    Map<String, Object> params = new HashMap<>();
    params.put("name", country.getName());
    params.put("name_ru", country.getNameRu());
    params.put("slug", country.getSlug());
    params.put("created_at", country.getCreatedAt());
    params.put("created_by", country.getCreatedBy());
    params.put("updated_at", country.getUpdatedAt());
    params.put("updated_by", country.getUpdatedBy());

    KeyHolder holder = new GeneratedKeyHolder();

    int affected = jdbcTemplate.update(addCountrySql, new MapSqlParameterSource(params), holder);

    Validate.validState(affected == 1, "Unexpected number of affected rows after creation of country: %d",
            affected);//from  www  . ja  v  a  2 s  .com

    return Integer.valueOf(holder.getKey().intValue());
}

From source file:ru.mystamps.web.dao.impl.JdbcImageDao.java

@Override
public Integer add(String type) {
    KeyHolder holder = new GeneratedKeyHolder();

    int affected = jdbcTemplate.update(addImageSql,
            new MapSqlParameterSource(Collections.singletonMap("type", type)), holder);

    Validate.validState(affected == 1, "Unexpected number of affected rows after adding image: %d", affected);

    return Integer.valueOf(holder.getKey().intValue());
}

From source file:ru.mystamps.web.dao.impl.JdbcImageDataDao.java

@Override
public Integer add(AddImageDataDbDto imageData) {
    Map<String, Object> params = new HashMap<>();
    params.put("image_id", imageData.getImageId());
    params.put("content", imageData.getContent());

    KeyHolder holder = new GeneratedKeyHolder();

    int affected = jdbcTemplate.update(addImageDataSql, new MapSqlParameterSource(params), holder);

    Validate.validState(affected == 1, "Unexpected number of affected rows after creation of image's data: %d",
            affected);/*ww w  .  j  ava  2  s.c o m*/

    return Integer.valueOf(holder.getKey().intValue());
}

From source file:ru.mystamps.web.dao.impl.JdbcSeriesDao.java

@Override
public Integer add(AddSeriesDbDto series) {
    Map<String, Object> params = new HashMap<>();
    params.put("category_id", series.getCategoryId());
    params.put("country_id", series.getCountryId());
    params.put("quantity", series.getQuantity());
    params.put("perforated", series.getPerforated());
    params.put("release_day", series.getReleaseDay());
    params.put("release_month", series.getReleaseMonth());
    params.put("release_year", series.getReleaseYear());
    params.put("michel_price", series.getMichelPrice());
    params.put("michel_currency", series.getMichelCurrency());
    params.put("scott_price", series.getScottPrice());
    params.put("scott_currency", series.getScottCurrency());
    params.put("yvert_price", series.getYvertPrice());
    params.put("yvert_currency", series.getYvertCurrency());
    params.put("gibbons_price", series.getGibbonsPrice());
    params.put("gibbons_currency", series.getGibbonsCurrency());
    params.put("comment", series.getComment());
    params.put("created_at", series.getCreatedAt());
    params.put("created_by", series.getCreatedBy());
    params.put("updated_at", series.getUpdatedAt());
    params.put("updated_by", series.getUpdatedBy());

    KeyHolder holder = new GeneratedKeyHolder();

    int affected = jdbcTemplate.update(createSeriesSql, new MapSqlParameterSource(params), holder);

    Validate.validState(affected == 1, "Unexpected number of affected rows after creation of series: %d",
            affected);/* w w w  .j  ava2 s .c  o m*/

    return Integer.valueOf(holder.getKey().intValue());
}

From source file:ru.mystamps.web.dao.impl.JdbcSeriesDao.java

/**
 * @author Sergey Chechenev/*from w w w. j  a  va  2  s .c  o  m*/
 */
@Override
public void markAsModified(Integer seriesId, Date updatedAt, Integer updatedBy) {
    Map<String, Object> params = new HashMap<>();
    params.put("series_id", seriesId);
    params.put("updated_at", updatedAt);
    params.put("updated_by", updatedBy);

    int affected = jdbcTemplate.update(markAsModifiedSql, params);

    Validate.validState(affected == 1, "Unexpected number of affected rows after updating series: %d",
            affected);
}