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:Main.java

private static void testTransfer() {
    List src, targ;

    src = new ArrayList();
    targ = new ArrayList();

    transfer(src, targ, 10);//from  ww w  .  j a va  2 s  .  c o m
    assert src.isEmpty() && targ.isEmpty();

    src.add("1");
    transfer(src, targ, 0);
    assert src.size() == 1 && targ.isEmpty();
    transfer(src, targ, 1);
    assert src.isEmpty() && targ.size() == 1;

    targ.clear();
    src.add("1");
    transfer(src, targ, 10);
    assert src.isEmpty() && targ.size() == 1;

}

From source file:ee.ria.xroad.proxy.serverproxy.CustomSSLSocketFactory.java

private static void checkServerTrusted(ServiceId service, X509Certificate cert) throws Exception {
    if (!ServerConf.isSslAuthentication(service)) {
        return;// w w  w.j av a2  s.c  o m
    }

    log.trace("Verifying service TLS certificate...");

    ClientId client = service.getClientId();
    List<X509Certificate> isCerts = ServerConf.getIsCerts(client);
    if (isCerts.isEmpty()) {
        throw new Exception(String.format("Client '%s' has no IS certificates", client));
    }

    if (isCerts.contains(cert)) {
        log.trace("Found matching IS certificate");
        return;
    }

    log.error("Could not find matching IS certificate for client '{}'", client);
    throw new Exception("Server certificate is not trusted");
}

From source file:com.mrmq.uyoutube.data.UpdateVideo.java

/**
 * Add a keyword tag to a video that the user specifies. Use OAuth 2.0 to
 * authorize the API request./*from ww w.  j  a v  a  2  s .c  om*/
 */
public static Video updateVideo(YouTube youtube, Video newVideo) {
    Video videoResponse = null;
    try {
        Preconditions.checkNotNull(newVideo, "Video can not be null");
        Preconditions.checkNotNull(newVideo.getSnippet(), "Video snippet can not be null");

        // Call the YouTube Data API's youtube.videos.list method to
        // retrieve the resource that represents the specified video.
        YouTube.Videos.List listVideosRequest = youtube.videos().list("snippet").setId(newVideo.getId());
        VideoListResponse listResponse = listVideosRequest.execute();

        // Since the API request specified a unique video ID, the API
        // response should return exactly one video. If the response does
        // not contain a video, then the specified video ID was not found.
        List<Video> videoList = listResponse.getItems();
        if (videoList.isEmpty()) {
            logger.error("Can't find a video with ID: " + newVideo.getId());
            return null;
        }

        // Extract the snippet from the video resource.
        Video video = videoList.get(0);
        VideoSnippet snippet = video.getSnippet();

        // Preserve any tags already associated with the video. If the
        // video does not have any tags, create a new array. Append the
        // provided tag to the list of tags associated with the video.
        if (newVideo.getSnippet().getTags() != null)
            snippet.setTags(newVideo.getSnippet().getTags());
        if (!StringUtils.isEmpty(newVideo.getSnippet().getTitle()))
            snippet.setTitle(newVideo.getSnippet().getTitle());
        if (!StringUtils.isEmpty(newVideo.getSnippet().getDescription()))
            snippet.setDescription(newVideo.getSnippet().getDescription());

        // Update the video resource by calling the videos.update() method.
        YouTube.Videos.Update updateVideosRequest = youtube.videos().update("snippet", video);
        videoResponse = updateVideosRequest.execute();

        // Print information from the updated resource.
        logger.info("\n================== Returned Video ==================\n");
        logger.info("  - Title: " + videoResponse.getSnippet().getTitle());
        logger.info("  - Tags: " + videoResponse.getSnippet().getTags());
        return videoResponse;
    } catch (GoogleJsonResponseException e) {
        logger.error("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : "
                + e.getDetails().getMessage());
    } catch (IOException e) {
        logger.error("IOException: " + e.getMessage(), e);
    } catch (Throwable t) {
        logger.error("Throwable: " + t.getMessage(), t);
    }

    return videoResponse;
}

From source file:com.projecttango.examples.java.floorplan.PlanBuilder.java

/**
 * Converts wall measurements to string.
 *
 * @param wallMeasurementList//from w  ww .j a va  2 s .  c o m
 * @return String
 */
public static String toString(List<WallMeasurement> wallMeasurementList) {
    List<String> planPoints = new ArrayList<String>();
    if (!wallMeasurementList.isEmpty()) {
        for (WallMeasurement wallMeasurement : wallMeasurementList) {
            float[] openGlWall = wallMeasurement.getPlaneTransform();
            float[] measurementPoint = new float[] { openGlWall[12], openGlWall[13], openGlWall[14] };
            planPoints.add(Arrays.toString(measurementPoint));
        }
    }
    return planPoints.toString();
}

From source file:com.textocat.textokit.morph.opencorpora.OpencorporaMorphDictionaryAPI.java

