Example usage for java.util AbstractList add

List of usage examples for java.util AbstractList add

Introduction

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

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list (optional operation).

Usage

From source file:Main.java

public static void main(String args[]) {
    AbstractList<String> v = new Vector<String>();
    v.add("A");
    v.add("B");/* www  . j ava 2  s  .  c  o m*/

    Iterator i = v.listIterator();
    while (i.hasNext()) {
        System.out.println(i.next());
    }
}

From source file:Main.java

public static <T> List<T> toList(Enumeration<? extends T> things) {
    AbstractList<T> list = new ArrayList<T>();
    while (things.hasMoreElements()) {
        list.add(things.nextElement());
    }//ww w .  j a v a 2  s  .com
    return list;
}

From source file:Main.java

public static void getAllChildrenText(Element paramElement, String paramString,
        AbstractList paramAbstractList) {
    NodeList localNodeList = paramElement.getChildNodes();
    for (int i = 0; i < localNodeList.getLength(); i++) {
        Node localNode = localNodeList.item(i);
        if ((localNode.getNodeType() == 1) && (((Element) localNode).getTagName().equals(paramString))) {
            String str = getNodeText(localNode);
            if (str != null)
                paramAbstractList.add(str);
        }//from  w w w . j  a  v a 2s.  com
    }
}

From source file:org.apache.hadoop.hive.metastore.Warehouse.java

/**
 * Extracts values from partition name without the column names.
 * @param name Partition name.//from  w  w  w . j a v a  2s  .  c om
 * @param result The result. Must be pre-sized to the expected number of columns.
 */
public static AbstractList<String> makeValsFromName(String name, AbstractList<String> result)
        throws MetaException {
    assert name != null;
    String[] parts = slash.split(name, 0);
    if (result == null) {
        result = new ArrayList<>(parts.length);
        for (int i = 0; i < parts.length; ++i) {
            result.add(null);
        }
    } else if (parts.length != result.size()) {
        throw new MetaException(
                "Expected " + result.size() + " components, got " + parts.length + " (" + name + ")");
    }
    for (int i = 0; i < parts.length; ++i) {
        int eq = parts[i].indexOf('=');
        if (eq <= 0) {
            throw new MetaException("Unexpected component " + parts[i]);
        }
        result.set(i, unescapePathName(parts[i].substring(eq + 1)));
    }
    return result;
}

From source file:com.metaparadigm.jsonrpc.ListSerializer.java

public Object unmarshall(SerializerState state, Class clazz, Object o) throws UnmarshallException {
    JSONObject jso = (JSONObject) o;// ww  w .  j a  v  a2s  .  c o m
    String java_class = null;
    try {
        java_class = jso.getString("javaClass");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    if (java_class == null)
        throw new UnmarshallException("no type hint");
    AbstractList al = null;
    if (java_class.equals("java.util.List") || java_class.equals("java.util.AbstractList")
            || java_class.equals("java.util.ArrayList")) {
        al = new ArrayList();
    } else if (java_class.equals("java.util.LinkedList")) {
        al = new LinkedList();
    } else if (java_class.equals("java.util.Vector")) {
        al = new Vector();
    } else {
        throw new UnmarshallException("not a List");
    }
    JSONArray jsonlist = null;
    try {
        jsonlist = jso.getJSONArray("list");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    if (jsonlist == null)
        throw new UnmarshallException("list missing");
    int i = 0;
    try {
        for (; i < jsonlist.length(); i++)
            al.add(ser.unmarshall(state, null, jsonlist.get(i)));
    } catch (UnmarshallException e) {
        throw new UnmarshallException("element " + i + " " + e.getMessage());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return al;
}

From source file:com.digitalarx.android.files.services.FileDownloader.java

/**
 * Entry point to add one or several files to the queue of downloads.
 * //from   w ww  .  j a va 2 s.  c o  m
 * New downloads are added calling to startService(), resulting in a call to this method. This ensures the service will keep on working 
 * although the caller activity goes away.
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)
    /*!intent.hasExtra(EXTRA_FILE_PATH) ||
    !intent.hasExtra(EXTRA_REMOTE_PATH)*/
    ) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
    }
    Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
    OCFile file = intent.getParcelableExtra(EXTRA_FILE);

    AbstractList<String> requestedDownloads = new Vector<String>(); // dvelasco: now this always contains just one element, but that can change in a near future (download of multiple selection)
    String downloadKey = buildRemoteName(account, file);
    try {
        DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
        mPendingDownloads.putIfAbsent(downloadKey, newDownload);
        newDownload.addDatatransferProgressListener(this);
        newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
        requestedDownloads.add(downloadKey);
        sendBroadcastNewDownload(newDownload);

    } catch (IllegalArgumentException e) {
        Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
        return START_NOT_STICKY;
    }

    if (requestedDownloads.size() > 0) {
        Message msg = mServiceHandler.obtainMessage();
        msg.arg1 = startId;
        msg.obj = requestedDownloads;
        mServiceHandler.sendMessage(msg);
    }

    return START_NOT_STICKY;
}

From source file:com.owncloud.android.files.services.FileDownloader.java

/**
 * Entry point to add one or several files to the queue of downloads.
 *
 * New downloads are added calling to startService(), resulting in a call to this method.
 * This ensures the service will keep on working although the caller activity goes away.
 *//*from w w  w .  j  av  a2 s  .  c om*/
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
    } else {
        final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
        final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
        AbstractList<String> requestedDownloads = new Vector<String>();
        try {
            DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
            newDownload.addDatatransferProgressListener(this);
            newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
            Pair<String, String> putResult = mPendingDownloads.putIfAbsent(account, file.getRemotePath(),
                    newDownload);
            String downloadKey = putResult.first;
            requestedDownloads.add(downloadKey);

            sendBroadcastNewDownload(newDownload, putResult.second);

        } catch (IllegalArgumentException e) {
            Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
            return START_NOT_STICKY;
        }

        if (requestedDownloads.size() > 0) {
            Message msg = mServiceHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = requestedDownloads;
            mServiceHandler.sendMessage(msg);
        }
        //}
    }

    return START_NOT_STICKY;
}

