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:net.securnetwork.itebooks.downloader.EbookDownloader.java

private static int getLastEbookIndex() {
    try {/*from  w  ww .  j  a  v a  2 s  . c  o  m*/
        Source sourceHTML = new Source(new URL(BASE_URL));
        List<Element> allTDs = sourceHTML.getAllElements(HTMLElementName.TD);
        for (Element td : allTDs) {
            List<Element> innerH2s = td.getAllElements(HTMLElementName.H2);
            if (!innerH2s.isEmpty() && "Last Upload Ebooks".equalsIgnoreCase( //$NON-NLS-1$
                    innerH2s.get(0).getTextExtractor().toString())) {
                // Found interesting section
                List<Element> allTDElements = td.getAllElements(HTMLElementName.TD);
                Element lastEbookLink = allTDElements.get(0).getAllElements(HTMLElementName.A).get(0);
                String lastEbookRelativeHref = lastEbookLink.getAttributeValue("href"); //$NON-NLS-1$
                StringTokenizer tokenizer = new StringTokenizer(lastEbookRelativeHref, "/"); //$NON-NLS-1$
                for (int i = 1; i < tokenizer.countTokens(); i++) {
                    tokenizer.nextToken();
                }
                return Integer.parseInt(tokenizer.nextToken());
            }

        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return MAX_EBOOK_INDEX;
}

From source file:com.orange.ngsi.server.NgsiValidation.java

private static boolean nullOrEmpty(List e) {
    return e == null || e.isEmpty();
}

From source file:edu.uci.ics.hyracks.control.cc.partitions.PartitionMatchMaker.java

private static <T> void removeEntries(Map<PartitionId, List<T>> map, IEntryFilter<T> filter) {
    Iterator<Map.Entry<PartitionId, List<T>>> i = map.entrySet().iterator();
    while (i.hasNext()) {
        Map.Entry<PartitionId, List<T>> e = i.next();
        List<T> list = e.getValue();
        removeEntries(list, filter);/* ww w  . ja v  a  2 s .com*/
        if (list.isEmpty()) {
            i.remove();
        }
    }
}

From source file:com.liferay.apio.architect.internal.annotation.representor.processor.TypeProcessor.java

private static ParsedType _processType(Class<?> typeClass, boolean nested) {
    Type type = typeClass.getAnnotation(Type.class);

    Builder builder = new Builder(type, typeClass);

    if (!nested) {
        Method idMethod = Try.fromFallible(() -> getMethodsListWithAnnotation(typeClass, Id.class))
                .filter(methods -> !methods.isEmpty()).map(methods -> methods.get(0)).orElse(null);

        builder.idMethod(idMethod);/* ww  w .  ja v  a  2  s  . c o  m*/
    }

    List<Method> methods = getMethodsListWithAnnotation(typeClass, Field.class);

    methods.forEach(method -> _processMethod(builder, method));

    return builder.build();
}

From source file:com.yahoo.sql4d.sql4ddriver.Util.java

public static <T extends DruidBaseBean> void printTable(List<T> baseAllRows) {
    if (baseAllRows == null || baseAllRows.isEmpty()) {
        return;/*from  w w  w .  j av a  2s. co m*/
    }
    List<Method> setters = getAllSetters(baseAllRows.get(0).getClass());
    for (Method setter : setters) {
        printf("%-10s  |", setter.getName().substring(3));
    }
    newLine();
    List<Method> getters = getAllGetters(baseAllRows.get(0).getClass());
    for (T row : baseAllRows) {
        for (Method getter : getters) {
            try {
                printf("%-10s  |", getter.invoke(row));
            } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        newLine();
    }
}

From source file:com.google.openrtb.json.OpenRtbJsonUtils.java

/**
 * Writes a long array if not empty, using quotes for values that are too big.
 *
 * @see #writeLong(long, JsonGenerator)/*from   w  ww.  j a  v a 2  s.  c om*/
 */
public static void writeLongs(String fieldName, List<Long> data, JsonGenerator gen) throws IOException {
    if (!data.isEmpty()) {
        gen.writeArrayFieldStart(fieldName);
        for (long d : data) {
            writeLong(d, gen);
        }
        gen.writeEndArray();
    }
}

From source file:com.mxep.web.common.persistence.DynamicSpecifications.java

public static <T> Specification<T> bySearchFilter(final Collection<SearchFilter> filters,
        final Class<T> entityClazz) {
    return new Specification<T>() {
        @Override/*from w  w  w  .ja v a2 s  . c o  m*/
        public Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
            if (Collections3.isNotEmpty(filters)) {
                List<Predicate> predicates = getPredicate(filters, root, query, builder);
                // ? and ???
                if (!predicates.isEmpty()) {
                    return builder.and(predicates.toArray(new Predicate[predicates.size()]));
                }
            }
            return builder.conjunction();
        }
    };
}

From source file:com.netflix.spinnaker.halyard.cli.ui.v1.AnsiFormatUtils.java

public static String format(Provider provider) {
    AnsiStoryBuilder resultBuilder = new AnsiStoryBuilder();
    AnsiParagraphBuilder paragraph = resultBuilder.addParagraph();

    paragraph.addSnippet(provider.getNodeName().toUpperCase()).addStyle(AnsiStyle.BOLD);
    paragraph.addSnippet(" provider");

    resultBuilder.addNewline();/*  ww  w . java 2 s  . co m*/

    paragraph = resultBuilder.addParagraph();

    paragraph.addSnippet("enabled: " + provider.isEnabled());

    paragraph = resultBuilder.addParagraph();
    paragraph.addSnippet("accounts: ");

    List<Account> accounts = provider.getAccounts();
    if (accounts == null || accounts.isEmpty()) {
        paragraph.addSnippet("[]");
    } else {
        accounts.forEach(account -> {
            AnsiParagraphBuilder list = resultBuilder.addParagraph().setIndentFirstLine(true).setIndentWidth(1);
            list.addSnippet("- ");
            list.addSnippet(account.getName());
        });
    }

    return resultBuilder.toString();
}

From source file:com.google.openrtb.json.OpenRtbJsonUtils.java

/**
 * Writes a string array if not empty./*from   ww  w . ja  v a  2s  .  c o m*/
 */
public static void writeStrings(String fieldName, List<String> data, JsonGenerator gen) throws IOException {
    if (!data.isEmpty()) {
        gen.writeArrayFieldStart(fieldName);
        for (String d : data) {
            gen.writeString(d);
        }
        gen.writeEndArray();
    }
}