public static String locateDictionaryClassPath() {
    List<Manifest> jarManifests = ManifestUtils.searchByAttributeKey(ME_OPENCORPORA_DICTIONARY_VERSION);
    if (jarManifests.isEmpty())
        throw new IllegalStateException("Can't find an OpenCorpora dictionary in classpath");
    if (jarManifests.size() > 1)
        throw new UnsupportedOperationException("Found several OpenCorpora dictionaries in classpath");
    Manifest ocJarManifest = jarManifests.get(0);
    String version = ocJarManifest.getMainAttributes().getValue(ME_OPENCORPORA_DICTIONARY_VERSION);
    String revision = ocJarManifest.getMainAttributes().getValue(ME_OPENCORPORA_DICTIONARY_REVISION);
    String variant = ocJarManifest.getMainAttributes().getValue(ME_OPENCORPORA_DICTIONARY_VARIANT);
    return String.format(OpencorporaMorphDictionaryAPI.FILENAME_PATTERN_OPENCORPORA_SERIALIZED_DICT, version,
            revision, variant);/*from   w ww .jav a  2 s  .co m*/
}

From source file:Main.java

private static String[] setPlacesToWatch(String placeWatch) {

    String[] places = { "" };
    if (placeWatch != null && !placeWatch.equals("")) {
        StringTokenizer tok = new StringTokenizer(placeWatch, ",");
        List<String> l = new ArrayList<String>();
        while (tok.hasMoreElements()) {
            l.add(tok.nextToken().toString());
        }/*from  w w w .  j a v  a  2  s .  co  m*/
        if (!l.isEmpty()) {
            //Object[] o = l.toArray();
            places = new String[l.size()];// (String[])o;
            int idx = 0;
            for (String s : l) {
                places[idx++] = s;
            }
        }

    }
    return places;
}

From source file:fr.paris.lutece.plugins.genericattributes.util.GenericAttributesUtils.java

/**
 * Return the field which title is specified in parameter
 * @param strTitle the title/*from   ww  w  .j a v  a  2 s.c o m*/
 * @param listFields the list of fields
 * @return the field which title is specified in parameter
 */
public static Field findFieldByTitleInTheList(String strTitle, List<Field> listFields) {
    if ((listFields == null) || listFields.isEmpty()) {
        return null;
    }

    for (Field field : listFields) {
        if (StringUtils.isNotBlank(strTitle)) {
            if (StringUtils.equals(StringUtils.trim(strTitle), StringUtils.trim(field.getTitle()))) {
                return field;
            }
        } else if (StringUtils.isBlank(field.getTitle())) {
            return field;
        }
    }

    return null;
}

From source file:com.openkm.util.DocumentUtils.java

/**
 * Text spell checker/* ww w  .j av a2s . c om*/
 */
public static String spellChecker(String text) throws IOException {
    log.debug("spellChecker({})", text);
    StringBuilder sb = new StringBuilder();

    if (Config.SYSTEM_OPENOFFICE_DICTIONARY.equals("")) {
        log.warn("OpenOffice dictionary not configured");
        sb.append(text);
    } else {
        log.info("Using OpenOffice dictionary: {}", Config.SYSTEM_OPENOFFICE_DICTIONARY);
        ZipFile zf = new ZipFile(Config.SYSTEM_OPENOFFICE_DICTIONARY);
        OpenOfficeSpellDictionary oosd = new OpenOfficeSpellDictionary(zf);
        SpellChecker sc = new SpellChecker(oosd);
        sc.setCaseSensitive(false);
        StringTokenizer st = new StringTokenizer(text);

        while (st.hasMoreTokens()) {
            String w = st.nextToken();
            List<String> s = sc.getDictionary().getSuggestions(w);

            if (s.isEmpty()) {
                sb.append(w).append(" ");
            } else {
                sb.append(s.get(0)).append(" ");
            }
        }

        zf.close();
    }

    log.debug("spellChecker: {}", sb.toString());
    return sb.toString();
}

From source file:Main.java

/** Builds a parameter string based on the given parameters, separated by given delimiter, and optionally quoted values */
public static String buildParameterString(List<Pair<String, String>> parameters, String delimiter,
        boolean quote) throws UnsupportedEncodingException {

    if (parameters == null || parameters.isEmpty())
        return "";
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < parameters.size(); i++) {
        String key = parameters.get(i).first;
        String value = parameters.get(i).second;
        // skip 'null' values
        if (value == null)
            continue;
        String a = URLEncoder.encode(key, "UTF-8");
        String b = URLEncoder.encode(value, "UTF-8");
        builder.append(a + "="); // append key + "="
        if (quote)
            builder.append("\""); // optionally append quote
        builder.append(b); // append value
        if (quote)
            builder.append("\""); // optionally append quote
        if (i != parameters.size() - 1)
            builder.append(delimiter);/*from www  .  j ava  2 s  . com*/
    }
    return builder.toString();
}

From source file:com.fluke.application.IEODReader.java

static void processFolder(List<File> folders) throws IOException {
    List<File> newFolders = new ArrayList<>();
    for (File file : folders) {
        processChildren(file.listFiles(), newFolders);
    }/*from ww  w . j  a va 2s  .c  o m*/
    if (!newFolders.isEmpty()) {
        processFolder(newFolders);
    }
}