Example usage for java.util List isEmpty

List of usage examples for java.util List isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:hrytsenko.gscripts.io.CsvFiles.java

/**
 * Save records into file.//from w ww.  j  a  va  2 s .  c  o  m
 * 
 * <p>
 * If file already exists, then it will be overridden.
 * 
 * @param records
 *            the list of records to save.
 * @param args
 *            the named arguments.
 * 
 * @throws IOException
 *             if file could not be saved.
 */
public static void saveCsv(List<Map<String, ?>> records, Map<String, ?> args) {
    if (records.isEmpty()) {
        LOGGER.info("No records to save.");
        return;
    }

    Path path = NamedArgs.findPath(args);
    LOGGER.info("Save {}.", path.getFileName());

    CsvSchema.Builder csvSchema = schemaFrom(args).setUseHeader(true);
    Records.columns(records).forEach(csvSchema::addColumn);

    try (Writer writer = Files.newBufferedWriter(path, charsetFrom(args))) {
        CsvMapper csvMapper = new CsvMapper();
        csvMapper.configure(CsvGenerator.Feature.ALWAYS_QUOTE_STRINGS, true);

        csvMapper.writer().with(csvSchema.build()).writeValue(writer, Records.normalize(records));
    } catch (IOException exception) {
        throw new AppException(String.format("Could not save file %s.", path.getFileName()), exception);
    }
}

From source file:com.jaxio.celerio.configuration.Pattern.java

public static boolean hasPattern(List<Pattern> patterns, String value) {
    // no definition : everything is ok
    if (patterns.isEmpty()) {
        return true;
    }/*w w  w .  j a  va2  s  .  c  o m*/

    for (Pattern pattern : patterns) {
        if (pattern.match(value)) {
            return pattern.isIncluded();
        }
    }

    if (hasOnlyExcludes(patterns)) {
        return true;
    } else if (hasOnlyIncludes(patterns)) {
        return false;
    } else {
        return false;
    }
}

From source file:com.notonthehighstreet.ratel.internal.model.Error.java

private static List<Backtrace> unwrapStackTrace(final Throwable e) {
    // As Honeybadger only supports a single error, we need to massage the wrapped exceptions into a single stack trace
    final List<Backtrace> backtraces = new ArrayList<Backtrace>();

    Throwable cause = e;/*from  ww  w . j  a va 2  s .c om*/

    while (cause != null) {
        if (!backtraces.isEmpty()) {
            backtraces.add(Backtrace.markerBacktrace(cause));
        }

        for (final StackTraceElement element : e.getStackTrace()) {
            backtraces.add(Backtrace.fromStackTrace(element));
        }

        cause = cause.getCause();
    }

    return backtraces;
}

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

@SuppressWarnings("unchecked")
public static void renderPatchDom(PageContext pageContext) throws JspException {
    Object l = pageContext.getAttribute(GWIKI_MESSAGE_ATTR);
    if ((l instanceof List) == false) {
        return;/*from w w  w  .j a  v  a 2  s .  c  o  m*/
    }
    List<GWikiMessageTag> tags = (ArrayList<GWikiMessageTag>) l;
    if (tags.isEmpty() == true) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("<script type=\"text/javascript\">gwikiPatchI18NElements([");
    boolean first = true;
    for (GWikiMessageTag tag : tags) {
        if (first == false) {
            sb.append(", ");
        } else {
            first = false;
        }
        sb.append("{ id: '" + tag.getTagId() + "', i18nKey: '" + tag.getKeyAttrValue() + "'}");
    }
    sb.append("]);</script>");

    try {
        pageContext.getOut().write(sb.toString());
    } catch (IOException e) {
        throw new JspException(e);
    }

}

From source file:Main.java

private static Integer indexOfClosestZoom(Camera.Parameters parameters, double targetZoomRatio) {
    List<Integer> ratios = parameters.getZoomRatios();
    //        Log.i(TAG, "Zoom ratios: " + ratios);
    int maxZoom = parameters.getMaxZoom();
    if (ratios == null || ratios.isEmpty() || ratios.size() != maxZoom + 1) {
        //            Log.w(TAG, "Invalid zoom ratios!");
        return null;
    }// w w  w.j  ava2s.c  o m
    double target100 = 100.0 * targetZoomRatio;
    double smallestDiff = Double.POSITIVE_INFINITY;
    int closestIndex = 0;
    for (int i = 0; i < ratios.size(); i++) {
        double diff = Math.abs(ratios.get(i) - target100);
        if (diff < smallestDiff) {
            smallestDiff = diff;
            closestIndex = i;
        }
    }
    //        Log.i(TAG, "Chose zoom ratio of " + (ratios.get(closestIndex) / 100.0));
    return closestIndex;
}

From source file:com.abombrecords.amt_unlocker.AMT_Unlocker.java

