Example usage for java.util Collections addAll

List of usage examples for java.util Collections addAll

Introduction

In this page you can find the example usage for java.util Collections addAll.

Prototype

@SafeVarargs
public static <T> boolean addAll(Collection<? super T> c, T... elements) 

Source Link

Document

Adds all of the specified elements to the specified collection.

Usage

From source file:net.bulletin.pdi.xero.step.XeroGetStep.java

private Stack<String> getContainerElementsStack(XeroGetStepMeta meta) throws KettleException {
    Stack<String> result = new Stack<String>();
    String ce = StringUtils.trimToEmpty(meta.getContainerElements());

    while (ce.startsWith("/")) {
        ce = ce.substring(1);/* ww w  .j a v  a 2  s .  co  m*/
    }

    if (StringUtils.isNotBlank(ce)) {
        if (!PATTERN_CONTAINERELEMENTS.matcher(ce).matches()) {
            throw new KettleException("malformed container elements; " + ce);
        }

        Collections.addAll(result, ce.split("/"));
    }

    return result;
}

From source file:com.adobe.cq.wcm.core.components.internal.models.v1.PageImpl.java

protected void addPolicyClientLibs(List<String> categories) {
    if (currentStyle != null) {
        Collections.addAll(categories, currentStyle.get(PN_CLIENTLIBS, ArrayUtils.EMPTY_STRING_ARRAY));
    }//  ww w .ja v  a 2s. com
}

From source file:co.marcin.novaguilds.util.ItemStackUtils.java

