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:eionet.cr.util.Util.java

/**
 *
 * @param array/* w w w . j  av  a 2s .c  o  m*/
 * @return
 */
public static String[] pruneUrls(String[] array) {

    if (array == null || array.length == 0) {
        return array;
    }

    ArrayList<String> list = new ArrayList<String>();
    for (int i = 0; i < array.length; i++) {
        if (!URLUtil.isURL(array[i])) {
            list.add(array[i]);
        }
    }

    if (list.isEmpty()) {
        return array;
    } else {
        String[] result = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            result[i] = list.get(i);
        }
        return result;
    }
}

From source file:de.whs.poodle.controllers.instructor.InstructorStartController.java

@RequestMapping(method = RequestMethod.GET)
public String get(@ModelAttribute Instructor instructor, Model model,
        @ModelAttribute("globalCourses") ArrayList<Course> courses) {
    if (courses.isEmpty())
        return "instructor/firstStart";

    List<AbstractExercise> exercises = getLatestChanges(instructor.getId());
    List<Statistic> feedbackList = statisticsRepo.getStatistics(new FeedbackSearchCriteria(),
            instructor.getId(), FEEDBACK_MAX);

    model.addAttribute("exercises", exercises);
    model.addAttribute("feedbackList", feedbackList);
    return "instructor/start";
}

From source file:ee.ioc.cs.vsle.synthesize.SpecParser.java

/**
 * @return list of fields declared in a specification.
 * @throws SpecParseException //from   w w w.j a  v a2s  .  com
 */
public static Collection<ClassField> getFields(String path, String fileName, String ext)
        throws IOException, SpecParseException {
    Map<String, ClassField> fields = new LinkedHashMap<String, ClassField>();
    String s = FileFuncs.getFileContents(new File(path, fileName + ext));
    ArrayList<String> specLines = getSpec(s, false);

    while (!specLines.isEmpty()) {
        LineType lt = null;
        try {
            lt = getLine(specLines);
        } catch (SpecParseException e) {
            e.printStackTrace();
        }

        if (lt != null) {
            if (lt.getType() == LineType.TYPE_ASSIGNMENT) {
                LineType.Assignment statement = (LineType.Assignment) lt.getStatement();
                ClassField field;
                if ((field = fields.get(statement.getName())) != null) {
                    field.setValue(statement.getValue());
                }
            } else if (lt.getType() == LineType.TYPE_DECLARATION) {
                LineType.Declaration statement = (LineType.Declaration) lt.getStatement();

                for (int i = 0; i < statement.getNames().length; i++) {
                    ClassField var = new ClassField(statement.getNames()[i], statement.getType());

                    fields.put(var.getName(), var);
                }
            } else if (lt.getType() == LineType.TYPE_ALIAS) {
                LineType.Alias statement = (LineType.Alias) lt.getStatement();
                Alias alias = new Alias(statement.getName(), statement.getComponentType());
                if (statement.getComponents() != null && statement.getComponents().length > 0) {
                    try {
                        //TODO - probably some time it will be needed to fill the class list
                        //and this does not work for aliases with wildcards
                        alias.addAll(statement.getComponents(), fields.values(), new ClassList());
                        //alternative approach is to do next - 
                        //for( String var : list ) {
                        //    ClassField aliasCF = fields.get( var );
                        //    if( aliasCF != null )
                        //        alias.addVar( aliasCF );
                        //}
                    } catch (UnknownVariableException e) {
                        logger.info("Line: " + e.getLine() + ", " + e.toString());
                    } catch (AliasException e) {
                    }
                }
                fields.put(statement.getName(), alias);
            } else if (lt.getType() == LineType.TYPE_SUPERCLASSES) {
                LineType.Superclasses statement = (LineType.Superclasses) lt.getStatement();

                for (String name : statement.getClassNames()) {
                    for (ClassField var : getFields(path, name, ext)) {
                        fields.put(var.getName(), var);
                    }
                }
            }
        }
    }
    return fields.values();
}

From source file:com.imagelake.android.category.Servlet_categories.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    PrintWriter out = response.getWriter();

    CategoriesDAOImp categoryDAOImp = new CategoriesDAOImp();
    JSONArray ja = new JSONArray();
    ArrayList<Categories> categoriesList = (ArrayList<Categories>) categoryDAOImp.listAllCategories();
    if (!categoriesList.isEmpty()) {
        for (Categories cc : categoriesList) {
            JSONObject jo = new JSONObject();
            jo.put("id", cc.getCategory_id());
            jo.put("cat", cc.getCategory());
            ja.add(jo);//w w  w. jav a  2 s . c  o m

        }
        out.write("json=" + ja.toJSONString());
    } else {

        JSONObject jo = new JSONObject();
        jo.put("id", 0);
        jo.put("cat", "No category found.");
        ja.add(jo);
        out.write("json=" + ja.toJSONString());

    }
}

