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.ccserver.digital.controller.CreditCardApplicationDocumentControllerTest.java

@Test
public void downloadDocumentWithEmptyReturnedObject() {

    Mockito.when(mockDocService.getDocumentsByApplicationId(1L))
            .thenReturn(new ArrayList<CreditCardApplicationDocumentDTO>());
    ResponseEntity<?> response = mockDocController.downloadDocumentByAppId(1L);

    // assert//from   ww w  .  java2 s. c o  m
    Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
    ArrayList<CreditCardApplicationDocumentDTO> docs = (ArrayList<CreditCardApplicationDocumentDTO>) response
            .getBody();
    Assert.assertTrue(docs.isEmpty());
}

From source file:io.github.redpanda4552.SimpleEgg.util.LoreExtractor.java

/**
 * Applies attributes stored in a lore ArrayList to a LivingEntity. In the
 * case of proper, untampered SimpleEggs, all instanceof checks should have
 * been previously handled by the LorePackager, so no type checking should
 * be required prior to calling this method, and by extension any type
 * compatibility issues will be an indication of tampering. Null Entities
 * will throw an IllegalArgumentException.
 * @param lore - The lore ArrayList to apply.
 * @param livingEntity - The Entity to assemble a lore for.
 * @throws IllegalArgumentException If entity parameter is null
 *///from  w w  w. j a va2s .c om
public LoreExtractor(ArrayList<String> lore, LivingEntity livingEntity) throws IllegalArgumentException {
    if (lore == null || lore.isEmpty()) {
        throw new IllegalArgumentException("Can't apply null/empty lore!");
    }

    if (livingEntity == null) {
        throw new IllegalArgumentException("Can't apply lore to a null entity!");
    }

    attributeMap = new HashMap<String, String>();

    for (String str : lore) {
        str = ChatColor.stripColor(str);
        String[] strArr = str.split(": ");
        attributeMap.put(strArr[0], strArr[1]);
    }

    livingEntity(livingEntity);

    if (livingEntity instanceof Ageable) {
        ageable((Ageable) livingEntity);

        if (livingEntity instanceof Sheep) {
            sheep((Sheep) livingEntity);
        } else if (livingEntity instanceof Pig) {
            pig((Pig) livingEntity);
        } else if (livingEntity instanceof Rabbit) {
            rabbit((Rabbit) livingEntity);
        } else if (livingEntity instanceof Villager) {
            villager((Villager) livingEntity);
        } else if (livingEntity instanceof Tameable) {
            tameable((Tameable) livingEntity);

            if (livingEntity instanceof AbstractHorse) {
                abstractHorse((AbstractHorse) livingEntity);

                if (livingEntity instanceof Horse) {
                    horse((Horse) livingEntity);
                } else if (livingEntity instanceof ChestedHorse) {
                    chestedHorse((ChestedHorse) livingEntity);

                    if (livingEntity instanceof Llama) {
                        llama((Llama) livingEntity);
                    }
                }
            } else if (livingEntity instanceof Sittable) {
                sittable((Sittable) livingEntity);

                if (livingEntity instanceof Wolf) {
                    wolf((Wolf) livingEntity);
                } else if (livingEntity instanceof Ocelot) {
                    ocelot((Ocelot) livingEntity);
                } else if (livingEntity instanceof Parrot) {
                    parrot((Parrot) livingEntity);
                }
            }
        }
    } else if (livingEntity instanceof Slime) {
        slime((Slime) livingEntity);
    } else if (livingEntity instanceof Creeper) {
        creeper((Creeper) livingEntity);
    } else if (livingEntity instanceof Zombie) {
        zombie((Zombie) livingEntity);

        if (livingEntity instanceof PigZombie) {
            pigZombie((PigZombie) livingEntity);
        } else if (livingEntity instanceof ZombieVillager) {
            zombieVillager((ZombieVillager) livingEntity);
        }
    } else if (livingEntity instanceof Spellcaster) {
        spellCaster((Spellcaster) livingEntity);
    } else if (livingEntity instanceof IronGolem) {
        ironGolem((IronGolem) livingEntity);
    } else if (livingEntity instanceof Snowman) {
        snowman((Snowman) livingEntity);
    } else if (livingEntity instanceof Enderman) {
        enderman((Enderman) livingEntity);
    } else if (livingEntity instanceof Phantom) {
        phantom((Phantom) livingEntity);
    } else if (livingEntity instanceof PufferFish) {
        pufferFish((PufferFish) livingEntity);
    } else if (livingEntity instanceof TropicalFish) {
        tropicalFish((TropicalFish) livingEntity);
    }

    if (livingEntity instanceof Colorable) {
        colorable((Colorable) livingEntity);
    }
}

