Example usage for java.util ArrayList isEmpty

List of usage examples for java.util ArrayList isEmpty

Introduction

In this page you can find the example usage for java.util ArrayList isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:com.dtolabs.rundeck.core.execution.workflow.steps.NodeDispatchStepExecutor.java

/**
 * Return a StepExecutionResult based on the DispatcherResult, that can later be extracted.
 *//*www.  j  av a2s . c o m*/
public static StepExecutionResult wrapDispatcherResult(final DispatcherResult dispatcherResult) {
    final StepExecutionResultImpl result;
    if (dispatcherResult.isSuccess()) {
        result = NodeDispatchStepExecutorResult.success(dispatcherResult);
    } else {
        result = NodeDispatchStepExecutorResult.failure(dispatcherResult, null, Reason.NodeDispatchFailure,
                "Node dispatch failed");
        //extract failed nodes
        ArrayList<String> nodeNames = new ArrayList<String>();
        for (String nodeName : dispatcherResult.getResults().keySet()) {
            NodeStepResult nodeStepResult = dispatcherResult.getResults().get(nodeName);
            if (!nodeStepResult.isSuccess()) {
                nodeNames.add(nodeName);
            }
        }
        if (!nodeNames.isEmpty()) {
            result.getFailureData().put(FAILURE_DATA_FAILED_NODES, StringUtils.join(nodeNames, ","));
        }
    }
    return result;
}

From source file:com.cisco.oss.foundation.message.HornetQMessagingFactory.java

private static void printHQVersion(final Map<String, Map<String, String>> serverConnections,
        final ArrayList<String> serverConnectionKeys) {

    if (serverConnectionKeys != null && !serverConnectionKeys.isEmpty()) {

        String host = serverConnections.get(serverConnectionKeys.get(0)).get("host");
        String port = serverConnections.get(serverConnectionKeys.get(0)).get("jmxPort");
        if (port == null) {
            port = "3900";
        }//from w  ww.j a  va  2 s .  com

        printHQVersion(host, port);
    }
}

From source file:com.icesoft.faces.facelets.D2DFaceletViewHandler.java

/**
 * For performance reasons, when there aren't id collisions
 * we want this to be as fast as possible.  When there are
 * collisions, then we'll take some extra time to do a second
 * pass to provide more information/*w  w w .  j  av  a  2  s  .c om*/
 * It could have all been done in one pass, but that would penalise
 * the typical case, where there are not duplicate ids
 *
 * @param comp UIComponent to recurse down through, searching for
 *             duplicate ids. Should be the UIViewRoot
 */
protected static void verifyUniqueComponentIds(FacesContext context, UIComponent comp) {
    if (!log.isDebugEnabled())
        return;

    HashMap ids = new HashMap(512);
    ArrayList duplicateIds = new ArrayList(256);
    quicklyDetectDuplicateComponentIds(comp, ids, duplicateIds);

    if (!duplicateIds.isEmpty()) {
        HashMap duplicateIds2comps = new HashMap(512);
        compileDuplicateComponentIds(comp, duplicateIds2comps, duplicateIds);
        reportDuplicateComponentIds(context, duplicateIds2comps, duplicateIds);
    }
}

From source file:com.oeg.oops.VocabUtils.java

/**
 * The reason why the model is not returned is because I want to be able to close it later.
 * @param model//from   w  w w.  j a  v  a2s.  c  om
 * @param ontoPath
 * @param ontoURL
 */
private static void readOnlineModel(OntModel model, Vocabulary v) {
    ArrayList<String> s = v.getSupportedSerializations();
    if (s.isEmpty()) {
        System.err.println("Error: no serializations available!!");
        Report.getInstance().addErrorForVocab(v.getUri(), TextConstants.Error.NO_SERIALIZATIONS_FOR_VOCAB);
    } else {
        if (s.contains("application/rdf+xml")) {
            model.read(v.getUri(), null, "RDF/XML");
        } else if (s.contains("text/turtle")) {
            model.read(v.getUri(), null, "TURTLE");
        } else if (s.contains("text/n3")) {
            model.read(v.getUri(), null, "N3");
        } else {
            //try the application/rdf+xml anyways. It is the most typical,
            //and sometimes it may not have been recognized because they
            //don't add a content header
            try {
                model.read(v.getUri(), null, "RDF/XML");
                v.getSupportedSerializations().add("application/rdf+xml");
            } catch (Exception e) {
                System.err.println("Error: no serializations available!!");
                Report.getInstance().addErrorForVocab(v.getUri(),
                        TextConstants.Error.NO_SERIALIZATIONS_FOR_VOCAB);
            }
        }
        //            System.out.println("Vocab "+v.getUri()+" loaded successfully!");
    }
}

From source file:vocab.VocabUtils.java

