Example usage for java.util List addAll

List of usage examples for java.util List addAll

Introduction

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

Prototype

boolean addAll(Collection<? extends E> c);

Source Link

Document

Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation).

Usage

From source file:jsonclient.JsonClient.java

public static List<Place> getCities(String regionId) {
    String jsonQuery;/*from  w  w w  . j av a 2s.co m*/
    String repsonse;
    Places cities = null;
    jsonQuery = "{\"data\":{\"action\":\"GetCityList\", \"param\":{\"regionId\":\"" + regionId + "\"}}}";
    List<Place> citiesList = new ArrayList<Place>();
    try {
        repsonse = JsonClient.setSlide(jsonQuery);
        cities = new Gson().fromJson(repsonse, Places.class);
    } catch (IOException ex) {
        System.out.println(ex);
    }
    citiesList.addAll(cities.getData().getList());
    citiesList.addAll(cities.getData().getPrefferedList());
    return citiesList;
}

From source file:com.cbtec.eliademyutils.EliademyUtils.java

public static String serviceCall(String data, String webService, String token, String serviceClient) {

    String retval = null;// www .  j  av a2s.  co m
    Log.d("EliademyUtils", "Service: " + data + " Service: " + webService);

    try {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

        if (data.toString().length() > 0) {
            JSONObject jsObj = new JSONObject(data.toString());
            nameValuePairs.addAll(nameValueJson(jsObj, ""));
        }
        nameValuePairs.add(new BasicNameValuePair("wstoken", token));
        nameValuePairs.add(new BasicNameValuePair("wsfunction", webService));
        nameValuePairs.add(new BasicNameValuePair("moodlewsrestformat", "json"));

        HttpPost httppost = new HttpPost(serviceClient + "/webservice/rest/server.php?");

        Log.d("EliademyUtils", nameValuePairs.toString());
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            StringBuilder jsonStr = new StringBuilder();
            InputStream iStream = entity.getContent();
            BufferedReader bufferReader = new BufferedReader(new InputStreamReader(iStream));
            String jpart;
            while ((jpart = bufferReader.readLine()) != null) {
                jsonStr.append(jpart);
            }
            iStream.close();
            return jsonStr.toString();
        }
    } catch (Exception e) {
        Log.e("EliademyUtils", "exception", e);
        return retval;
    }
    return retval;
}

From source file:net.adamcin.httpsig.http.apache3.Http3Util.java

public static void enableAuth(HttpClient client, Keychain keychain, KeyId keyId) {
    Signer signer = new Signer(keychain, keyId);
    CredentialsProvider credProvider = (CredentialsProvider) client.getParams()
            .getParameter(CredentialsProvider.PROVIDER);

    CredentialsProvider newProvider;/*from  ww  w.  j  a va2s.  c  o  m*/
    if (credProvider instanceof SignerCredentialsProvider) {
        newProvider = new SignerCredentialsProvider(signer,
                ((SignerCredentialsProvider) credProvider).getDelegatee());
    } else {
        newProvider = new SignerCredentialsProvider(signer, credProvider);
    }

    client.getParams().setParameter(CredentialsProvider.PROVIDER, newProvider);
    AuthPolicy.registerAuthScheme(Constants.SCHEME, Http3SignatureAuthScheme.class);
    List<String> schemes = new ArrayList<String>();
    schemes.add(Constants.SCHEME);

    Collection authSchemePriority = (Collection) DefaultHttpParams.getDefaultParams()
            .getParameter(AuthPolicy.AUTH_SCHEME_PRIORITY);
    if (authSchemePriority != null) {
        schemes.addAll(authSchemePriority);
    }
    client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, schemes);
}

From source file:UnitTest2.java

public static void testexclude() throws IOException, ParseException, DScabiClientException {
    DMeta meta = new DMeta("localhost", "5000");

    List<DComputeNoBlock> cnba = meta.getComputeNoBlockMany(1);
    List<DComputeNoBlock> cnbexclude = new ArrayList<DComputeNoBlock>();
    cnbexclude.addAll(cnba);

    List<DComputeNoBlock> cnba2 = meta.getComputeNoBlockManyMayExclude(1, cnbexclude);

    for (DComputeNoBlock cnb2 : cnba2) {
        log.debug("cnb2 : {}", cnb2.toString());
    }/*from w  w  w . j a va2  s.c om*/
    cnba.get(0).close();
    cnba2.get(0).close();
    meta.close();
}