From source file:MSUmpire.LCMSPeakStructure.LCMSPeakMS1.java

public void AssignQuant(boolean export) throws IOException {
    if (IDsummary == null) {
        return;//from  w w w. j  a va 2s.  c o  m
    }
    if (!FilenameUtils.getBaseName(IDsummary.mzXMLFileName)
            .equals(FilenameUtils.getBaseName(ScanCollectionName))) {
        return;
    }
    Logger.getRootLogger().info("Assigning peak cluster to peptide IDs......");
    Logger.getRootLogger().info("Total peptide ions to be quantified..:" + IDsummary.GetPepIonList().size());
    int count = 0;
    for (PepIonID pepIonID : IDsummary.GetPepIonList().values()) {
        pepIonID.CreateQuantInstance(MaxNoPeakCluster);
        pepIonID.MS1PeakClusters.clear();
        ArrayList<PeakCluster> clusterList = FindAllPeakClustersForPepByPSM(pepIonID);
        if (!clusterList.isEmpty()) {
            count++;
            PeakCluster targetCluster = clusterList.get(0);
            float Intensity = targetCluster.PeakHeight[0];

            for (int i = 1; i < clusterList.size(); i++) {
                if (clusterList.get(i).PeakHeight[0] > Intensity) {
                    targetCluster = clusterList.get(i);
                    Intensity = clusterList.get(i).PeakHeight[0];
                }
            }
            pepIonID.PeakArea = targetCluster.PeakArea;
            pepIonID.PeakHeight = targetCluster.PeakHeight;
            if (!pepIonID.MS1PeakClusters.contains(targetCluster)) {
                pepIonID.MS1PeakClusters.add(targetCluster);
            }
            pepIonID.PeakClusterScore = targetCluster.MS1Score;
            pepIonID.PeakRT = targetCluster.PeakHeightRT[0];
            pepIonID.ObservedMz = targetCluster.mz[0];
            targetCluster.AssignedPepIon = pepIonID.GetKey();
            targetCluster.Identified = true;
        } else {
            Logger.getRootLogger().warn("Feature for " + pepIonID.ModSequence + " not found: Charge="
                    + pepIonID.Charge + ", mz=" + pepIonID.ObservedMz + ", RT=" + pepIonID.GetRT());
        }
    }
    DecimalFormat df = new DecimalFormat("###.##");

    Logger.getRootLogger().info("No. of peptide ions quantified..:" + count + "("
            + df.format((float) count / IDsummary.GetPepIonList().size() * 100) + "%)");

    if (export) {
        ExportID();
    }
}

From source file:de.micromata.genome.gwiki.page.impl.GWikiWikiPageBaseArtefakt.java

public boolean compileFragements(GWikiContext wikiContext) {
    if (getCompiledObject() != null) {
        return true;
    }/*from  w w  w .  ja va2 s.  com*/
    if (wikiContext == null) {
        wikiContext = GWikiContext.getCurrent();
    }
    final GWikiContext wctx = wikiContext;
    long start = System.currentTimeMillis();
    wikiContext.getWikiWeb().getFilter().compileWikiWikiPage(wikiContext, wikiContext.getCurrentElement(), this,
            new GWikiWikiPageCompileFilter() {

                @Override
                public Void filter(
                        GWikiFilterChain<Void, GWikiWikiPageCompileFilterEvent, GWikiWikiPageCompileFilter> chain,
                        GWikiWikiPageCompileFilterEvent event) {
                    if (StringUtils.isEmpty(getStorageData()) == true) {
                        setCompiledObject(new GWikiContent(new ArrayList<GWikiFragment>()));
                        return null;
                    }
                    GWikiWikiParser wkparse = new GWikiWikiParser();
                    setCompiledObject(wkparse.parse(wctx, getStorageData()));
                    return null;
                }
            });
    LoggingServiceManager.get().getStatsDAO().addPerformance(GWikiLogCategory.Wiki, "GWikiParse.parse",
            System.currentTimeMillis() - start, 0);
    if (getCompiledObject() == null) {
        return false;
    }
    ArrayList<GWikiFragment> tprepareHeaderFragments = new ArrayList<GWikiFragment>();
    getCompiledObject().iterate(new GWikiSimpleFragmentVisitor() {

        @Override
        public void begin(GWikiFragment fragment) {
            if (fragment.requirePrepareHeader(wctx) == true) {
                tprepareHeaderFragments.add(fragment);
            }
        }
    });
    if (tprepareHeaderFragments.isEmpty() == true) {
        prepareHeaderFragments = null;
    } else {
        prepareHeaderFragments = tprepareHeaderFragments;
    }
    return getCompiledObject() != null;
}