@SuppressWarnings("deprecation")
public static ItemStack stringToItemStack(String str) {
    if (!str.isEmpty()) {
        ItemStack itemStack;/*from   www  .j a v  a 2s .c o m*/
        Material material;
        String name = "";
        int amount = 0;
        List<String> lore = new ArrayList<>();
        String loreString = "";
        String bookAuthor = null;
        String bookBook = null;
        String player = null;
        short durability = 0;
        PotionType potionType = null;
        int potionLevel = 0;
        byte data = (byte) 0;
        Map<Enchantment, Integer> enchantments = new HashMap<>();

        String[] explode = str.split(" ");

        String materialString = explode[0];

        DyeColor color;

        if (explode[0].contains(":")) {
            String[] dataSplit = explode[0].split(":");
            materialString = dataSplit[0];
            String dataString = dataSplit[1];

            if (NumberUtils.isNumeric(dataString)) {
                durability = Short.parseShort(dataString);
                data = Byte.parseByte(dataString);
            } else {
                color = DyeColor.valueOf(dataString.toUpperCase());
                if (color != null) {
                    data = color.getData();
                }

                durability = data;
            }
        }

        if (NumberUtils.isNumeric(materialString)) {
            material = Material.getMaterial(Integer.parseInt(materialString));
        } else {
            material = Material.getMaterial(materialString.toUpperCase());
        }

        if (material == null) {
            return stringToItemStack("DIRT 1 name:&cINVALID_ITEM");
        }

        if (explode.length > 1) { //amount
            if (NumberUtils.isNumeric(explode[1])) {
                amount = Integer.parseInt(explode[1]);
                explode[1] = null;
            }
        } else {
            amount = material.getMaxStackSize();
        }

        explode[0] = null;

        for (String detail : explode) {
            if (detail != null) {
                if (detail.contains(":")) {
                    String[] detailSplit = detail.split(":");
                    String value = detailSplit[1];
                    //Bukkit.getLogger().info(detailSplit[0] + " : " + value);
                    switch (detailSplit[0].toLowerCase()) {
                    case "name":
                        name = value;
                        break;
                    case "lore":
                        loreString = value;
                        break;
                    case "title":
                        name = value;
                        break;
                    case "author":
                        bookAuthor = value;
                        break;
                    case "book":
                        bookBook = value;
                        break;
                    case "power":
                        if (material == Material.BOW) {
                            enchantments.put(Enchantment.ARROW_DAMAGE, Integer.valueOf(value));
                        } else if (material == Material.POTION) {
                            if (NumberUtils.isNumeric(value)) {
                                potionLevel = Integer.parseInt(value);
                            }
                        } else if (material == Material.FIREWORK) {
                            //TODO
                        }
                        break;
                    case "effect":
                        if (material == Material.POTION) {
                            potionType = PotionType.valueOf(value.toUpperCase());
                        }
                        break;
                    case "duration":
                        break;
                    case "color":
                        color = DyeColor.valueOf(value.toUpperCase());
                        break;
                    case "player":
                        player = value;
                        break;
                    case "fade":
                        break;
                    case "shape":
                        break;

                    case "sharpness":
                    case "alldamage":
                        enchantments.put(Enchantment.DAMAGE_ALL, Integer.valueOf(value));
                        break;
                    case "arrowdamage":
                    case "ardmg":
                        enchantments.put(Enchantment.ARROW_DAMAGE, Integer.valueOf(value));
                        break;
                    case "baneofarthropods":
                        enchantments.put(Enchantment.DAMAGE_ARTHROPODS, Integer.valueOf(value));
                        break;
                    case "durability":
                    case "unbreaking":
                        enchantments.put(Enchantment.DURABILITY, Integer.valueOf(value));
                        break;
                    case "fire":
                    case "fireaspect":
                        enchantments.put(Enchantment.FIRE_ASPECT, Integer.valueOf(value));
                        break;
                    case "knockback":
                        enchantments.put(Enchantment.KNOCKBACK, Integer.valueOf(value));
                        break;
                    case "looting":
                    case "fortune":
                        enchantments.put(Enchantment.LOOT_BONUS_BLOCKS, Integer.valueOf(value));
                        break;
                    case "mobloot":
                        enchantments.put(Enchantment.LOOT_BONUS_MOBS, Integer.valueOf(value));
                        break;
                    case "smite":
                    case "undeaddamage":
                        enchantments.put(Enchantment.DAMAGE_UNDEAD, Integer.valueOf(value));
                        break;
                    case "arrowknockback":
                    case "punch":
                        enchantments.put(Enchantment.ARROW_KNOCKBACK, Integer.valueOf(value));
                        break;
                    case "flame":
                    case "flamearrow":
                        enchantments.put(Enchantment.ARROW_FIRE, Integer.valueOf(value));
                        break;
                    case "infarrows":
                    case "infinity":
                        enchantments.put(Enchantment.ARROW_INFINITE, Integer.valueOf(value));
                        break;
                    case "digspeed":
                    case "efficiency":
                        enchantments.put(Enchantment.DIG_SPEED, Integer.valueOf(value));
                    case "silktouch":
                        enchantments.put(Enchantment.SILK_TOUCH, Integer.valueOf(value));
                        break;
                    case "highcrit":
                    case "thorns":
                        enchantments.put(Enchantment.THORNS, Integer.valueOf(value));
                        break;
                    case "blastprotect":
                        enchantments.put(Enchantment.PROTECTION_EXPLOSIONS, Integer.valueOf(value));
                        break;
                    case "fallprot":
                    case "featherfall":
                        enchantments.put(Enchantment.PROTECTION_FALL, Integer.valueOf(value));
                        break;
                    case "fireprot":
                    case "fireprotect":
                        enchantments.put(Enchantment.PROTECTION_FIRE, Integer.valueOf(value));
                        break;
                    case "projectileprotection":
                    case "projprot":
                        enchantments.put(Enchantment.PROTECTION_PROJECTILE, Integer.valueOf(value));
                        break;
                    case "protect":
                    case "protection":
                        enchantments.put(Enchantment.PROTECTION_ENVIRONMENTAL, Integer.valueOf(value));
                        break;
                    case "waterworker":
                        enchantments.put(Enchantment.WATER_WORKER, Integer.valueOf(value));
                        break;
                    case "respiration":
                    case "breath":
                    case "aquainfinity":
                        enchantments.put(Enchantment.OXYGEN, Integer.valueOf(value));
                        break;
                    case "luck":
                        enchantments.put(Enchantment.LUCK, Integer.valueOf(value));
                        break;
                    case "lure":
                        enchantments.put(Enchantment.LURE, Integer.valueOf(value));
                        break;
                    }
                }
            }
        }

        //replace _ with spaces
        name = name.replace("_", " ");
        name = StringUtils.fixColors(name);
        loreString = loreString.replace("_", " ");
        loreString = StringUtils.fixColors(loreString);

        if (loreString.contains("|")) {
            Collections.addAll(lore, org.apache.commons.lang.StringUtils.split(loreString, '|'));
        } else {
            lore.add(loreString);
        }

        itemStack = new ItemStack(material, amount, data);
        itemStack.addUnsafeEnchantments(enchantments);
        ItemMeta itemMeta = itemStack.getItemMeta();

        if (!name.isEmpty()) {
            itemMeta.setDisplayName(name);
        }

        if (!loreString.isEmpty()) {
            itemMeta.setLore(lore);
        }

        if (material == Material.POTION && potionLevel != 0 && potionType != null) {
            Potion potion = new Potion(potionType, potionLevel);
            potion.apply(itemStack);
        }

        itemStack.setDurability(durability);
        itemStack.setItemMeta(itemMeta);

        if (player != null && itemStack.getType() == Material.SKULL_ITEM) {
            SkullMeta skullMeta = (SkullMeta) Bukkit.getItemFactory().getItemMeta(Material.SKULL_ITEM);
            skullMeta.setOwner(player);
            itemStack.setItemMeta(skullMeta);
        }

        return itemStack;
    }

    return stringToItemStack("DIRT 1 name:&cINVALID_ITEM");
}