From source file:net.opentsdb.meta.TSMeta.java

/**
 * Attempts to fetch the timeseries meta data from storage. 
 * This method will fetch the {@code counter} and {@code meta} columns.
 * <b>Note:</b> This method will not load the UIDMeta objects.
 * @param tsdb The TSDB to use for storage access
 * @param tsuid The UID of the meta to fetch
 * @return A TSMeta object if found, null if not
 * @throws HBaseException if there was an issue fetching
 * @throws IllegalArgumentException if parsing failed
 * @throws JSONException if the data was corrupted
 *///from   www .ja  va2  s .c  om
private static Deferred<TSMeta> getFromStorage(final TSDB tsdb, final byte[] tsuid) {

    /**
     * Called after executing the GetRequest to parse the meta data.
     */
    final class GetCB implements Callback<Deferred<TSMeta>, ArrayList<KeyValue>> {

        /**
         * @return Null if the meta did not exist or a valid TSMeta object if it
         * did.
         */
        @Override
        public Deferred<TSMeta> call(final ArrayList<KeyValue> row) throws Exception {
            if (row == null || row.isEmpty()) {
                return Deferred.fromResult(null);
            }

            long dps = 0;
            long last_received = 0;
            TSMeta meta = null;

            for (KeyValue column : row) {
                if (Arrays.equals(COUNTER_QUALIFIER, column.qualifier())) {
                    dps = Bytes.getLong(column.value());
                    last_received = column.timestamp() / 1000;
                } else if (Arrays.equals(META_QUALIFIER, column.qualifier())) {
                    meta = JSON.parseToObject(column.value(), TSMeta.class);
                }
            }

            if (meta == null) {
                LOG.warn("Found a counter TSMeta column without a meta for TSUID: "
                        + UniqueId.uidToString(row.get(0).key()));
                return Deferred.fromResult(null);
            }

            meta.total_dps = dps;
            meta.last_received = last_received;
            return Deferred.fromResult(meta);
        }

    }

    final GetRequest get = new GetRequest(tsdb.metaTable(), tsuid);
    get.family(FAMILY);
    get.qualifiers(new byte[][] { COUNTER_QUALIFIER, META_QUALIFIER });
    return tsdb.getClient().get(get).addCallbackDeferring(new GetCB());
}

From source file:Bag.java

public Object get(Object key) {
    ArrayList values = (ArrayList) super.get(key);
    if (values != null && !values.isEmpty()) {
        return values.get(0);
    } else {//w ww  . j av  a2s.com
        return null;
    }
}

From source file:com.bitranger.parknshop.common.recommend.vectors.similarity.PearsonCorrelation.java

@Override
public double similarity(ArrayList<Long> vec1, ArrayList<Long> vec2) {
    if (vec1.isEmpty() || vec2.isEmpty()) {
        return 0;
    }/*from   www . ja  va 2  s  .  c om*/

    // first compute means of common items
    double sum1 = 0;
    double sum2 = 0;
    int n = 0;
    for (Pair<VectorEntry, VectorEntry> pair : Vectors.fastIntersect(vec1, vec2)) {
        sum1 += pair.getLeft().getValue();
        sum2 += pair.getRight().getValue();
        n += 1;
    }

    if (n == 0) {
        return 0;
    }

    final double mu1 = sum1 / n;
    final double mu2 = sum2 / n;

    double var1 = 0;
    double var2 = 0;
    double dot = 0;
    int nCoratings = 0;

    for (Pair pair : Vectors.fastIntersect(vec1, vec2)) {
        final double v1 = (double) pair.getLeft();
        final double v2 = (double) pair.getRight();
        var1 += v1 * v1;
        var2 += v2 * v2;
        dot += v1 * v2;
        nCoratings += 1;
    }

    if (nCoratings == 0) {
        return 0;
    } else {
        return dot / (sqrt(var1 * var2) + shrink_age);
    }
}

From source file:com.shouwy.series.web.control.application.HomeController.java

