Example usage for java.util Vector firstElement

List of usage examples for java.util Vector firstElement

Introduction

In this page you can find the example usage for java.util Vector firstElement.

Prototype

public synchronized E firstElement() 

Source Link

Document

Returns the first component (the item at index 0 ) of this vector.

Usage

From source file:com.github.igor_kudryashov.utils.notes.NotesDocument.java

/**
 * As lotus.domino.Document.replaceItemValue() method modifies the value of the document Lotus
 * Notes, but only if the new value is different from existing
 *
 * @param item//from ww w. j  a v a 2s. co m
 *            - the lotus.Domino.Item object.
 * @param value
 *            - the new value of Notes item.
 * @return <code>true</code> if the value has been updated, <code>false</code> otherwise.
 * @throws NotesException
 */
@SuppressWarnings("unchecked")
public static boolean updateItemValue(Item item, Object value) throws NotesException {
    Vector<Object> vec = item.getValues();
    if (value.getClass().getName().contains("Vector")) {
        if (vec.equals(value)) {
            return false;
        } else {
            item.setValues((Vector<Object>) value);
        }
    } else {
        if (vec.size() == 1) {
            if (vec.firstElement() instanceof Number) {
                // because lotus.docmino.Item.getValues() alvays return java.util.Vector with
                // Double elements for Numeric items,
                // value parameter must be converted to Double
                MutableDouble md = new MutableDouble((Number) value);
                if (Double.compare((Double) vec.firstElement(), md.getValue()) == 0) {
                    return false;
                }
            } else if (vec.firstElement() instanceof String) {
                if (vec.firstElement().equals((String) value)) {
                    return false;
                }
            } else {
                if (vec.firstElement().equals(value)) {
                    return false;
                }
            }
        }
        vec = new Vector<Object>();
        vec.add(value);
        item.setValues(vec);
    }

    return true;

}

From source file:takatuka.classreader.dataObjs.attribute.ExceptionTableEntry.java

void restorePCInformation(BHInstruction inst) throws Exception {
    if (inst instanceof InstructionsCombined) {
        InstructionsCombined instComb = (InstructionsCombined) inst;
        Vector<BHInstruction> instr = instComb.getSimpleInstructions();
        updatePCInformation(instr.firstElement().getInstructionId(), inst.getOffSet());
        updatePCInformation(instr.lastElement().getInstructionId(), inst.getOffSet());
    } else {/*from   w w  w  .ja v a 2 s  . co m*/
        updatePCInformation(inst.getInstructionId(), inst.getOffSet());
    }
}

From source file:io.calq.android.analytics.ApiDispatcher.java

/**
 * Builds a payload based on the batch content.
 *///from   www  .  j  a va 2 s . c  o m
private StringEntity buildPayload(Vector<QueuedApiCall> batch) throws UnsupportedEncodingException {
    // Single item?
    if (batch.size() == 1) {
        return new StringEntity(batch.firstElement().getPayload(), "UTF-8");
    } else {
        StringBuilder payload = new StringBuilder();
        payload.append("[");
        for (int n = 0; n < batch.size(); n++) {
            if (n > 0) {
                payload.append(",");
            }
            QueuedApiCall apiCall = batch.get(n);
            payload.append(apiCall.getPayload());
        }
        payload.append("]");
        return new StringEntity(payload.toString(), "UTF-8");
    }
}

From source file:org.bibsonomy.webapp.filters.ContentNegotiationFilter.java

/**
 * Supports content negotiation using the HTTP accept header.
 *  //w  ww  .  ja va  2  s  .  c om
 * Extracts the preferred response format from the accept header and returns
 * the corresponding URL path for the webapp. Only the format with the 
 * highest priority is regarded. Thus, this method is much stricter than
 * {@link HeaderUtils#getResponseFormat(String, int)}. 
 * <br/> 
 * If no matching URL path could be found, <code>null</code> is returned.
 *   
 * 
 * @param acceptHeader - the "Accept" header of the HTTP request.
 * @return The 
 */
private String getResponseFormat(final String acceptHeader) {
    if (!present(acceptHeader))
        return null;
    /*
     * extract ordered list of preferred types
     */
    final SortedMap<Double, Vector<String>> preferredTypes = org.bibsonomy.rest.utils.HeaderUtils
            .getPreferredTypes(acceptHeader);
    /*
     * extract highest ranked formats
     */
    final Vector<String> firstFormats = preferredTypes.get(preferredTypes.firstKey());
    /*
     * return best match
     */
    return FORMAT_MAPPING.get(firstFormats.firstElement());
}

