下面列出了org.apache.commons.lang.Validate#noNullElements ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* This method will add any given {@link ItemHandler} to this {@link SlimefunItem}.
* Note that this will not work after the {@link SlimefunItem} was registered.
*
* @param handlers
* Any {@link ItemHandler} that should be added to this {@link SlimefunItem}
*/
public final void addItemHandler(ItemHandler... handlers) {
Validate.notEmpty(handlers, "You cannot add zero handlers...");
Validate.noNullElements(handlers, "You cannot add any 'null' ItemHandler!");
if (state != ItemState.UNREGISTERED) {
throw new UnsupportedOperationException("You cannot add an ItemHandler after the SlimefunItem was registered.");
}
for (ItemHandler handler : handlers) {
itemhandlers.put(handler.getIdentifier(), handler);
// Tickers are a special case (at the moment at least)
if (handler instanceof BlockTicker) {
ticking = true;
SlimefunPlugin.getRegistry().getTickerBlocks().add(getID());
blockTicker = (BlockTicker) handler;
}
else if (handler instanceof GeneratorTicker) {
generatorTicker = (GeneratorTicker) handler;
}
}
}
/**
* This method will add any given {@link ItemSetting} to this {@link SlimefunItem}.
* Note that this will not work after the {@link SlimefunItem} was registered.
*
* @param settings
* Any {@link ItemSetting} that should be added to this {@link SlimefunItem}
*/
public final void addItemSetting(ItemSetting<?>... settings) {
Validate.notEmpty(settings, "You cannot add zero settings...");
Validate.noNullElements(settings, "You cannot add any 'null' ItemSettings!");
if (state != ItemState.UNREGISTERED) {
throw new UnsupportedOperationException("You cannot add an ItemSetting after the SlimefunItem was registered.");
}
for (ItemSetting<?> setting : settings) {
if (setting != null) {
// Prevent two Item Settings with the same key
for (ItemSetting<?> existingSetting : itemSettings) {
if (existingSetting.getKey().equals(setting.getKey())) {
throw new IllegalArgumentException("This Item has already an ItemSetting with this key: " + setting.getKey());
}
}
itemSettings.add(setting);
}
}
}
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
validVerifyType(verifyType);
Validate.notEmpty(schemaFile);
Validate.noNullElements(schemaFile);
this.verify = verifyType;
this.schemaFiles = schemaFile;
}
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
validVerifyType(verifyType);
Validate.notEmpty(schemaFile);
Validate.noNullElements(schemaFile);
this.verify = verifyType;
this.schemaFiles = schemaFile;
}
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
validVerifyType(verifyType);
Validate.notEmpty(schemaFile);
Validate.noNullElements(schemaFile);
this.verify = verifyType;
this.schemaFiles = schemaFile;
}
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
validVerifyType(verifyType);
Validate.notEmpty(schemaFile);
Validate.noNullElements(schemaFile);
this.verify = verifyType;
this.schemaFiles = schemaFile;
}
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
validVerifyType(verifyType);
Validate.notEmpty(schemaFile);
Validate.noNullElements(schemaFile);
this.verify = verifyType;
this.schemaFiles = schemaFile;
}
public List<MppPreview> getMedecinePackages(String searchString, String lang, List<String> types, int first, int count) {
try {
drugsDAO.openDataStoreSession();
Validate.noNullElements(new Object[]{searchString, lang});
log.debug("Asked language : " + lang);
lang = getAvailableLanguage(lang);
log.debug("Final language : " + lang);
List<Mpp> packages = drugsDAO.getMedecinePackages(searchString, lang, types, first, count);
return (List<MppPreview>) CollectionUtils.collect(packages, MPP_TO_MPPPREVIEW);
} finally {
drugsDAO.closeDataStoreSession();
}
}
public List<MppPreview> getMedecinePackagesFromIngredients(String searchString, String lang, List<String> types, int first, int count) {
try {
drugsDAO.openDataStoreSession();
Validate.noNullElements(new Object[]{searchString, lang});
log.debug("Asked language : " + lang);
lang = getAvailableLanguage(lang);
log.debug("Final language : " + lang);
List<Mpp> packages = drugsDAO.getMedecinePackagesFromIngredients(searchString, lang, types, first, count);
return (List<MppPreview>) CollectionUtils.collect(packages, MPP_TO_MPPPREVIEW);
} finally {
drugsDAO.closeDataStoreSession();
}
}
Schedule(final List<CarrierMovement> carrierMovements) {
Validate.notNull(carrierMovements);
Validate.noNullElements(carrierMovements);
Validate.notEmpty(carrierMovements);
this.carrierMovements = carrierMovements;
}
/**
* 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;
}
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;
}
/**
* Constructor.
*
* @param legs List of legs for this itinerary.
*/
public Itinerary(final List<Leg> legs) {
Validate.notEmpty(legs);
Validate.noNullElements(legs);
this.legs = legs;
}
public void pushAll(final Collection<Record> rs) {
Validate.notNull(rs);
Validate.noNullElements(rs);
this.doPushAll(rs);
this.statPush(rs.size(), this.getByteSize(rs));
}
public void pushAll(final Collection<Record> rs) {
Validate.notNull(rs);
Validate.noNullElements(rs);
this.doPushAll(rs);
this.statPush(rs.size(), this.getByteSize(rs));
}
@Override
public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
Validate.noNullElements(items, "Item cannot be null");
HashMap<Integer, ItemStack> leftover = new HashMap();
label35:
for(int i = 0; i < items.length; ++i) {
ItemStack item = items[i];
while(true) {
while(true) {
int firstPartial = this.firstPartial(item);
if (firstPartial == -1) {
int firstFree = this.firstEmpty();
if (firstFree == -1) {
leftover.put(i, item);
continue label35;
}
if (item.getAmount() <= 64) {
this.setItem(firstFree, item);
continue label35;
}
ItemStack stack = item.clone();
stack.setAmount(64);
this.setItem(firstFree, stack);
item.setAmount(item.getAmount() - 64);
} else {
ItemStack partialItem = this.getItem(firstPartial);
int amount = item.getAmount();
int partialAmount = partialItem.getAmount();
int maxAmount = partialItem.getMaxStackSize();
if (amount + partialAmount <= maxAmount) {
partialItem.setAmount(amount + partialAmount);
this.setItem(firstPartial, partialItem);
continue label35;
}
partialItem.setAmount(maxAmount);
this.setItem(firstPartial, partialItem);
item.setAmount(amount + partialAmount - maxAmount);
}
}
}
}
return leftover;
}
@Override
public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
Validate.noNullElements(items, "Item cannot be null");
HashMap<Integer, ItemStack> leftover = new HashMap();
label35:
for(int i = 0; i < items.length; ++i) {
ItemStack item = items[i];
while(true) {
while(true) {
int firstPartial = this.firstPartial(item);
if (firstPartial == -1) {
int firstFree = this.firstEmpty();
if (firstFree == -1) {
leftover.put(i, item);
continue label35;
}
if (item.getAmount() <= 64) {
this.setItem(firstFree, item);
continue label35;
}
ItemStack stack = item.clone();
stack.setAmount(64);
this.setItem(firstFree, stack);
item.setAmount(item.getAmount() - 64);
} else {
ItemStack partialItem = this.getItem(firstPartial);
int amount = item.getAmount();
int partialAmount = partialItem.getAmount();
int maxAmount = partialItem.getMaxStackSize();
if (amount + partialAmount <= maxAmount) {
partialItem.setAmount(amount + partialAmount);
this.setItem(firstPartial, partialItem);
continue label35;
}
partialItem.setAmount(maxAmount);
this.setItem(firstPartial, partialItem);
item.setAmount(amount + partialAmount - maxAmount);
}
}
}
}
return leftover;
}
public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
Validate.noNullElements(items, "Item cannot be null");
HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();
/* TODO: some optimization
* - Create a 'firstPartial' with a 'fromIndex'
* - Record the lastPartial per Material
* - Cache firstEmpty result
*/
for (int i = 0; i < items.length; i++) {
ItemStack item = items[i];
while (true) {
// Do we already have a stack of it?
int firstPartial = firstPartial(item);
// Drat! no partial stack
if (firstPartial == -1) {
// Find a free spot!
int firstFree = firstEmpty();
if (firstFree == -1) {
// No space at all!
leftover.put(i, item);
break;
} else {
// More than a single stack!
if (item.getAmount() > getMaxItemStack()) {
CraftItemStack stack = CraftItemStack.asCraftCopy(item);
stack.setAmount(getMaxItemStack());
setItem(firstFree, stack);
item.setAmount(item.getAmount() - getMaxItemStack());
} else {
// Just store it
setItem(firstFree, item);
break;
}
}
} else {
// So, apparently it might only partially fit, well lets do just that
ItemStack partialItem = getItem(firstPartial);
int amount = item.getAmount();
int partialAmount = partialItem.getAmount();
int maxAmount = partialItem.getMaxStackSize();
// Check if it fully fits
if (amount + partialAmount <= maxAmount) {
partialItem.setAmount(amount + partialAmount);
break;
}
// It fits partially
partialItem.setAmount(maxAmount);
item.setAmount(amount + partialAmount - maxAmount);
}
}
}
return leftover;
}
/**
* The constructor for a LockedCategory.
*
* @param key
* A unique identifier for this category
* @param item
* The display item for this category
* @param tier
* The tier of this category
* @param parents
* The parent categories for this category
*
*/
public LockedCategory(NamespacedKey key, ItemStack item, int tier, NamespacedKey... parents) {
super(key, item, tier);
Validate.noNullElements(parents, "A LockedCategory must not have any 'null' parents!");
this.keys = parents;
}