/**
 * The reason why the model is not returned is because I want to be able to close it later.
 * @param model// w  w  w  .j  av  a 2 s  . co  m
 * @param ontoPath
 * @param ontoURL 
 */
private static void readOnlineModel(OntModel model, Vocabulary v) {
    ArrayList<String> s = v.getSupportedSerializations();
    if (s.isEmpty()) {
        System.err.println("Error: no serializations available!!");
        Report.getInstance().addErrorForVocab(v.getUri(), TextConstants.Error.NO_SERIALIZATIONS_FOR_VOCAB);
        //try the application/rdf+xml anyways. It is the most typical, 
        //and sometimes it may not have been recognized because they 
        //don't add a content header
        try {
            model.read(v.getUri(), null, "RDF/XML");
            v.getSupportedSerializations().add("application/rdf+xml");
        } catch (Exception e) {
            System.err.println("Error: no serializations available!!");
            Report.getInstance().addErrorForVocab(v.getUri(), TextConstants.Error.NO_SERIALIZATIONS_FOR_VOCAB);
        }
    } else {
        if (s.contains("application/rdf+xml")) {
            doContentNegotiation(model, v, "application/rdf+xml", "RDF/XML");
        } else if (s.contains("text/turtle")) {
            doContentNegotiation(model, v, "text/turtle", "TURTLE");
        } else if (s.contains("text/n3")) {
            doContentNegotiation(model, v, "text/n3", "N3");
        }
        //            System.out.println("Vocab "+v.getUri()+" loaded successfully!");
    }
}

From source file:com.google.sample.castcompanionlibrary.utils.Utils.java

/**
 * Builds and returns a {@link MediaInfo} that was wrapped in a {@link Bundle} by
 * <code>fromMediaInfo</code>.
 *
 * @param wrapper/*from   w  w w  .ja  v a 2  s.c o m*/
 * @return
 * @see <code>fromMediaInfo()</code>
 */
public static MediaInfo toMediaInfo(Bundle wrapper) {
    if (null == wrapper) {
        return null;
    }

    MediaMetadata metaData = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);

    metaData.putString(MediaMetadata.KEY_SUBTITLE, wrapper.getString(MediaMetadata.KEY_SUBTITLE));
    metaData.putString(MediaMetadata.KEY_TITLE, wrapper.getString(MediaMetadata.KEY_TITLE));
    metaData.putString(MediaMetadata.KEY_STUDIO, wrapper.getString(MediaMetadata.KEY_STUDIO));
    ArrayList<String> images = wrapper.getStringArrayList(KEY_IMAGES);
    if (null != images && !images.isEmpty()) {
        for (String url : images) {
            Uri uri = Uri.parse(url);
            metaData.addImage(new WebImage(uri));
        }
    }
    String customDataStr = wrapper.getString(KEY_CUSTOM_DATA);
    JSONObject customData = null;
    if (!TextUtils.isEmpty(customDataStr)) {
        try {
            customData = new JSONObject(customDataStr);
        } catch (JSONException e) {
            LOGE(TAG, "Failed to deserialize the custom data string: custom data= " + customDataStr);
        }
    }
    List<MediaTrack> mediaTracks = null;
    if (wrapper.getString(KEY_TRACKS_DATA) != null) {
        try {
            JSONArray jsonArray = new JSONArray(wrapper.getString(KEY_TRACKS_DATA));
            mediaTracks = new ArrayList<MediaTrack>();
            if (jsonArray != null && jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject jsonObj = (JSONObject) jsonArray.get(i);
                    MediaTrack.Builder builder = new MediaTrack.Builder(jsonObj.getLong(KEY_TRACK_ID),
                            jsonObj.getInt(KEY_TRACK_TYPE));
                    if (jsonObj.has(KEY_TRACK_NAME)) {
                        builder.setName(jsonObj.getString(KEY_TRACK_NAME));
                    }
                    if (jsonObj.has(KEY_TRACK_SUBTYPE)) {
                        builder.setSubtype(jsonObj.getInt(KEY_TRACK_SUBTYPE));
                    }
                    if (jsonObj.has(KEY_TRACK_CONTENT_ID)) {
                        builder.setContentId(jsonObj.getString(KEY_TRACK_CONTENT_ID));
                    }
                    if (jsonObj.has(KEY_TRACK_LANGUAGE)) {
                        builder.setLanguage(jsonObj.getString(KEY_TRACK_LANGUAGE));
                    }
                    if (jsonObj.has(KEY_TRACKS_DATA)) {
                        builder.setCustomData(new JSONObject(jsonObj.getString(KEY_TRACKS_DATA)));
                    }
                    mediaTracks.add(builder.build());
                }
            }
        } catch (JSONException e) {
            LOGE(TAG, "Failed to build media tracks from the wrapper bundle", e);
        }
    }
    return new MediaInfo.Builder(wrapper.getString(KEY_URL)).setStreamType(wrapper.getInt(KEY_STREAM_TYPE))
            .setContentType(wrapper.getString(KEY_CONTENT_TYPE)).setMetadata(metaData).setCustomData(customData)
            .setMediaTracks(mediaTracks).setStreamDuration(wrapper.getLong(KEY_STREAM_DURATION)).build();
}