From source file:org.apache.jcs.auxiliary.lateral.xmlrpc.LateralXMLRPCReceiverConnection.java

/**
 * Description of the Method/*w w w .ja v a  2s  .c om*/
 *
 * @return
 * @param method
 * @param params
 */
public Object execute(String method, Vector params) {
    // do nothing with method name for now, later the action code can be
    // the method name
    LateralElementDescriptor led = null;
    try {
        // get the LED out of the params
        byte[] data = (byte[]) params.firstElement();
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        BufferedInputStream bis = new BufferedInputStream(bais);
        ObjectInputStream ois = new ObjectInputStream(bis);
        try {
            led = (LateralElementDescriptor) ois.readObject();
        } finally {
            ois.close();
        }
    } catch (Exception e) {
        log.error(e);
    }
    // this should start a thread fo non gets?
    return executeImpl(led);
}

From source file:org.kepler.ssh.LocalDelete.java

public boolean deleteFiles(String mask, boolean recursive) throws ExecException {

    if (mask == null)
        return true;
    if (mask.trim() == "")
        return true;

    // pre-test to conform to 'rm -rf': if the mask ends for . or ..
    // it must throw an error
    String name = new File(mask).getName();
    if (name.equals(".") || name.equals("..")) {
        throw new ExecException("Directories like . or ..  are not allowed to be removed: " + mask);
    }/*  w ww .ja  va  2  s . c  om*/

    // split the mask into a vector of single masks
    // e.g. a/b*d/c?? into (a, b*d, c??)
    Vector splittedMask = splitMask(mask);
    // sure it has at least one element: .
    String path = (String) splittedMask.firstElement();
    splittedMask.remove(0);

    return delete(new File(path), splittedMask, recursive);
}

From source file:edu.duke.cabig.c3pr.domain.scheduler.runtime.job.CCTSNotificationMessageJob.java

/**
 * @param queue/* w  w  w  . j  a v a  2 s  .  c  om*/
 */
private void process(final Vector<CCTSNotification> queue) {
    boolean done;
    do {
        done = true;
        CCTSNotification notification = null;
        try {
            notification = queue.firstElement();
        } catch (NoSuchElementException e) {
        }
        if (notification == null) {
            log.debug("CCTS notification queue is empty; messages, if any, have been processed.");
        } else
            try {
                process(notification);
                queue.remove(notification);
                done = false;
            } catch (ESBCommunicationException e) {
                log.error(ExceptionUtils.getFullStackTrace(e));
                log.error("Processing of a CCTS notification failed: " + notification);
                log.error("Failed notification will be put back into the queue for another re-try later.");
            } catch (Exception e) {
                log.error(ExceptionUtils.getFullStackTrace(e));
                log.error("Processing of a CCTS notification failed: " + notification);
                log.error(
                        "This error indicates a problem with the message itself. It will be removed from the queue. No further delivery attempts will be made.");
                queue.remove(notification);
                done = false;
            }
    } while (!done);
}

From source file:opendap.aws.glacier.Vault.java

public void purgeDuplicatesOLD() throws IOException {

    VaultInventory inventory = getInventory();

    HashMap<String, Vector<GlacierArchive>> archives = new HashMap<String, Vector<GlacierArchive>>();

    GregorianCalendar gc = new GregorianCalendar();

    Vector<GlacierArchive> tuples;
    for (GlacierArchive gar : inventory.getArchiveList()) {
        String resourceID = gar.getResourceId();
        tuples = archives.get(resourceID);
        if (tuples == null)
            tuples = new Vector<GlacierArchive>();
        tuples.add(gar);/*from  w w  w.  ja  v a2s .  co m*/
    }

    for (Vector<GlacierArchive> archiveTuple : archives.values()) {
        if (archiveTuple.size() > 1) {
            GlacierArchive newest = archiveTuple.firstElement();
            for (GlacierArchive gar : archiveTuple) {
                if (newest.getCreationDate().getTime() > gar.getCreationDate().getTime()) {
                    deleteArchive(gar.getArchiveId());
                } else {
                    deleteArchive(newest.getArchiveId());
                    newest = gar;
                }
            }
        }
    }

}