private HashMap<Type, Series> getRandSeries(ArrayList<Type> listType, ArrayList<Series> listSeries) {
    HashMap<Type, Series> mapSeries = new HashMap<Type, Series>();
    HashMap<Integer, ArrayList<Series>> mapSeriesByType = Util.mapSeriesByIdType(listSeries);
    for (Type t : listType) {
        ArrayList<Series> list = mapSeriesByType.get(t.getId());
        Series s = null;/*from   w ww.  jav a2s  .c  o m*/
        if (list != null && !list.isEmpty()) {
            s = list.get((int) (Math.random() * (list.size())));
        }
        mapSeries.put(t, s);
    }

    return mapSeries;
}

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

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*///  ww  w . java2 s .  c o  m
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out = response.getWriter();
    String userName = request.getParameter("username");
    List<String> projectList = ProjectsDAO.getProjectList();
    JSONArray list = new JSONArray();
    //      String bigList = "";
    ArrayList<Permission> permissionList = PermissionManDAO.getAllProjectPermission(userName);
    if (permissionList != null && !permissionList.isEmpty())
        for (Permission p : permissionList)
            projectList.remove(p.getProjectName());
    for (String s : projectList)
        list.put(s);
    //         bigList += "<option name='" + s + "'>" + s + "</option>";
    out.print(list);
    out.flush();
}

From source file:ece356.UserDBAO.java

public static ArrayList<DoctorData> queryDoctor(HashMap<String, String> doctorParam, String user)
        throws ClassNotFoundException, SQLException {
    Connection con = null;/*from w  w  w  . java  2s  .  c o  m*/
    PreparedStatement pstmt = null;
    ArrayList<DoctorData> ret;
    try {
        con = getConnection();
        String query;
        boolean reviewByFriends = false;
        if (doctorParam.containsKey("reviewByFriends")) {

            if (doctorParam.get("reviewByFriends").equals("yes")) {

                query = "select * from doctorSearchView where username in (select username from doctorSearchView left join review on doctorSearchView.doc_spec_username = review.doc_username where doctorSearchView.patient_username in "
                        + "(select friend.sent_username as friend "
                        + "from friend where friend.isAccepted = 1 AND friend.recieved_username like '%" + user
                        + "%'" + "union " + "select friend.recieved_username as friend "
                        + "from friend where friend.isAccepted = 1 AND friend.sent_username like '%" + user
                        + "%'))";
                reviewByFriends = true;
            } else {
                query = "SELECT * FROM doctorSearchView ";
            }
            doctorParam.remove("reviewByFriends");
        } else {
            query = "SELECT * FROM doctorSearchView ";
            //pstmt = con.prepareStatement(query);

        }
        // Query for general doctor information
        ArrayList<String> keys = new ArrayList<String>(doctorParam.keySet());
        ArrayList<String> values = new ArrayList<String>(doctorParam.values());

        HashMap<Integer, Integer> h1 = new HashMap<>();
        int counter = 0;
        if (!keys.isEmpty()) {
            counter++;
            if (!reviewByFriends)
                query = query + " where";
            else
                query = query + " AND";

            for (String key : keys) {
                if (key.equals("averageRating") || key.equals("yearsLicensed")) {
                    query = query + " " + key + " >= ?";
                    query += " AND";
                    h1.put(counter, counter);
                } else if (key.equals("gender")) {
                    query = query + " " + key + " = ?";
                    query += " AND";
                    h1.put(counter, counter);
                } else if (keys.equals("reviewByFriends")) {

                } else {
                    query = query + " " + key + " LIKE ?";
                    query += " AND";
                }
                counter++;
            }
            query = query.substring(0, query.length() - 4);
            System.out.println(query);
        }

        query += " group by first_name, last_name, gender, averageRating, numberOfReviews";

        pstmt = con.prepareStatement(query);

        if (!values.isEmpty()) {
            counter = 1;
            for (String value : values) {
                if (h1.containsKey(counter)) {
                    pstmt.setString(counter, value);
                } else {
                    pstmt.setString(counter, "%" + value + "%");
                }
                counter++;
            }
        }
        System.out.println(pstmt);
        ResultSet resultSet;
        resultSet = pstmt.executeQuery();

        ret = new ArrayList();

        while (resultSet.next()) {
            DoctorData doctor = new DoctorData();
            doctor.userName = resultSet.getString("username");
            doctor.firstName = resultSet.getString("first_name");
            doctor.middleInitial = resultSet.getString("middle_initial");
            doctor.lastName = resultSet.getString("last_name");
            doctor.gender = resultSet.getString("gender");
            doctor.averageRating = resultSet.getDouble("averageRating");
            doctor.numberOfReviews = resultSet.getInt("numberOfReviews");
            ret.add(doctor);
        }
        return ret;
    } catch (Exception e) {
        System.out.println("EXCEPTION:%% " + e);
    } finally {
        if (pstmt != null) {
            pstmt.close();
        }
        if (con != null) {
            con.close();
        }
    }
    return null;
}