From source file:ch.admin.suis.msghandler.signer.SignerTest.java

private List<File> getAllFilesFromDir(File directory) {
    if (directory == null) {
        return new ArrayList<File>();
    }/*  ww w  .  j  a v a 2s . c  o m*/

    File[] files = ch.admin.suis.msghandler.util.FileUtils.listFiles(directory, new FileFilter() {
        @Override
        public boolean accept(File pathname) {
            return pathname.isFile() && ch.admin.suis.msghandler.util.FileUtils.canRead(pathname)
                    && !pathname.isHidden();
        }
    });

    List<File> retVal = new ArrayList();
    Collections.addAll(retVal, files);
    return retVal;
}

From source file:com.example.app.profile.ui.user.ProfileMembershipManagement.java

/**
 * Add one or more excluded membership types.
 * Excluded membership types will not be shown in the UI.
 *
 * @param types the types.//  ww w . ja  va  2s  . c  om
 */
public void addExcludedMembershipType(@Nonnull MembershipType... types) {
    Collections.addAll(_excludedMembershipTypes, types);
}

From source file:com.example.app.profile.ui.user.PrincipalValueEditor.java

@Override
public void init() {
    super.init();

    addEditorForProperty(() -> {//from  w  ww  . j a  v  a  2s.  c o  m
        ContactValueEditorConfig config = new ContactValueEditorConfig();
        NameValueEditorConfig nameConfig = new NameValueEditorConfig();
        nameConfig.setIncludedFields(first, last);
        nameConfig.setRequiredFields(first, last);
        EmailAddressValueEditorConfig emailConfig = new EmailAddressValueEditorConfig();
        emailConfig.setEmailSupplier(() -> {
            TextEditor editor = new TextEditor(LABEL_EMAIL(), null);
            editor.addClassName(CSSUtil.CSS_REQUIRED_FIELD);

            editor.setValueValidator(new CompositeValidator(
                    new RequiredValueValidator<>().withErrorMessage(CommonValidationText.ARG0_IS_REQUIRED,
                            LABEL_EMAIL()),
                    new EmailValidator(LABEL_EMAIL(), true).withNotificationSourceSetter(
                            (validator, component, notification) -> notification.setSource(editor)),
                    new Validator() {

                        public NotificationSourceSetter<Validator> _notificationSourceSetter;

                        /**
                         * Set the notification source setter.
                         * @see NotificationSourceSetter#defaultSourceSetter()
                         * @param notificationSourceSetter the notification source setter
                         */
                        @SuppressFBWarnings(value = "UMAC_UNCALLABLE_METHOD_OF_ANONYMOUS_CLASS", justification = "Called via reflection")
                        public void setNotificationSourceSetter(
                                @Nullable NotificationSourceSetter<Validator> notificationSourceSetter) {
                            _notificationSourceSetter = notificationSourceSetter;
                        }

                        @Override
                        public boolean validate(Component component, Notifiable notifiable) {
                            Field field = (Field) component;
                            if (editor.getModificationState() != ModificationState.UNCHANGED) {
                                AuthenticationDomainList authDomain = createDomainList(getAuthDomains());
                                Principal result = _principalDAO.getPrincipalByLogin(field.getText(),
                                        authDomain);
                                if (result != null && !Objects.equals(result, getValue())) {
                                    NotificationImpl error = error(
                                            createText(ERROR_MESSAGE_USERNAME_EXISTS_FMT(), LABEL_EMAIL()));
                                    _notificationSourceSetter.setSource(this, field, error);
                                    notifiable.sendNotification(error);
                                    return false;
                                }
                            }
                            return true;
                        }
                    }).withNotificationSourceSetterOnChildren(
                            (validator, component, notification) -> notification.setSource(editor)));
            return editor;
        });
        PhoneNumberValueEditorConfig phoneConfig = new PhoneNumberValueEditorConfig();
        phoneConfig.setDefaultContactDataCategory(BUSINESS);
        phoneConfig.setRequiredFields(PhoneNumberField.phoneNumber);
        PhoneNumberValueEditorConfig smsConfig = new PhoneNumberValueEditorConfig();
        smsConfig.setSingleFieldSupplier(() -> {
            _smsEditor.setValueValidator(new PhoneNumberValidator());
            return _smsEditor;
        });
        smsConfig.setDefaultPhoneNumberType(MOBILE);
        smsConfig.setDefaultContactDataCategory(PERSONAL);

        AddressValueEditorConfig addressValueEditorConfig = new AddressValueEditorConfig();
        addressValueEditorConfig.getRequiredFields().clear();

        config.setIncludedFields(ContactField.name, ContactField.timezone);
        config.setRequiredFields(ContactField.name, ContactField.timezone);
        config.setNameConfig(nameConfig);
        config.setEmailAddressConfigs(emailConfig);
        config.setPhoneNumberConfigs(phoneConfig, smsConfig);
        config.setAddressConfigs(addressValueEditorConfig);

        return new ContactValueEditor(config);
    }, "contact");

    addEditorForProperty(() -> {
        List<PrincipalStatus> statusList = new ArrayList<>();
        statusList.add(null);
        Collections.addAll(statusList, PrincipalStatus.values());
        ComboBoxValueEditor<PrincipalStatus> editor = new ComboBoxValueEditor<>(LABEL_STATUS(), statusList,
                PrincipalStatus.active);
        editor.setRequiredValueValidator();
        editor.setVisible(false);
        return editor;
    }, Principal::getStatus, (writeVal, propVal) -> {
        if (propVal != null) {
            switch (propVal) {
            case active:
            case pending:
            case suspended:
                writeVal.setEnabled(true);
                break;
            case closed:
                writeVal.setEnabled(false);
                break;
            default:
                break;
            }
        }
        writeVal.setStatus(propVal);
    });
}

