Example usage for java.util AbstractQueue add

List of usage examples for java.util AbstractQueue add

Introduction

In this page you can find the example usage for java.util AbstractQueue add.

Prototype

public boolean add(E e) 

Source Link

Document

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Usage

From source file:persistence.JSONReader.java

/**
 * // www.  j a  v a  2s  .c o m
 * @param c the class of the Models expected
 * @return a List of Models from a JSON formatted file.
 * @throws java.io.IOException
 * @throws org.json.simple.parser.ParseException
 */
public static AbstractQueue<JSONModel> loadModels(Class c)
        throws IOException, ParseException, InstantiationException, IllegalAccessException {
    AbstractQueue<JSONModel> modelQueue = new PriorityQueue();
    JSONModel model;
    JSONParser parser = new JSONParser();

    String json = file.readLine();
    while (json != null) {
        model = (JSONModel) c.newInstance();
        JSONObject jsonObject = (JSONObject) parser.parse(json);
        model.fromJSON(jsonObject);
        modelQueue.add(model);
        json = file.readLine();
    }

    return modelQueue;
}

From source file:com.netflix.discovery.shared.Applications.java

/**
 * Add the instance to the given map based if the vip address matches with
 * that of the instance. Note that an instance can be mapped to multiple vip
 * addresses./* www  .j a v a  2 s.c  om*/
 *
 */
private void addInstanceToMap(InstanceInfo info, String vipAddresses,
        Map<String, AbstractQueue<InstanceInfo>> vipMap) {
    if (vipAddresses != null) {
        String[] vipAddressArray = vipAddresses.split(",");
        for (String vipAddress : vipAddressArray) {
            String vipName = vipAddress.toUpperCase(Locale.ROOT);
            AbstractQueue<InstanceInfo> instanceInfoList = vipMap.get(vipName);
            if (instanceInfoList == null) {
                instanceInfoList = new ConcurrentLinkedQueue<InstanceInfo>();
                vipMap.put(vipName, instanceInfoList);
            }
            instanceInfoList.add(info);
        }
    }
}