From source file:ece356.UserDBAO.java

public static ArrayList<PatientData> queryPatients(String username, String state, String city,
        String loggedInUser) throws ClassNotFoundException, SQLException {
    Connection con = null;/*from ww w  .j  av a 2  s . c o  m*/
    PreparedStatement pstmt = null;
    ArrayList<PatientData> ret;
    try {
        con = getConnection();
        ResultSet resultSet;

        // Query who is already friends with the person logged in            
        String friendShipQuery = "select friend.recieved_username as friend from friend where sent_username = ? and friend.isAccepted=1"
                + " union"
                + " select friend.sent_username as friend from friend where recieved_username = ? and friend.isAccepted=1";

        pstmt = con.prepareStatement(friendShipQuery);
        pstmt.setString(1, loggedInUser);
        pstmt.setString(2, loggedInUser);

        resultSet = pstmt.executeQuery();
        ArrayList<String> alreadyFriends = new ArrayList();
        while (resultSet.next()) {
            alreadyFriends.add(resultSet.getString("friend"));
        }

        // Query if a request has already been sent to this person
        friendShipQuery = "select friend.recieved_username as friend from friend where sent_username = ? and friend.isAccepted=0";

        pstmt = con.prepareStatement(friendShipQuery);
        pstmt.setString(1, loggedInUser);

        resultSet = pstmt.executeQuery();
        ArrayList<String> waitingForRequest = new ArrayList();
        while (resultSet.next()) {
            waitingForRequest.add(resultSet.getString("friend"));
        }

        ArrayList<String> keys = new ArrayList();
        ArrayList<String> values = new ArrayList();
        if (username != null && !username.equals("")) {
            keys.add("patient_username");
            values.add(username);
        }

        if (state != null && !state.equals("")) {
            keys.add("home_address_state");
            values.add(state);
        }

        if (city != null && !city.equals("")) {
            keys.add("home_address_city");
            values.add(city);
        }

        // Query for general doctor information
        String query = "SELECT * FROM patientSearchView";
        if (!keys.isEmpty()) {
            query = query + " where";
            for (String key : keys) {
                query = query + " " + key + " LIKE ?";
                query += " AND";
            }
            query = query.substring(0, query.length() - 4);
            System.out.println(query);
        }
        pstmt = con.prepareStatement(query);

        if (!values.isEmpty()) {
            int count = 1;
            for (String value : values) {
                pstmt.setString(count, "%" + value + "%");
                count++;
            }
        }

        resultSet = pstmt.executeQuery();

        ret = new ArrayList();
        while (resultSet.next()) {
            PatientData patient = new PatientData();
            patient.userName = resultSet.getString("patient_username");
            patient.city = resultSet.getString("home_address_city");
            patient.state = resultSet.getString("home_address_state");
            patient.numberOfReviews = resultSet.getInt("numberOfReviews");
            patient.lastReviewDate = resultSet.getTimestamp("lastReviewDate");
            ret.add(patient);

            if (alreadyFriends.contains(patient.getUserName())) {
                patient.setFriendShipStatusWithLoggedInUser(FriendShipStatus.ALREADY_FRIENDS);
            } else if (waitingForRequest.contains(patient.getUserName())) {
                patient.setFriendShipStatusWithLoggedInUser(FriendShipStatus.WAITING_FOR_ACCEPT);
            } else {
                patient.setFriendShipStatusWithLoggedInUser(FriendShipStatus.NOT_FRIENDS);
            }
        }

        // Add friendship status for each patient
        /*select friend.sent_username, friend.isAccepted as friend
        from friend where friend.recieved_username = 'pat_bob'
        union
        select friend.recieved_username, friend.isAccepted as friend 
        from friend where friend.sent_username = 'pat_bob'*/

        return ret;
    } catch (Exception e) {
        System.out.println("EXCEPTION:%% " + e);
    } finally {
        if (pstmt != null) {
            pstmt.close();
        }
        if (con != null) {
            con.close();
        }
    }
    return null;
}