From source file:cc.kune.wave.server.CustomSettingsBinder.java

/**
 * Bind configuration parameters into Guice Module.
 *
 * @param propertyFile the property file
 * @param settingsArg the settings arg//w  w  w . j a  v a  2  s  . c  o m
 * @return a Guice module configured with setting support.
 * @throws ConfigurationException on configuration error
 */
public static Module bindSettings(String propertyFile, Class<?>... settingsArg) throws ConfigurationException {
    final CompositeConfiguration config = new CompositeConfiguration();
    config.addConfiguration(new SystemConfiguration());
    config.addConfiguration(new PropertiesConfiguration(propertyFile));

    List<Field> fields = new ArrayList<Field>();
    for (Class<?> settings : settingsArg) {
        fields.addAll(Arrays.asList(settings.getDeclaredFields()));
    }

    // Reflect on settings class and absorb settings
    final Map<Setting, Field> settings = new LinkedHashMap<Setting, Field>();
    for (Field field : fields) {
        if (!field.isAnnotationPresent(Setting.class)) {
            continue;
        }

        // Validate target type
        SettingTypeValidator typeHelper = supportedSettingTypes.get(field.getType());
        if (typeHelper == null || !typeHelper.check(field.getGenericType())) {
            throw new IllegalArgumentException(field.getType() + " is not one of the supported setting types");
        }

        Setting setting = field.getAnnotation(Setting.class);
        settings.put(setting, field);
    }

    // Now validate them
    List<String> missingProperties = new ArrayList<String>();
    for (Setting setting : settings.keySet()) {
        if (setting.defaultValue().isEmpty()) {
            if (!config.containsKey(setting.name())) {
                missingProperties.add(setting.name());
            }
        }
    }
    if (missingProperties.size() > 0) {
        StringBuilder error = new StringBuilder();
        error.append("The following required properties are missing from the server configuration: ");
        error.append(Joiner.on(", ").join(missingProperties));
        throw new ConfigurationException(error.toString());
    }

    // bundle everything up in an injectable guice module
    return new AbstractModule() {

        @Override
        protected void configure() {
            // We must iterate the settings a third time when binding.
            // Note: do not collapse these loops as that will damage
            // early error detection. The runtime is still O(n) in setting count.
            for (Map.Entry<Setting, Field> entry : settings.entrySet()) {
                Class<?> type = entry.getValue().getType();
                Setting setting = entry.getKey();

                if (int.class.equals(type)) {
                    Integer defaultValue = null;
                    if (!setting.defaultValue().isEmpty()) {
                        defaultValue = Integer.parseInt(setting.defaultValue());
                    }
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getInteger(setting.name(), defaultValue));
                } else if (boolean.class.equals(type)) {
                    Boolean defaultValue = null;
                    if (!setting.defaultValue().isEmpty()) {
                        defaultValue = Boolean.parseBoolean(setting.defaultValue());
                    }
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getBoolean(setting.name(), defaultValue));
                } else if (String.class.equals(type)) {
                    bindConstant().annotatedWith(Names.named(setting.name()))
                            .to(config.getString(setting.name(), setting.defaultValue()));
                } else {
                    String[] value = config.getStringArray(setting.name());
                    if (value.length == 0 && !setting.defaultValue().isEmpty()) {
                        value = setting.defaultValue().split(",");
                    }
                    bind(new TypeLiteral<List<String>>() {
                    }).annotatedWith(Names.named(setting.name())).toInstance(ImmutableList.copyOf(value));
                }
            }
        }
    };
}

From source file:com.amazonaws.services.kinesis.clientlibrary.config.AWSCredentialsProviderPropertyValueDecoder.java

private static List<String> getProviderNames(String property) {
    // assume list delimiter is ","
    String[] elements = property.split(LIST_DELIMITER);
    List<String> result = new ArrayList<String>();
    for (int i = 0; i < elements.length; i++) {
        String string = elements[i].trim();
        if (!string.isEmpty()) {
            // find all possible names and add them to name list
            result.addAll(getPossibleFullClassNames(string));
        }// w w  w .ja v  a  2s  .c  om
    }
    return result;
}

From source file:com.qubit.solution.fenixedu.integration.cgd.webservices.messages.member.SearchMemberOutputData.java

