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:caveworld.core.CaverManager.java

@Override
public void setMiningPointAmount(String oredict, int amount) {
    ArrayList<ItemStack> ores = OreDictionary.getOres(oredict);

    if (!ores.isEmpty()) {
        for (ItemStack entry : ores) {
            Block block = Block.getBlockFromItem(entry.getItem());

            if (block != Blocks.air) {
                setMiningPointAmount(block, entry.getItemDamage(), amount);
            }//  ww  w  . j  av a  2  s  .c o  m
        }
    }
}

From source file:com.strategicgains.docussandra.controller.perf.remote.mongo.PlayersRemotePerfMongo.java

/**
 * Tests that the POST /{databases}/{table}/query endpoint properly runs a
 * query with a set time./*ww  w  .j av  a2 s. c  o m*/
 */
@Test
@Override
public void postQueryTest() {
    try {
        int numQueries = 50;
        Date start = new Date();
        MongoClient mongoClient = new MongoClient(uri);
        mongoClient.setWriteConcern(WriteConcern.MAJORITY);
        DB db = mongoClient.getDB(this.getDb().name());
        final DBCollection coll = db.getCollection(this.getDb().name());

        for (int i = 0; i < numQueries; i++) {
            ArrayList<String> res = new ArrayList<>();
            logger.debug("Query: " + i);
            DBCursor curser = coll.find(new BasicDBObject("NAMELAST", "Manning"));
            int count = 0;
            while (curser.hasNext() && count++ < 10000) {
                DBObject o = curser.next();
                assertNotNull(o);
                assertTrue(o.toString().contains("Manning"));
                res.add(o.toString());
            }
            assertFalse(res.isEmpty());
        }
        Date end = new Date();
        long executionTime = end.getTime() - start.getTime();
        double inSeconds = (double) executionTime / 1000d;
        double average = (double) inSeconds / (double) numQueries;
        output.info("Players-Mongo: Time to execute (single field) for " + numQueries + " is: " + inSeconds
                + " seconds");
        output.info("Players-Mongo: Averge time for single field is: " + average);
    } catch (UnknownHostException e) {
        logger.error("Couldn't run test.", e);
        throw new RuntimeException(e);
    }
}

From source file:net.bluehornreader.service.FeedManagerService.java

/**
 * Assigns the feeds to crawlers. <p/>
 *
 * Should work but there are many ways to improve it:
 *
 * <ul> It's probably a good idea to shuffle the feeds every once in a while (like 1 hour) </ul>
 *
 * <ul> When there's any change, everything is computed from scratch and marked as new, causing various things to restart at once </ul>
 *
 * <ul> In a big deployment it may take too long to assign the feeds (note: 100000 feeds is not much) </ul>
 *//*from w  w  w.  j  a  v a2  s . c  om*/
private void distributeFeeds() throws Exception {
    long begin = System.currentTimeMillis();

    ArrayList<Crawler> crawlers = crawlerDb.getAll(); // ttt1 reads all fields but doesn't need them
    ArrayList<Crawler> liveCrawlers = new ArrayList<>();
    ArrayList<Crawler> deadCrawlers = new ArrayList<>();
    for (Crawler crawler : crawlers) {
        if (checkAndStoreAlive(crawler)) {
            liveCrawlers.add(crawler);
        } else {
            deadCrawlers.add(crawler);
        }
    }

    HashMap<String, ArrayList<String>> newFeedMap = new HashMap<>();
    if (liveCrawlers.isEmpty()) {
        LOG.warn("No live crawlers found");
    } else {
        Collections.sort(liveCrawlers, new Comparator<Crawler>() {
            @Override
            public int compare(Crawler o1, Crawler o2) {
                return o1.crawlerId.compareTo(o2.crawlerId);
            }
        });
        for (Crawler crawler : liveCrawlers) {
            newFeedMap.put(crawler.crawlerId, new ArrayList<String>());
        }
        int k = 0;
        for (Feed feed : feeds) {
            newFeedMap.get(liveCrawlers.get(k).crawlerId).add(feed.feedId);
            ++k;
            if (k >= liveCrawlers.size()) {
                k = 0;
            }
        }
    }

    if (!newFeedMap.equals(feedMap)) {
        LOG.info("new feed map");
        feedMap = newFeedMap;
        for (Crawler crawler : liveCrawlers) {
            crawlerDb.updateFeedList(crawler.crawlerId, feedMap.get(crawler.crawlerId), crawler.feedIdsSeq + 1);
        }
    }

    crawlerDb.delete(deadCrawlers);

    long end = System.currentTimeMillis();
    if (end - begin > Config.getConfig().feedManagerTickInterval / 4) {
        LOG.error("FeedManagerTickInterval is too low"); // ttt1 maybe throw
        // ttt1 perhaps have worker threads or something, if using more than 10000 feeds
    }
}