From source file:org.apache.hive.service.cli.thrift.TestThriftHttpCLIServiceFeatures.java

private void verifyForwardedHeaders(ArrayList<String> headerIPs, String cmd) throws Exception {
    TTransport transport;/*from  w w  w. ja  va 2  s . c o  m*/
    DefaultHttpClient hClient = new DefaultHttpClient();
    String httpUrl = getHttpUrl();

    // add an interceptor that adds the X-Forwarded-For header with given ips
    if (!headerIPs.isEmpty()) {
        Header xForwardHeader = new BasicHeader("X-Forwarded-For", Joiner.on(",").join(headerIPs));
        RequestDefaultHeaders headerInterceptor = new RequestDefaultHeaders(Arrays.asList(xForwardHeader));
        hClient.addRequestInterceptor(headerInterceptor);
    }

    // interceptor for adding username, pwd
    HttpBasicAuthInterceptor authInt = new HttpBasicAuthInterceptor(ThriftCLIServiceTest.USERNAME,
            ThriftCLIServiceTest.PASSWORD, null, null, false, null);
    hClient.addRequestInterceptor(authInt);

    transport = new THttpClient(httpUrl, hClient);
    TCLIService.Client httpClient = getClient(transport);

    // Create a new open session request object
    TOpenSessionReq openReq = new TOpenSessionReq();
    TOpenSessionResp openResp = httpClient.OpenSession(openReq);

    //execute a query
    TExecuteStatementReq execReq = new TExecuteStatementReq(openResp.getSessionHandle(), "show tables");
    httpClient.ExecuteStatement(execReq);

    // capture arguments to authorizer impl call and verify ip addresses passed
    ArgumentCaptor<HiveAuthzContext> contextCapturer = ArgumentCaptor.forClass(HiveAuthzContext.class);

    verify(mockedAuthorizer).checkPrivileges(any(HiveOperationType.class),
            Matchers.anyListOf(HivePrivilegeObject.class), Matchers.anyListOf(HivePrivilegeObject.class),
            contextCapturer.capture());

    HiveAuthzContext context = contextCapturer.getValue();
    System.err.println("Forwarded IP Addresses " + context.getForwardedAddresses());

    List<String> auditIPAddresses = new ArrayList<String>(context.getForwardedAddresses());
    Collections.sort(auditIPAddresses);
    Collections.sort(headerIPs);

    Assert.assertEquals("Checking forwarded IP Address", headerIPs, auditIPAddresses);
}

From source file:NaraePreference.java

/**
 * @deprecated Use put(String key, ArrayList<String> value) that add API 11
 *//*from www.  j a  v  a  2 s .  co m*/
public void put_deprecated(String key, ArrayList<String> value) {
    JSONArray a = new JSONArray();
    for (int i = 0; i < value.size(); i++) {
        a.put(value.get(i));
    }
    if (!value.isEmpty()) {
        editor.putString(key, a.toString());
    } else {
        editor.putString(key, null);
    }
    editor.commit();
    keylist.add(key);
}

From source file:com.espertech.esper.core.EPStatementImpl.java