public static SearchMemberOutputData createDefault(IMemberIDAdapter strategy, Person person) {

    SearchMemberOutputData searchMemberOutputData = new SearchMemberOutputData();
    searchMemberOutputData.setMemberID(strategy.retrieveMemberID(person));
    searchMemberOutputData.setName(person.getName());
    String socialSecurityNumber = person.getSocialSecurityNumber();
    if (socialSecurityNumber != null && FiscalCodeValidation.isValidcontrib(socialSecurityNumber)) {
        searchMemberOutputData.setFiscalCode(Long.valueOf(socialSecurityNumber));
    } else {/*from   w ww . j  a v a2s  .  c  o m*/
        searchMemberOutputData.setFiscalCode(0L);
    }

    Unit institutionUnit = Bennu.getInstance().getInstitutionUnit();

    searchMemberOutputData.setEstablishmentName(institutionUnit.getName());
    searchMemberOutputData.setEstablishmentCode(institutionUnit.getCode());

    ExecutionYear readCurrentExecutionYear = ExecutionYear.readCurrentExecutionYear();
    ExecutionYear previousYear = readCurrentExecutionYear.getPreviousExecutionYear();
    List<ExecutionSemester> semesters = new ArrayList<ExecutionSemester>();
    semesters.addAll(readCurrentExecutionYear.getExecutionPeriodsSet());
    semesters.addAll(previousYear.getExecutionPeriodsSet());

    String stayingIndicator = (person.getStudent() != null && person.getStudent().hasActiveRegistrations())
            || (person.getTeacher() != null && person.getTeacher().getTeacherAuthorizationStream()
                    .anyMatch(authorization -> semesters.contains(authorization.getExecutionSemester()))) ? "S"
                            : "N";
    searchMemberOutputData.setStayingIndicator(stayingIndicator);
    return searchMemberOutputData;
}

From source file:org.geoserver.wps.ppio.ProcessParameterIO.java

public static List<ProcessParameterIO> findAll(Parameter<?> p, ApplicationContext context) {
    // enum special treatment
    if (p.type.isEnum()) {
        List<ProcessParameterIO> result = new ArrayList<ProcessParameterIO>();
        result.add(new LiteralPPIO(p.type));
        return result;
    }/*from   w ww.  jav a2 s .  c  o  m*/

    // load all extensions
    List<ProcessParameterIO> l = new ArrayList<ProcessParameterIO>(defaults);
    if (context != null) {
        l.addAll(GeoServerExtensions.extensions(ProcessParameterIO.class, context));
    } else {
        l.addAll(GeoServerExtensions.extensions(ProcessParameterIO.class));
    }

    // find parameters that match
    List<ProcessParameterIO> matches = new ArrayList<ProcessParameterIO>();

    // do a two phase search, first try to match the identifier
    for (ProcessParameterIO ppio : l) {
        if (ppio.getIdentifer() != null && ppio.getIdentifer().equals(p.key)
                && ppio.getType().isAssignableFrom(p.type)) {
            matches.add(ppio);
        }
    }

    // if no matches, look for just those which match by type
    if (matches.isEmpty()) {
        for (ProcessParameterIO ppio : l) {
            if (ppio.getType().isAssignableFrom(p.type)) {
                matches.add(ppio);
            }
        }
    }

    return matches;
}

From source file:com.flipkart.zjsonpatch.JsonDiff.java

private static List<Object> getPath(List<Object> path, Object key) {
    List<Object> toReturn = new ArrayList<Object>();
    toReturn.addAll(path);
    toReturn.add(key);//from w  w w  .j  av a  2 s . com
    return toReturn;
}

From source file:jsonclient.JsonClient.java

public static List<Place> getRegions(String countryId) {
    String jsonQuery;/*  ww  w .  j  a v  a  2 s . c om*/
    String repsonse;
    Places regions = null;
    jsonQuery = "{\"data\":{\"action\":\"GetRegionList\", \"param\":{\"countryId\":\"" + countryId + "\"}}}";
    List<Place> regionsList = new ArrayList<Place>();
    try {
        repsonse = JsonClient.setSlide(jsonQuery);
        regions = new Gson().fromJson(repsonse, Places.class);
    } catch (IOException ex) {
        System.out.println(ex);
    }
    regionsList.addAll(regions.getData().getList());
    regionsList.addAll(regions.getData().getPrefferedList());
    return regionsList;
}