From source file:NaraePreference.java

/**
 * @deprecated Use put(String key, ArrayList<String> value) that add API 11
 *///from  w  ww .  j a  va2  s  . c  o  m
public void put_deprecated(String key, String[] value) {
    ArrayList<String> arraylist = new ArrayList<>(Arrays.asList(value));
    JSONArray a = new JSONArray();
    for (int i = 0; i < arraylist.size(); i++) {
        a.put(arraylist.get(i));
    }
    if (!arraylist.isEmpty()) {
        editor.putString(key, a.toString());
    } else {
        editor.putString(key, null);
    }
    editor.commit();
    keylist.add(key);
}

From source file:com.pureinfo.srm.reports.table.data.sci.SCIBySubjectOnlyStatistic.java

protected IObjects doQuery() throws PureException {
    IStatement stat = null;//from   www.j a va2 s .  c o  m
    try {
        ISCIMgr mgr = (ISCIMgr) ArkContentHelper.getContentMgrOf(SCI.class);
        ISQLLogic con = makeDateCondtion();
        String sWhere = "";

        ArrayList params = new ArrayList();
        String sCon = con == null ? null : con.toSQL(params);
        if (sCon != null && sCon.trim().length() > 0) {
            sWhere = " WHERE " + sCon;
        }
        String strSQL = "select count({this.id}) _NUM, {this.englishScience} AS _SUB,{this.schoolName} AS _SCH "
                + " from {this} " + sWhere + " group by _SUB";
        stat = mgr.createQuery(strSQL, 0);
        if (!params.isEmpty()) {
            stat.setParameters(0, params);
        }

        IObjects nums = stat.executeQuery(false);
        return nums;
    } finally {
        if (stat != null)
            stat.clear();
    }

}

From source file:userInteface.Patient.ManageVitalSignsJPanel.java