public void addListenerWithReplay(UpdateListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException("Null listener reference supplied");
    }//w w  w.j  a  va  2s . co  m

    if (isDestroyed()) {
        throw new IllegalStateException("Statement is in destroyed state");
    }

    statementContext.getEpStatementHandle().getStatementLock().acquireReadLock();
    try {
        // Add listener - listener not receiving events from this statement, as the statement is locked
        statementListenerSet.addListener(listener);
        statementContext.getStatementResultService().setUpdateListeners(statementListenerSet);
        statementLifecycleSvc.dispatchStatementLifecycleEvent(new StatementLifecycleEvent(this,
                StatementLifecycleEvent.LifecycleEventType.LISTENER_ADD, listener));

        Iterator<EventBean> it = iterator();
        if (it == null) {
            try {
                listener.update(null, null);
            } catch (Throwable t) {
                String message = "Unexpected exception invoking listener update method for replay on listener class '"
                        + listener.getClass().getSimpleName() + "' : " + t.getClass().getSimpleName() + " : "
                        + t.getMessage();
                log.error(message, t);
            }
            return;
        }

        ArrayList<EventBean> events = new ArrayList<EventBean>();
        for (; it.hasNext();) {
            events.add(it.next());
        }

        if (events.isEmpty()) {
            try {
                listener.update(null, null);
            } catch (Throwable t) {
                String message = "Unexpected exception invoking listener update method for replay on listener class '"
                        + listener.getClass().getSimpleName() + "' : " + t.getClass().getSimpleName() + " : "
                        + t.getMessage();
                log.error(message, t);
            }
        } else {
            EventBean[] iteratorResult = events.toArray(new EventBean[events.size()]);
            try {
                listener.update(iteratorResult, null);
            } catch (Throwable t) {
                String message = "Unexpected exception invoking listener update method for replay on listener class '"
                        + listener.getClass().getSimpleName() + "' : " + t.getClass().getSimpleName() + " : "
                        + t.getMessage();
                log.error(message, t);
            }
        }
    } finally {
        statementContext.getEpStatementHandle().getStatementLock().releaseReadLock();
    }
}

From source file:com.flat20.fingerplay.FingerPlayActivity.java

private void checkPurchases() {
    try {/*from w w w  .jav  a 2 s  .c o m*/
        Bundle ownedItems = mBillingService.getPurchases(3, getPackageName(), "subs", null);
        if (ownedItems.getInt("RESPONSE_CODE") == 0) {
            ArrayList<String> ownedSkus = ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
            ArrayList<String> ownedData = ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
            if (ownedSkus == null || ownedSkus.isEmpty()) {
                showSubscribeDialog();
            } else {
                for (int i = 0; i < ownedSkus.size(); i++) {
                    if (IAP_SUBS_KEY.equals(ownedSkus.get(i))) {
                        JSONObject jsonData = new JSONObject(ownedData.get(i));
                        int purchaseState = jsonData.getInt("purchaseState");
                        if (purchaseState == 0) {
                            Toast.makeText(this, R.string.toast_subs_verified, Toast.LENGTH_SHORT).show();
                            if (TextUtils.isEmpty(PreferenceManager.getDefaultSharedPreferences(this)
                                    .getString("settings_server_address", null))) {
                                Toast.makeText(this, R.string.toast_server_not_setup, Toast.LENGTH_SHORT)
                                        .show();
                                startActivity(new Intent(getApplicationContext(), SettingsView.class));
                            }
                        } else if (purchaseState == 1) {
                            unableToVerifyLicense(getString(R.string.billing_error_cancelled), true);
                        } else if (purchaseState == 2) {
                            unableToVerifyLicense(getString(R.string.billing_error_refunded), true);
                        } else {
                            unableToVerifyLicense(getString(R.string.billing_error_unknown_state), true);
                        }
                    }
                }
            }
        } else {
            unableToVerifyLicense(getString(R.string.billing_error_unknown), true);
        }
    } catch (Exception e) {
        Log.e("Fingerplay", "Error checking for purchases", e);
        unableToVerifyLicense(getString(R.string.billing_error_unknown), true);
    }
}

From source file:com.pindroid.syncadapter.BookmarkSyncAdapter.java

private void SyncNotes()
        throws AuthenticationException, IOException, TooManyRequestsException, PinboardException {

    final ArrayList<Note> noteList = PinboardApi.getNoteList(mAccount, mContext);
    NoteManager.TruncateNotes(mAccount.name, mContext);

    for (Note n : noteList) {
        //NoteManager.UpsertNote(n, mAccount.name, mContext);

        Note t = PinboardApi.getNote(n.getPid(), mAccount, mContext);
        n.setText(t.getText());/* w w  w .ja v  a2s  .c o m*/
    }

    if (!noteList.isEmpty()) {
        NoteManager.BulkInsert(noteList, mAccount.name, mContext);
    }
}