From source file:com.synox.android.files.services.FileDownloader.java

/**
 * Entry point to add one or several files to the queue of downloads.
 * <p/>/*from   w  w w . ja v a  2 s .com*/
 * New downloads are added calling to startService(), resulting in a call to this method.
 * This ensures the service will keep on working although the caller activity goes away.
 */
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
    } else {
        final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
        final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
        AbstractList<String> requestedDownloads = new Vector<>();
        try {
            DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
            newDownload.addDatatransferProgressListener(this);
            newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
            Pair<String, String> putResult = mPendingDownloads.putIfAbsent(account, file.getRemotePath(),
                    newDownload);
            String downloadKey = putResult.first;
            requestedDownloads.add(downloadKey);

            // Store file on db with state 'downloading'
            /*
            TODO - check if helps with UI responsiveness,
            letting only folders use FileDownloaderBinder to check
            FileDataStorageManager storageManager =
            new FileDataStorageManager(account, getContentResolver());
            file.setDownloading(true);
            storageManager.saveFile(file);
            */

            sendBroadcastNewDownload(newDownload, putResult.second);

        } catch (IllegalArgumentException e) {
            Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
            return START_NOT_STICKY;
        }

        if (requestedDownloads.size() > 0) {
            Message msg = mServiceHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = requestedDownloads;
            mServiceHandler.sendMessage(msg);
        }
        //}
    }

    return START_NOT_STICKY;
}

From source file:com.cerema.cloud2.files.services.FileDownloader.java

/**
 * Entry point to add one or several files to the queue of downloads.
 *
 * New downloads are added calling to startService(), resulting in a call to this method.
 * This ensures the service will keep on working although the caller activity goes away.
 *///  w  w w . ja va  2s .c o  m
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log_OC.d(TAG, "Starting command with id " + startId);

    if (!intent.hasExtra(EXTRA_ACCOUNT) || !intent.hasExtra(EXTRA_FILE)) {
        Log_OC.e(TAG, "Not enough information provided in intent");
        return START_NOT_STICKY;
    } else {
        final Account account = intent.getParcelableExtra(EXTRA_ACCOUNT);
        final OCFile file = intent.getParcelableExtra(EXTRA_FILE);
        AbstractList<String> requestedDownloads = new Vector<String>();
        try {
            DownloadFileOperation newDownload = new DownloadFileOperation(account, file);
            newDownload.addDatatransferProgressListener(this);
            newDownload.addDatatransferProgressListener((FileDownloaderBinder) mBinder);
            Pair<String, String> putResult = mPendingDownloads.putIfAbsent(account, file.getRemotePath(),
                    newDownload);
            if (putResult != null) {
                String downloadKey = putResult.first;
                requestedDownloads.add(downloadKey);
                sendBroadcastNewDownload(newDownload, putResult.second);
            } // else, file already in the queue of downloads; don't repeat the request

        } catch (IllegalArgumentException e) {
            Log_OC.e(TAG, "Not enough information provided in intent: " + e.getMessage());
            return START_NOT_STICKY;
        }

        if (requestedDownloads.size() > 0) {
            Message msg = mServiceHandler.obtainMessage();
            msg.arg1 = startId;
            msg.obj = requestedDownloads;
            mServiceHandler.sendMessage(msg);
        }
        //}
    }

    return START_NOT_STICKY;
}

From source file:org.jabsorb.ng.serializer.impl.ListSerializer.java

@Override
public Object unmarshall(final SerializerState state, final Class<?> clazz, final Object o)
        throws UnmarshallException {

    final JSONObject jso = (JSONObject) o;
    String java_class;

    // Hint check
    try {//ww  w  . jav  a 2s.  c o m
        java_class = jso.getString("javaClass");
    } catch (final JSONException e) {
        throw new UnmarshallException("Could not read javaClass", e);
    }

    if (java_class == null) {
        throw new UnmarshallException("no type hint");
    }

    // Create the list
    final AbstractList<Object> ablist;
    if (java_class.equals("java.util.List") || java_class.equals("java.util.AbstractList")
            || java_class.equals("java.util.ArrayList")) {
        ablist = new ArrayList<Object>();
    } else if (java_class.equals("java.util.LinkedList")) {
        ablist = new LinkedList<Object>();
    } else if (java_class.equals("java.util.Vector")) {
        ablist = new Vector<Object>();
    } else {
        throw new UnmarshallException("not a List");
    }

    // Parse the JSON list
    JSONArray jsonlist;
    try {
        jsonlist = jso.getJSONArray("list");

    } catch (final JSONException e) {
        throw new UnmarshallException("Could not read list: " + e.getMessage(), e);
    }

    if (jsonlist == null) {
        throw new UnmarshallException("list missing");
    }

    state.setSerialized(o, ablist);

    int idx = 0;
    try {
        for (idx = 0; idx < jsonlist.length(); idx++) {
            ablist.add(ser.unmarshall(state, null, jsonlist.get(idx)));
        }
    } catch (final UnmarshallException e) {
        throw new UnmarshallException("element " + idx + " " + e.getMessage(), e);
    } catch (final JSONException e) {
        throw new UnmarshallException("element " + idx + " " + e.getMessage(), e);
    }
    return ablist;
}