public static boolean UnlockDoor(String Username, String Password, String DoorPIN) throws Exception {
    boolean bSuccess = false;

    //Log.d(LogTag, "Login");   
    DefaultHttpClient httpclient = new DefaultHttpClient();

    HttpPost httpost = new HttpPost("http://acemonstertoys.org/node?destination=node");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    nvps.add(new BasicNameValuePair("op", "Log in"));
    nvps.add(new BasicNameValuePair("name", Username));
    nvps.add(new BasicNameValuePair("pass", Password));
    nvps.add(new BasicNameValuePair("openid.return_to",
            "http://acemonstertoys.org/openid/authenticate?destination=node"));
    nvps.add(new BasicNameValuePair("form_id", "user_login_block"));
    nvps.add(new BasicNameValuePair("form_build_id", "form-4d6478bc67a79eda5e36c01499ba4c88"));

    httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

    HttpResponse response = httpclient.execute(httpost);
    HttpEntity entity = response.getEntity();

    //Log.d(LogTag, "Login form get: " + response.getStatusLine());
    if (entity != null) {
        entity.consumeContent();/*ww  w. j a  v  a  2s .com*/
    }

    //Log.d(LogTag, "Post Login cookies:");
    // look for drupal_uid and fail out if it isn't there
    List<Cookie> cookies = httpclient.getCookieStore().getCookies();
    if (cookies.isEmpty()) {
        //Log.d(LogTag, "None");
    } else {
        for (int i = 0; i < cookies.size(); i++) {
            //Log.d(LogTag, "- " + cookies.get(i).toString());

            if (cookies.get(i).getName().equals("drupal_uid")) {
                bSuccess = true;
            }
        }
    }

    if (bSuccess) {
        HttpPost httpost2 = new HttpPost("http://acemonstertoys.org/membership");

        List<NameValuePair> nvps2 = new ArrayList<NameValuePair>();
        nvps2.add(new BasicNameValuePair("doorcode", DoorPIN));
        nvps2.add(new BasicNameValuePair("forceit", "Open Door"));

        httpost2.setEntity(new UrlEncodedFormEntity(nvps2, HTTP.UTF_8));

        response = httpclient.execute(httpost2);
        entity = response.getEntity();

        //Log.d(LogTag, "Unlock form get: " + response.getStatusLine());
        if (entity != null) {
            entity.consumeContent();
        }
    }

    httpclient.getConnectionManager().shutdown();

    return bSuccess;
}

From source file:fredboat.util.DiscordUtil.java

public static int getHighestRolePosition(Member member) {
    List<Role> roles = member.getRoles();

    if (roles.isEmpty())
        return -1;

    Role top = roles.get(0);/*w w w.java 2s  .c  o m*/

    for (Role r : roles) {
        if (r.getPosition() > top.getPosition()) {
            top = r;
        }
    }

    return top.getPosition();
}

From source file:fr.paris.lutece.plugins.directory.utils.UrlUtils.java

/**
 * Get the parameter map from a given url
 * @param strUrl the url//from   w w  w.j a v  a2  s  .  co m
 * @return the parameter map
 */
public static Map<String, List<String>> getMapParametersFromUrl(String strUrl) {
    Map<String, List<String>> mapParameters = new HashMap<String, List<String>>();

    if (StringUtils.isNotBlank(strUrl) && (strUrl.indexOf(INTERROGATION_MARK) > 0)) {
        String strUrlParameters = strUrl.substring(strUrl.indexOf(INTERROGATION_MARK) + 1);
        String[] listParameters = strUrlParameters.split(AMPERSAND);

        if ((listParameters != null) && (listParameters.length > 0)) {
            for (String strParameter : listParameters) {
                String[] parameter = strParameter.split(EQUAL);

                if ((parameter != null) && (parameter.length == 2)) {
                    List<String> listParameterValues = mapParameters.get(parameter[0]);

                    if ((listParameterValues != null) && !listParameterValues.isEmpty()) {
                        listParameterValues.add(parameter[1]);
                    } else {
                        listParameterValues = new ArrayList<String>();
                        listParameterValues.add(parameter[1]);
                        mapParameters.put(parameter[0], listParameterValues);
                    }
                }
            }
        }
    }

    return mapParameters;
}

From source file:library.entry.Main.java

private static void viewbooks(List<Book> books) {
    if (books.isEmpty()) {
        ConsoleHelper.printMessage("");
        ConsoleHelper.printMessage("==== No books available ====");
        return;/* w  ww .  j  a va 2s .c o m*/
    }
    while (true) {
        ConsoleHelper.printMessage("");
        ConsoleHelper.printMessage("To view details enter the book ID, to return press <Enter>");
        ConsoleHelper.printMessage("");
        books.stream().forEach(o -> ConsoleHelper.printBookSelection(o.getId(), o.getTitle()));
        ConsoleHelper.printMessage("");
        ConsoleHelper.printPrompt("Book ID");
        Integer selectedId = ConsoleHelper.getInt(true);
        if (selectedId == null) {
            break;
        } else {
            books.stream().filter(b -> b.getId() == selectedId).forEach(b -> {
                ConsoleHelper.printMessage(String.format("ID: %s", "" + b.getId()), 1);
                ConsoleHelper.printMessage(String.format("Title: %s", b.getTitle()), 1);
                ConsoleHelper.printMessage(String.format("Author: %s", b.getAuthor()), 1);
                ConsoleHelper.printMessage(String.format("Description: %s", b.getDescription()), 1);
            });
        }
    }
}

From source file:net.meltdowntech.steamstats.SteamUser.java

public static SteamUser fetchUser(Long id) {
    //TODO Write optimized version of this
    List<SteamUser> user = fetchUsers(Arrays.asList(new Long[] { id }));
    if (!user.isEmpty())
        return user.get(0);
    return new SteamUser();
}