Java Code Examples for org.apache.commons.lang.Validate#noNullElements()

The following examples show how to use org.apache.commons.lang.Validate#noNullElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SlimefunItem.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 2
Source File: SlimefunItem.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
        }
    }
}
 
Example 3
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
   validVerifyType(verifyType);
   Validate.notEmpty(schemaFile);
   Validate.noNullElements(schemaFile);
   this.verify = verifyType;
   this.schemaFiles = schemaFile;
}
 
Example 4
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
   validVerifyType(verifyType);
   Validate.notEmpty(schemaFile);
   Validate.noNullElements(schemaFile);
   this.verify = verifyType;
   this.schemaFiles = schemaFile;
}
 
Example 5
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
   validVerifyType(verifyType);
   Validate.notEmpty(schemaFile);
   Validate.noNullElements(schemaFile);
   this.verify = verifyType;
   this.schemaFiles = schemaFile;
}
 
Example 6
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
   validVerifyType(verifyType);
   Validate.notEmpty(schemaFile);
   Validate.noNullElements(schemaFile);
   this.verify = verifyType;
   this.schemaFiles = schemaFile;
}
 
Example 7
Source File: DrugsLogicImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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();
    }
}
 
Example 8
Source File: DrugsLogicImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
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();
    }
}
 
Example 9
Source File: SchemaValidatorHandler.java    From freehealth-connector with GNU Affero General Public License v3.0 5 votes vote down vote up
public SchemaValidatorHandler(int verifyType, String... schemaFile) {
   validVerifyType(verifyType);
   Validate.notEmpty(schemaFile);
   Validate.noNullElements(schemaFile);
   this.verify = verifyType;
   this.schemaFiles = schemaFile;
}
 
Example 10
Source File: Itinerary.java    From dddsample-core with MIT License 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param legs List of legs for this itinerary.
 */
public Itinerary(final List<Leg> legs) {
  Validate.notEmpty(legs);
  Validate.noNullElements(legs);

  this.legs = legs;
}
 
Example 11
Source File: Leg.java    From dddsample-core with MIT License 5 votes vote down vote up
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;
}
 
Example 12
Source File: Schedule.java    From dddsample-core with MIT License 5 votes vote down vote up
Schedule(final List<CarrierMovement> carrierMovements) {
  Validate.notNull(carrierMovements);
  Validate.noNullElements(carrierMovements);
  Validate.notEmpty(carrierMovements);

  this.carrierMovements = carrierMovements;
}
 
Example 13
Source File: CarrierMovement.java    From dddsample-core with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: InventoryImpl.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 15
Source File: CraftInventory.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 16
Source File: PlayerInventoryImpl.java    From Civs with GNU General Public License v3.0 4 votes vote down vote up
@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;
}
 
Example 17
Source File: Channel.java    From DataLink with Apache License 2.0 4 votes vote down vote up
public void pushAll(final Collection<Record> rs) {
    Validate.notNull(rs);
    Validate.noNullElements(rs);
    this.doPushAll(rs);
    this.statPush(rs.size(), this.getByteSize(rs));
}
 
Example 18
Source File: ChannelBase.java    From DataLink with Apache License 2.0 4 votes vote down vote up
public void pushAll(final Collection<Record> rs) {
    Validate.notNull(rs);
    Validate.noNullElements(rs);
    this.doPushAll(rs);
    this.statPush(rs.size(), this.getByteSize(rs));
}
 
Example 19
Source File: LockedCategory.java    From Slimefun4 with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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;
}