From source file:com.skelril.aurora.authentication.AuthComponent.java

public synchronized JSONArray getFrom(String subAddress) {

    JSONArray objective = new JSONArray();
    HttpURLConnection connection = null;
    BufferedReader reader = null;

    try {/* w  w  w . j  a  v  a2 s .  co m*/
        JSONParser parser = new JSONParser();
        for (int i = 1; true; i++) {

            try {
                // Establish the connection
                URL url = new URL(config.websiteUrl + subAddress + "?page=" + i);
                connection = (HttpURLConnection) url.openConnection();
                connection.setConnectTimeout(1500);
                connection.setReadTimeout(1500);

                // Check response codes return if invalid
                if (connection.getResponseCode() < 200 || connection.getResponseCode() >= 300)
                    return null;

                // Begin to read results
                reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                StringBuilder builder = new StringBuilder();
                String line;
                while ((line = reader.readLine()) != null) {
                    builder.append(line);
                }

                // Parse Data
                JSONObject o = (JSONObject) parser.parse(builder.toString());
                JSONArray ao = (JSONArray) o.get("characters");
                if (ao.isEmpty())
                    break;
                Collections.addAll(objective, (JSONObject[]) ao.toArray(new JSONObject[ao.size()]));
            } catch (ParseException e) {
                break;
            } finally {
                if (connection != null)
                    connection.disconnect();

                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException ignored) {
                    }
                }
            }
        }
    } catch (IOException e) {
        return null;
    }

    return objective;
}

From source file:com.asakusafw.runtime.stage.resource.StageResourceDriver.java

private static ArrayList<String> restoreStrings(Configuration conf, String key) {
    assert conf != null;
    assert key != null;
    ArrayList<String> results = new ArrayList<>();
    String[] old = conf.getStrings(key);
    if (old != null && old.length >= 1) {
        Collections.addAll(results, old);
    }/*from  w w w  .  j a va2 s.c  o  m*/
    return results;
}

From source file:com.baidu.rigel.biplatform.ma.ds.service.impl.DataSourceServiceImpl.java

/**
 * ????idname???//from  ww w .  j a  v a  2s .c  o  m
 * 
 * @param idOrName
 * @return
 */
private String getDatasourceDefineNameByIdOrName(String productLine, String idOrName) {
    String dir = getDsFileStoreDir(productLine);
    String[] ds = null;
    try {
        ds = fileService.ls(dir);
    } catch (FileServiceException e1) {
        logger.debug(e1.getMessage(), e1);
    }
    if (ds == null || ds.length == 0) {
        String msg = "can not get ds define by id : " + idOrName;
        logger.error(msg);
        return null;
    }
    Set<String> tmp = new HashSet<String>();
    Collections.addAll(tmp, ds);
    Set<String> dict = new HashSet<String>();
    tmp.stream().forEach((String s) -> {
        dict.add(s.substring(0, s.indexOf("_")));
        dict.add(s.substring(s.indexOf("_") + 1));
    });
    if (!dict.contains(idOrName)) {
        return null;
    }

    String fileName = null;
    for (String dsFileName : ds) {
        if (dsFileName.contains(idOrName)) {
            fileName = dsFileName;
            break;
        }
    }
    return fileName;
}

From source file:com.example.app.profile.ui.user.ProfileMembershipManagement.java

/**
 * Add one or more required membership types.
 *
 * @param types the types./*ww w  . j  a  v a2 s. c o  m*/
 */
public void addRequiredMembershipType(@Nonnull MembershipType... types) {
    Collections.addAll(_requiredMembershipTypes, types);
    _requiredMembershipTypes.removeAll(_excludedMembershipTypes);
}