org.apache.commons.lang.Validate类的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(205)

本文整理了Java中org.apache.commons.lang.Validate类的一些代码示例,展示了Validate类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Validate类的具体详情如下:
包路径:org.apache.commons.lang.Validate
类名称:Validate

Validate介绍

[英]This class assists in validating arguments.

The class is based along the lines of JUnit. If an argument value is deemed invalid, an IllegalArgumentException is thrown. For example:

Validate.isTrue( i > 0, "The value must be greater than zero: ", i); 
Validate.notNull( surname, "The surname must not be null");

[中]此类帮助验证参数。
这个类是基于JUnit的。如果参数值被视为无效,则抛出IllegalArgumentException。例如:

Validate.isTrue( i > 0, "The value must be greater than zero: ", i); 
Validate.notNull( surname, "The surname must not be null");

代码示例

代码示例来源:origin: Bukkit/Bukkit

@Override
  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    return ImmutableList.of();
  }
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Create a new potion of the given type and level.
 *
 * @param type The type of potion.
 * @param level The potion's level.
 */
public Potion(PotionType type, int level) {
  this(type);
  Validate.notNull(type, "Type cannot be null");
  Validate.isTrue(type != PotionType.WATER, "Water bottles don't have a level!");
  Validate.isTrue(level > 0 && level < 3, "Level must be 1 or 2");
  this.level = level;
}

代码示例来源:origin: apache/storm

public AbstractHBaseBolt(String tableName, HBaseMapper mapper) {
  Validate.notEmpty(tableName, "Table name can not be blank or null");
  Validate.notNull(mapper, "mapper can not be null");
  this.tableName = tableName;
  this.mapper = mapper;
}

代码示例来源:origin: citerus/dddsample-core

/**
 * Constructor.
 *
 * @param legs List of legs for this itinerary.
 */
public Itinerary(final List<Leg> legs) {
 Validate.notEmpty(legs);
 Validate.noNullElements(legs);
 this.legs = legs;
}

代码示例来源:origin: citerus/dddsample-core

Schedule(final List<CarrierMovement> carrierMovements) {
 Validate.notNull(carrierMovements);
 Validate.noNullElements(carrierMovements);
 Validate.notEmpty(carrierMovements);
 this.carrierMovements = carrierMovements;
}

代码示例来源:origin: Alluxio/alluxio

/**
 * Prefix list is used to do file filtering.
 *
 * @param prefixes the prefixes with separators
 * @param separator the separator to split the prefixes
 */