From source file:io.calq.android.analytics.ApiDispatcher.java

/**
 * Dispatches the given API call to the remote Calq server.
 * @param batch             The batch of API calls to dispatch.
 * @throws ApiException // ww w.  ja  v  a 2  s . c  om
 * @returns if this was successful.
 */
public boolean dispatch(Vector<QueuedApiCall> batch) throws ApiException {

    // At some point we should switch from the Apache client to HttpURLConnection on clients that support it.
    //   See: http://android-developers.blogspot.co.uk/2011/09/androids-http-clients.html

    try {
        HttpClient httpclient = new DefaultHttpClient();

        HttpPost post = new HttpPost(getEndpointUrl(batch.firstElement()));
        post.setHeader("Content-type", "application/json");
        post.setEntity(buildPayload(batch));
        HttpResponse response = httpclient.execute(post);

        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode >= 500) {
            // 500s we want to retry later
            return false;
        } else if (statusCode != HttpStatus.SC_OK) {

            // Try get response for other codes, might have API error in it
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                out.close();
                String responseString = out.toString();

                JSONObject json = new JSONObject(responseString);
                if (json.has("error")) {
                    throw (new ApiException(json.getString("error")));
                } else {
                    throw (new ApiException("Unknown error occured during API call."));
                }
            }
        }
    } catch (ClientProtocolException e) {
        // Failed, but don't know why. Signal failed for re-queue
        return false;
    } catch (IOException e) {
        // Failed, but don't know why. Signal failed for re-queue
        return false;
    } catch (JSONException e) {
        // Failed, but don't know why. Signal failed for re-queue
        return false;
    }

    // All OK. This call can be removed from local queue
    return true;
}

From source file:it.sasabz.android.sasabus.fragments.OnlineSelectFragment.java

public void fillSpinner(Vector<XMLStation> from_list, Vector<XMLStation> to_list) {
    String datetimestring = "";
    SimpleDateFormat simple = new SimpleDateFormat("dd.MM.yyyy HH:mm");
    datetimestring = simple.format(datum);

    if (from_list.size() == 1 && to_list.size() == 1) {
        Log.v("Check", "Check");
        XMLStation from = from_list.firstElement();
        XMLStation to = to_list.firstElement();

        getConnectionList(from, to, datetimestring);
    } else if (from_list.size() == 1 && to.contains(to_list.get(0).getName())) {
        Log.v("Check", "Check");
        XMLStation from = from_list.firstElement();
        XMLStation to = to_list.firstElement();

        getConnectionList(from, to, datetimestring);
    } else if (to_list.size() == 1 && from.contains(from_list.get(0).getName())) {
        Log.v("Check", "Check");
        XMLStation from = from_list.firstElement();
        XMLStation to = to_list.firstElement();

        getConnectionList(from, to, datetimestring);
    } else {/*  w  w w  . j  av a  2 s  . c  om*/

        TextView datetime = (TextView) result.findViewById(R.id.time);

        datetime.setText(datetimestring);

        progress.dismiss();

        if (from_list == null || to_list == null) {
            Toast.makeText(getContext(), R.string.online_connection_error, Toast.LENGTH_LONG).show();
            getFragmentManager().popBackStack();
            return;
        }

        from_spinner = (Spinner) result.findViewById(R.id.from_spinner);
        to_spinner = (Spinner) result.findViewById(R.id.to_spinner);

        // Create an ArrayAdapter using the string array and a default spinner layout
        MyXMLStationListAdapter from_adapter = new MyXMLStationListAdapter(getContext(), from_list);
        // Create an ArrayAdapter using the string array and a default spinner layout
        MyXMLStationListAdapter to_adapter = new MyXMLStationListAdapter(getContext(), to_list);

        // Apply the adapter to the spinner
        from_spinner.setAdapter(from_adapter);
        // Apply the adapter to the spinner
        to_spinner.setAdapter(to_adapter);

        search = (Button) result.findViewById(R.id.search);

        search.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                XMLStation from = (XMLStation) from_spinner.getSelectedItem();
                XMLStation to = (XMLStation) to_spinner.getSelectedItem();
                TextView datetime = (TextView) result.findViewById(R.id.time);
                getConnectionList(from, to, datetime.getText().toString());
            }
        });
        result.setVisibility(View.VISIBLE);
    }
}