From source file:be.ac.ucl.lfsab1509.llncampus.UCLouvain.java

/**
 * Launch the download of the courses list and store them in the database.
 * // w  w w .  ja v  a  2  s .  com
 * @param context
 *          Application context.
 * @param username
 *          UCL global user identifier.
 * @param password
 *          UCL password.
 * @param end
 *          Runnable to be executed at the end of the download.
 * @param mHandler
 *          Handler to manage messages and threads.
 *          
 */
public static void downloadCoursesFromUCLouvain(final LLNCampusActivity context, final String username,
        final String password, final Runnable end, final Handler mHandler) {
    Time t = new Time();
    t.setToNow();
    int year = t.year;
    // A new academic year begin in September (8th month on 0-based count).
    if (t.month < 8) {
        year--;
    }
    final int academicYear = year;

    mHandler.post(new Runnable() {

        public void run() {

            final ProgressDialog mProgress = new ProgressDialog(context);
            mProgress.setCancelable(false);
            mProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            mProgress.setMax(100);
            mProgress.setMessage(context.getString(R.string.connection));
            mProgress.show();

            new Thread(new Runnable() {
                /**
                 * Set the progress to the value n and show the message nextStep
                 * @param n
                 *          The progress value.
                 * @param nextStep
                 *          The message to show (indicate the next step to be processed).
                 */
                public void progress(final int n, final String nextStep) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            mProgress.setProgress(n);
                            mProgress.setMessage(nextStep);
                        }
                    });
                    Log.d("UCLouvain", nextStep);
                }

                /**
                 * Notify to the user an error.
                 * 
                 * @param msg
                 *          The message to show to the user.
                 */
                public void sendError(String msg) {
                    notify(context.getString(R.string.error) + " :" + msg);
                    mProgress.cancel();
                }

                /**
                 * Notify to the user a message.
                 * 
                 * @param msg
                 *          The message to show to the user.
                 */
                public void notify(final String msg) {
                    mHandler.post(new Runnable() {
                        public void run() {
                            context.notify(msg);
                        }
                    });
                }

                public void run() {
                    progress(0, context.getString(R.string.connection_ucl));
                    UCLouvain uclouvain = new UCLouvain(username, password);

                    progress(20, context.getString(R.string.fetch_info));
                    ArrayList<Offer> offers = uclouvain.getOffers(academicYear);

                    if (offers == null || offers.isEmpty()) {
                        sendError(context.getString(R.string.error_academic_year) + academicYear);
                        return;
                    }

                    int i = 40;
                    ArrayList<Course> courses = new ArrayList<Course>();
                    for (Offer o : offers) {
                        progress(i, context.getString(R.string.get_courses) + o.getOfferName());
                        ArrayList<Course> offerCourses = uclouvain.getCourses(o);
                        if (offerCourses != null && !offerCourses.isEmpty()) {
                            courses.addAll(offerCourses);
                        } else {
                            Log.e("CoursListEditActivity", "Error : No course for offer [" + o.getOfferCode()
                                    + "] " + o.getOfferName());
                        }
                        i += (int) (30. / offers.size());
                    }

                    if (courses.isEmpty()) {
                        sendError(context.getString(R.string.courses_empty));
                        return;
                    }

                    // Remove old courses.
                    progress(70, context.getString(R.string.cleaning_db));
                    LLNCampus.getDatabase().delete("Courses", "", null);
                    LLNCampus.getDatabase().delete("Horaire", "", null);

                    // Add new data.
                    i = 80;
                    for (Course c : courses) {
                        progress(i, context.getString(R.string.add_courses_db));
                        ContentValues cv = new ContentValues();
                        cv.put("CODE", c.getCourseCode());
                        cv.put("NAME", c.getCoursName());

                        LLNCampus.getDatabase().insert("Courses", cv);
                        i += (int) (20. / courses.size());
                    }

                    progress(100, context.getString(R.string.end));
                    mProgress.cancel();
                    mHandler.post(end);
                }
            }).start();
        }
    });
}

From source file:eu.learnpad.verification.plugin.pn.modelcheckers.LOLA.java