private void populateVitalSignTable(Person person) {

    DefaultTableModel model = (DefaultTableModel) viewVitalSignsJTable.getModel();
    model.setRowCount(0);/*from   w  w  w.j av  a  2s  . co m*/
    if (person != null) {
        int patientAge = person.getAge();
        ArrayList<VitalSign> vitalSignList = person.getPatient().getVitalSignHistory().getHistory();

        if (vitalSignList.isEmpty()) {
            JOptionPane.showMessageDialog(this, "No vital signs found. Please add vital signs", "Error",
                    JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        for (VitalSign vitalSign : vitalSignList) {
            Object[] row = new Object[2];
            row[0] = vitalSign;
            row[1] = VitalSignStatus(patientAge, vitalSign);
            model.addRow(row);
        }
    }
}

From source file:co.uk.randompanda30.sao.modules.util.BackupUtil.java

public void backup() {
    TEMP.isBackingup = true;// ww w  .  ja  va  2s  . com

    SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy-HH:mm:ss-z");
    f.setTimeZone(TimeZone.getTimeZone("Europe/London"));

    ArrayList<File> fq = new ArrayList<>();

    File ff = new File(toStore);

    FileUtils.listFiles(ff, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).stream()
            .filter(fff -> fff.getName().endsWith(".zip")).forEach(fq::add);

    if (!fq.isEmpty() && fq.size() >= 5) {
        File[] fil = fq.toArray(new File[fq.size()]);
        Arrays.sort(fil, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);

        fil[0].delete();
    }

    size = 0;
    files = 0;

    p = 0;
    lp = -1;

    time = f.format(GregorianCalendar.getInstance().getTime());

    logFile = new File(toStoreLogs + time + ".log");

    if (!new File(toStore).exists()) {
        new File(toStore).mkdir();
    }

    if (!logFile.exists()) {
        try {
            logFile.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    Dispatch.sendMessage((String) Messages.MessagesValues.MODULES_BACKUP_STARTED.value, null);

    Bukkit.getOnlinePlayers().stream().filter(player -> player.hasPermission("backup.notification"))
            .forEach(player -> Dispatch
                    .sendMessage((String) Messages.MessagesValues.MODULES_BACKUP_STARTED.value, player));

    Thread t = new Thread(new Runnable() {
        boolean nc = false;

        @Override
        public void run() {
            String s = "zip -r " + toStore + time + ".zip " + toBackup;

            for (String exclusion : (List<String>) Config.ConfigValues.BACKUP_EXCLUSIONPATHS.value) {
                String nex = exclusion.endsWith("/") ? exclusion : exclusion + "/";
                s += " -x " + toBackup + nex + "\\" + "*";
            }

            startBackupTimer();

            File file = new File(toBackup);

            // FileUtils.listFiles(file, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)
            listFDIR(file.getAbsolutePath());

            try {
                Process process = Runtime.getRuntime().exec(s);
                InputStreamReader is = new InputStreamReader(process.getInputStream());
                BufferedReader buff = new BufferedReader(is);

                FileOutputStream fos = new FileOutputStream(logFile);
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

                String line;

                while ((line = buff.readLine()) != null) {
                    files++;

                    bw.write(line);
                    bw.newLine();

                    updatePercentage();
                }
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            nc = true;

            Dispatch.sendMessage((String) Messages.MessagesValues.MODULES_BACKUP_STOPPED.value, null);

            Bukkit.getOnlinePlayers().stream().filter(player -> player.hasPermission("backup.notification"))
                    .forEach(player -> Dispatch.sendMessage(
                            (String) Messages.MessagesValues.MODULES_BACKUP_STOPPED.value, player));

            if (TEMP.pendingRestart) {
                // Message
                new ShutdownTask().runTaskTimer(SAO.getPlugin(), 0L, 20L);
            }
        }

        private void updatePercentage() {
            double d = (files / size) * 100;
            p = (int) d;
        }

        private void startBackupTimer() {
            new BukkitRunnable() {
                @Override
                public void run() {
                    if (!nc) {
                        String m = (String) Messages.MessagesValues.MODULES_BACKUP_PERCENTAGE.value;
                        m = m.replace("%perc", Integer.toString(p));
                        m = m.replace("%done", Integer.toString((int) files));
                        m = m.replace("%files", Integer.toString((int) size));

                        if (p != lp) {
                            lp = p;

                            Dispatch.sendMessage(m, null);

                            for (Player player : Bukkit.getOnlinePlayers()) {
                                if (player.hasPermission("backup.notification")) {
                                    Dispatch.sendMessage(m, player);
                                }
                            }
                        }
                    } else {
                        TEMP.isBackingup = false;
                        startTimer();
                        this.cancel();
                    }
                }
            }.runTaskTimer(SAO.getPlugin(), 0L, 100L);
        }
    });
    t.start();
}

From source file:com.webcohesion.enunciate.EnunciateConfiguration.java

public List<Contact> getContacts() {
    List<HierarchicalConfiguration> contacts = this.source.configurationsAt("contact");
    ArrayList<Contact> results = new ArrayList<Contact>(contacts.size());
    for (HierarchicalConfiguration configuration : contacts) {
        results.add(new Contact(configuration.getString("[@name]", null),
                configuration.getString("[@url]", null), configuration.getString("[@email]", null)));
    }/* w  w w . j  ava 2  s.  com*/
    return results.isEmpty() ? this.defaultContacts : results;
}

From source file:edu.lafayette.metadb.web.permission.ShowPermissions.java

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/// www . j av a2  s. c  o  m
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out = response.getWriter();
    JSONObject data = new JSONObject();
    String username = request.getParameter("username");
    StringBuilder list = new StringBuilder();
    ArrayList<Permission> permissionList;
    try {
        User user = UserManDAO.getUserData(username);
        JSONObject info = new JSONObject();
        data.put("info", info);

        info.put("auth_type", user.getAuthType());
        info.put("user_type", user.getType());

        permissionList = PermissionManDAO.getAllProjectPermission(username);

        if (permissionList != null && !permissionList.isEmpty()) {
            for (Permission p : permissionList) {

                String projname = p.getProjectName();
                list.append("<tr class='permission-cell' id='" + projname + "-permission'>\n");
                list.append("<td class='border'>");
                list.append(projname + "</td>\n");

                String md = p.getDesc_md();
                list.append("<td class='cell'>\n");
                if (md.equals("read")) {
                    list.append("<input type='radio' name='desc_md-" + projname
                            + "' value='read' checked/>read only<br/>");
                    list.append("<input type='radio' name='desc_md-" + projname
                            + "' value='read_write' />read/write");
                } else if (md.equals("read_write")) {
                    list.append("<input type='radio' name='desc_md-" + projname
                            + "' value='read' />read only<br/>");
                    list.append("<input type='radio' name='desc_md-" + projname
                            + "' value='read_write' checked/>read/write");
                }
                list.append("</td>\n");

                md = p.getAdmin_md();
                list.append("<td class='cell'>\n");
                if (md.equals("read")) {
                    list.append("<input type='radio' name='admin_md-" + projname
                            + "' value='read' checked/>read only<br/>");
                    list.append("<input type='radio' name='admin_md-" + projname
                            + "' value='read_write' />read/write");
                } else if (md.equals("read_write")) {
                    list.append("<input type='radio' name='admin_md-" + projname
                            + "' value='read' />read only<br/>");
                    list.append("<input type='radio' name='admin_md-" + projname
                            + "' value='read_write' checked/>read/write");
                }

                String table_edit = p.getTable_edit();
                list.append("<td class='cell'>\n");
                if (table_edit.equals("deny")) {
                    list.append("<input type='radio' name='table_edit-" + projname
                            + "' value='deny' checked/>deny access<br/>");
                    list.append("<input type='radio' name='table_edit-" + projname
                            + "' value='allow' />allow access");
                } else if (table_edit.equals("allow")) {
                    list.append("<input type='radio' name='table_edit-" + projname
                            + "' value='deny' />deny access<br/>");
                    list.append("<input type='radio' name='table_edit-" + projname
                            + "' value='allow' checked/>allow access");
                }

                String controlled_vocab = p.getControlled_vocab();
                list.append("<td class='cell'>\n");
                if (controlled_vocab.equals("deny")) {
                    list.append("<input type='radio' name='controlled_vocab-" + projname
                            + "' value='deny' checked/>deny access<br/>");
                    list.append("<input type='radio' name='controlled_vocab-" + projname
                            + "' value='allow' />allow access");
                } else if (controlled_vocab.equals("allow")) {
                    list.append("<input type='radio' name='controlled_vocab-" + projname
                            + "' value='deny' />deny access<br/>");
                    list.append("<input type='radio' name='controlled_vocab-" + projname
                            + "' value='allow' checked/>allow access");
                }
                list.append("</td>\n");

                String dataPerm = p.getData();
                list.append("<td class='cell'>\n");
                if (dataPerm.equals("none")) {
                    list.append("<input type='radio' name='data-" + projname
                            + "' value='none' checked />no access<br/>");
                    list.append("<input type='radio' name='data-" + projname
                            + "' value='export' />export only<br/>");
                    list.append("<input type='radio' name='data-" + projname
                            + "' value='import_export' />import/export");
                } else if (dataPerm.equals("export")) {
                    list.append(
                            "<input type='radio' name='data-" + projname + "' value='none' />no access<br/>");
                    list.append("<input type='radio' name='data-" + projname
                            + "' value='export' checked/>export only<br/>");
                    list.append("<input type='radio' name='data-" + projname
                            + "' value='import_export' />import/export");
                } else if (dataPerm.equals("import_export")) {
                    list.append(
                            "<input type='radio' name='data-" + projname + "' value='none' />no access<br/>");
                    list.append("<input type='radio' name='data-" + projname
                            + "' value='export' />export only<br/>");
                    list.append("<input type='radio' name='data-" + projname
                            + "' value='import_export' checked/>import/export");
                }
                list.append("</td>\n");

                list.append(
                        "<td class='border'><input type='button' class='ui-state-default' style='width:60px' name='revoke' value='Revoke'></td>\n");
                list.append("</tr>\n");
            }
        }
        data.put("data", list.toString());
        out.print(data);
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
    }
    response.setContentType("application/x-json");
    out.flush();
}

From source file:eionet.cr.dao.virtuoso.VirtuosoPostHarvestScriptDAO.java

@Override
public List<PostHarvestScriptDTO> getScriptsByIds(List<Integer> ids) throws DAOException {
    ArrayList<PostHarvestScriptDTO> result = new ArrayList<PostHarvestScriptDTO>();

    for (int id : ids) {
        result.add(fetch(id));//from   www.  j  a v a  2 s. c  o  m
    }

    return result.isEmpty() ? null : result;

}