public PrefixList(String prefixes, String separator) {
 Validate.notNull(separator);
 List<String> prefixList = new ArrayList<>(0);
 if (prefixes != null && !prefixes.trim().isEmpty()) {
  String[] candidates = prefixes.trim().split(separator);
  for (String prefix : candidates) {
   String trimmed = prefix.trim();
   if (!trimmed.isEmpty()) {
    prefixList.add(trimmed);
   }
  }
 }
 mInnerList = ImmutableList.copyOf(prefixList);
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Add a fade color to the firework effect.
 *
 * @param color The color to add
 * @return This object, for chaining
 * @throws IllegalArgumentException If colors is null
 * @throws IllegalArgumentException If any color is null (may be
 *     thrown after changes have occurred)
 */
public Builder withFade(Color color) throws IllegalArgumentException {
  Validate.notNull(color, "Cannot have null color");
  if (fadeColors == null) {
    fadeColors = ImmutableList.builder();
  }
  fadeColors.add(color);
  return this;
}

代码示例来源:origin: apache/storm

public JdbcLookupBolt(ConnectionProvider connectionProvider, String selectQuery, JdbcLookupMapper jdbcLookupMapper) {
  super(connectionProvider);
  Validate.notNull(selectQuery);
  Validate.notNull(jdbcLookupMapper);
  this.selectQuery = selectQuery;
  this.jdbcLookupMapper = jdbcLookupMapper;
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Creates a new note.
 *
 * @param note Internal note id. {@link #getId()} always return this
 *     value. The value has to be in the interval [0;&nbsp;24].
 */
public Note(int note) {
  Validate.isTrue(note >= 0 && note <= 24, "The note value has to be between 0 and 24.");
  this.note = (byte) note;
}

代码示例来源:origin: apache/storm

/**
 * AbstractMongoBolt Constructor.
 * @param url The MongoDB server url
 * @param collectionName The collection where reading/writing data
 */
public AbstractMongoBolt(String url, String collectionName) {
  Validate.notEmpty(url, "url can not be blank or null");
  Validate.notEmpty(collectionName, "collectionName can not be blank or null");
  this.url = url;
  this.collectionName = collectionName;
}

代码示例来源:origin: Bukkit/Bukkit

public EntityDamageEvent(final Entity damagee, final DamageCause cause, final Map<DamageModifier, Double> modifiers, final Map<DamageModifier, ? extends Function<? super Double, Double>> modifierFunctions) {
  super(damagee);
  Validate.isTrue(modifiers.containsKey(DamageModifier.BASE), "BASE DamageModifier missing");
  Validate.isTrue(!modifiers.containsKey(null), "Cannot have null DamageModifier");
  Validate.noNullElements(modifiers.values(), "Cannot have null modifier values");
  Validate.isTrue(modifiers.keySet().equals(modifierFunctions.keySet()), "Must have a modifier function for each DamageModifier");
  Validate.noNullElements(modifierFunctions.values(), "Cannot have null modifier function");
  this.originals = new EnumMap<DamageModifier, Double>(modifiers);
  this.cause = cause;
  this.modifiers = modifiers;
  this.modifierFunctions = modifierFunctions;
}

代码示例来源:origin: citerus/dddsample-core

public Leg(Voyage voyage, Location loadLocation, Location unloadLocation, Date loadTime, Date unloadTime) {
 Validate.noNullElements(new Object[] {voyage, loadLocation, unloadLocation, loadTime, unloadTime});
 
 this.voyage = voyage;
 this.loadLocation = loadLocation;
 this.unloadLocation = unloadLocation;
 this.loadTime = loadTime;
 this.unloadTime = unloadTime;
}

代码示例来源:origin: apache/storm

public HBaseLookupBolt(String tableName, HBaseMapper mapper, HBaseValueMapper rowToTupleMapper) {
  super(tableName, mapper);
  Validate.notNull(rowToTupleMapper, "rowToTupleMapper can not be null");
  this.rowToTupleMapper = rowToTupleMapper;
}

代码示例来源:origin: Bukkit/Bukkit

private Color(int red, int green, int blue) {
  Validate.isTrue(red >= 0 && red <= BIT_MASK, "Red is not between 0-255: ", red);
  Validate.isTrue(green >= 0 && green <= BIT_MASK, "Green is not between 0-255: ", green);
  Validate.isTrue(blue >= 0 && blue <= BIT_MASK, "Blue is not between 0-255: ", blue);
  this.red = (byte) red;
  this.green = (byte) green;
  this.blue = (byte) blue;
}

代码示例来源:origin: commons-lang/commons-lang

/**
 * <p>Validate that the specified argument collection is neither <code>null</code> 
 * nor a size of zero (no elements); otherwise throwing an exception. 
 *
 * <pre>Validate.notEmpty(myCollection);</pre>
 * 
 * <p>The message in the exception is &quot;The validated collection is 
 * empty&quot;.</p>
 * 
 * @param collection the collection to check
 * @throws IllegalArgumentException if the collection is empty
 */
public static void notEmpty(Collection collection) {
  notEmpty(collection, "The validated collection is empty");
}

代码示例来源:origin: citerus/dddsample-core

/**
 * Constructor.
 *
 * @param departureLocation location of departure
 * @param arrivalLocation location of arrival
 * @param departureTime time of departure
 * @param arrivalTime time of arrival
 */
// TODO make package local
public CarrierMovement(Location departureLocation,
            Location arrivalLocation,
            Date departureTime,
            Date arrivalTime) {
 Validate.noNullElements(new Object[]{departureLocation, arrivalLocation, departureTime, arrivalTime});
 this.departureTime = departureTime;
 this.arrivalTime = arrivalTime;
 this.departureLocation = departureLocation;
 this.arrivalLocation = arrivalLocation;
}

代码示例来源:origin: Bukkit/Bukkit

@Override
  public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    return ImmutableList.of();
  }
}

代码示例来源:origin: Bukkit/Bukkit

/**
 * Gets the color represented by the specified color code
 *
 * @param code Code to check
 * @return Associative {@link org.bukkit.ChatColor} with the given code,
 *     or null if it doesn't exist
 */
public static ChatColor getByChar(String code) {
  Validate.notNull(code, "Code cannot be null");
  Validate.isTrue(code.length() > 0, "Code must have at least one char");
  return BY_CHAR.get(code.charAt(0));
}

代码示例来源:origin: apache/storm

protected MongoMapState(Map<String, Object> map, Options options) {
  this.options = options;
  this.map = map;
  this.serializer = options.serializer;
  Validate.notEmpty(options.url, "url can not be blank or null");
  Validate.notEmpty(options.collectionName, "collectionName can not be blank or null");
  Validate.notNull(options.queryCreator, "queryCreator can not be null");
  Validate.notNull(options.mapper, "mapper can not be null");
  this.mongoClient = new MongoDbClient(options.url, options.collectionName);
}

代码示例来源:origin: apache/storm

/**
 * MongoInsertBolt Constructor.
 * @param url The MongoDB server url
 * @param collectionName The collection where reading/writing data
 * @param mapper MongoMapper converting tuple to an MongoDB document
 */
public MongoInsertBolt(String url, String collectionName, MongoMapper mapper) {
  super(url, collectionName);
  Validate.notNull(mapper, "MongoMapper can not be null");
  this.mapper = mapper;
}

相关文章

微信公众号

最新文章

更多