public static String[] getCounterExample(String lolaOutput, PetriNet pn) throws Exception {
    if (!isPropertyVerified(lolaOutput))
        throw new Exception("ERROR: The property is not verified so a counter example can not exist.");

    if (lolaOutput == null || lolaOutput.isEmpty())
        return new String[0];

    String newLineChar = "\r\n";
    if (!lolaOutput.contains("\r\n"))
        newLineChar = "\n";

    ArrayList<String> transitionTraceList = new ArrayList<String>();
    String[] traceRowList = lolaOutput.split(newLineChar);
    for (String traceRow : traceRowList)
        if (!(traceRow.contains(":") || traceRow.startsWith("===") || traceRow.startsWith("lola: ")
                || traceRow.startsWith("NOSTATE")))
            transitionTraceList.add(traceRow);

    if (transitionTraceList.isEmpty())
        return new String[0];

    ArrayList<String> placeTraceList = new ArrayList<String>();
    PetriNet pnc = pn.clonePN();//ww w .j  a v a2s  .  c  o  m
    ArrayList<PL> placeList = pnc.getPlaceList_safe();

    if (pnc.getEnabledTransitions()
            .contains(pnc.getTransition(transitionTraceList.get(transitionTraceList.size() - 1)))) {
        //rigirare l'output
        ArrayList<String> tmpList = new ArrayList<String>();
        for (int i = transitionTraceList.size() - 1; i >= 0; i--)
            tmpList.add(transitionTraceList.get(i));
        transitionTraceList = tmpList;
    }

    for (String transitionTrace : transitionTraceList) {
        int[] currentMark = pnc.getCurrentMark();
        String places = "";
        for (int i = 0; i < currentMark.length; i++)
            if (currentMark[i] != 0)
                places += placeList.get(i).name + " ";
        placeTraceList.add(places);

        pnc.fireTransition(pnc.getTransition(transitionTrace));
    }
    {
        int[] currentMark = pnc.getCurrentMark();
        String places = "";
        for (int i = 0; i < currentMark.length; i++)
            if (currentMark[i] != 0)
                places += placeList.get(i).name + " ";
        placeTraceList.add(places);
    }

    String[] ret = new String[placeTraceList.size()];
    placeTraceList.toArray(ret);
    return ret;
}

From source file:com.vk.sdk.payments.VKIInAppBillingService.java

private static Receipt getReceipt(@NonNull final Object iInAppBillingService, final int apiVersion,
        @NonNull final String packageName, @NonNull final String receiptOriginal)
        throws JSONException, RemoteException {
    JSONObject objectReceipt = new JSONObject(receiptOriginal);

    Receipt receipt = new Receipt();
    receipt.receiptData = receiptOriginal;
    receipt.quantity = 1;/*from w ww.j  a  v  a 2s.  com*/

    String sku = objectReceipt.getString(PRODUCT_ID);

    ArrayList<String> skuList = new ArrayList<>();
    skuList.add(sku);

    Bundle queryBundle = new Bundle();
    queryBundle.putStringArrayList(GET_SKU_DETAILS_ITEM_LIST, skuList);
    Bundle responseBundle = getSkuDetails(iInAppBillingService, apiVersion, packageName, "inapp", queryBundle);

    ArrayList<String> responseList = responseBundle.getStringArrayList(RESPONSE_GET_SKU_DETAILS_LIST);
    if (responseList != null && !responseList.isEmpty()) {
        try {
            JSONObject object = new JSONObject(responseList.get(0));
            receipt.priceValue = Float.parseFloat(object.optString(SKU_DETAIL_AMOUNT_MICROS)) / 1000000f;
            receipt.currency = object.optString(SKU_DETAIL_PRICE_CURRENCY_CODE);
        } catch (JSONException e) {
            // nothing
        }
    }
    return receipt;
}

From source file:com.intel.cosbench.driver.random.HistogramIntGenerator.java

private static HistogramIntGenerator tryParse(String pattern) {
    pattern = StringUtils.substringBetween(pattern, "(", ")");
    String[] args = StringUtils.split(pattern, ',');
    ArrayList<Bucket> bucketsList = new ArrayList<Bucket>();
    for (String arg : args) {
        String[] values = StringUtils.split(arg, '|');
        if (values.length != 3) {
            throw new IllegalArgumentException();
        }//from w ww  .  j av  a 2s.  c  o  m
        int lower = Integer.parseInt(values[0]);
        int upper = Integer.parseInt(values[1]);
        int weight = Integer.parseInt(values[2]);
        bucketsList.add(new Bucket(lower, upper, weight));
    }
    if (bucketsList.isEmpty()) {
        throw new IllegalArgumentException();
    }
    Collections.sort(bucketsList, new LowerComparator());
    final Bucket[] buckets = bucketsList.toArray(new Bucket[0]);
    int cumulativeWeight = 0;
    for (Bucket bucket : buckets) {
        cumulativeWeight += bucket.weight;
        bucket.cumulativeWeight = cumulativeWeight;
    }
    return new HistogramIntGenerator(buckets);
}