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:io.fabric8.vertx.maven.plugin.components.impl.GroovyExtensionCombiner.java

private static byte[] read(List<String> lines) {
    if (lines == null || lines.isEmpty()) {
        return new byte[0];
    }//w  ww . j  ava  2s . co m
    StringBuilder buffer = new StringBuilder();
    for (String l : lines) {
        buffer.append(l).append("\n");
    }
    return buffer.toString().getBytes();
}

From source file:Main.java

public static boolean isFlashSupported(Camera camera) {
    /* Credits: Top answer at http://stackoverflow.com/a/19599365/868173 */
    if (camera != null) {
        Camera.Parameters parameters = camera.getParameters();

        if (parameters.getFlashMode() == null) {
            return false;
        }/*w  w w . j  av a 2  s . c o m*/

        List<String> supportedFlashModes = parameters.getSupportedFlashModes();
        if (supportedFlashModes == null || supportedFlashModes.isEmpty() || supportedFlashModes.size() == 1
                && supportedFlashModes.get(0).equals(Camera.Parameters.FLASH_MODE_OFF)) {
            return false;
        }
    } else {
        return false;
    }

    return true;
}

From source file:Main.java

public static byte[] toPrimitiveByte(final List<Byte> array) {
    if (array == null) {
        return null;
    }//  w ww  . j ava  2  s  . c  o  m
    if (array.isEmpty()) {
        return EMPTY_BYTE_ARRAY;
    }
    final byte[] result = new byte[array.size()];
    for (int i = 0; i < array.size(); i++) {
        result[i] = array.get(i).byteValue();
    }
    return result;
}

From source file:Main.java

/**
 * Gets the immediately child element from the parent element.
 * //www.j a  va  2 s.  co m
 * @param parent the parent element in the element tree
 * @param tagName the specified tag name
 * @return immediately child element of parent element, NULL otherwise
 */
public static Element getChildElement(Element parent, String tagName) {
    List<Element> children = getChildElements(parent, tagName);

    if (children.isEmpty()) {
        return null;
    } else {
        return children.get(0);
    }
}

From source file:Main.java

/**
 * Gets the first element of the list. If the list is null or empty, null
 * is returned./*from   w w w  . j  a v a  2  s  .c om*/
 *
 * @param   <T>
 *      The type of element in the list.
 * @param   list
 *      The list to get the first element from.
 * @return
 *      The first element from the list, if one exists. Otherwise, null.
 */
public static <T> T getFirst(final List<? extends T> list) {
    if (list == null || list.isEmpty()) {
        return null;
    } else {
        return list.get(0);
    }
}

From source file:com.edmunds.etm.tools.urltoken.util.OptionUtils.java

public static String firstNonOptionArgument(OptionSet options) {
    List<String> arguments = options.nonOptionArguments();
    if (arguments.isEmpty()) {
        return null;
    }//  w w  w. java 2 s .c o m

    String tokenName = arguments.get(0);
    if (StringUtils.isBlank(tokenName)) {
        return null;
    }

    return tokenName;
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesSelector.java

public static KubernetesSelector contains(String key, List<String> values) {
    if (values == null || values.isEmpty()) {
        throw new IllegalArgumentException("At least one value must be supplied to a 'contains' selector");
    }//from w ww . j a v  a  2 s  .c o  m

    return new KubernetesSelector(Kind.CONTAINS, key, values);
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesSelector.java

public static KubernetesSelector notContains(String key, List<String> values) {
    if (values == null || values.isEmpty()) {
        throw new IllegalArgumentException("At least one value must be supplied to a 'notcontains' selector");
    }// w w w  .  j a va2s .  co m

    return new KubernetesSelector(Kind.NOT_CONTAINS, key, values);
}

From source file:Main.java

public static String getLocality(Context context) {
    @SuppressWarnings("static-access")
    LocationManager lm = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
    if (lm == null)
        return "";
    Location l = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    if (l == null)
        return "";
    Geocoder gc = new Geocoder(context);

    try {//w w w .  j av a2  s. co  m
        List<Address> address = gc.getFromLocation(l.getLatitude(), l.getLongitude(), 1);
        if (address != null && address.isEmpty() == false)
            return address.get(0).getLocality();
    } catch (Exception e) {
        return "";
    }

    return "";
}

From source file:Main.java

public static char[] toPrimitiveChar(final List<Integer> array) {
    if (array == null) {
        return null;
    }//from  ww w  .j a va2  s .c o m
    if (array.isEmpty()) {
        return EMPTY_CHAR_ARRAY;
    }
    final char[] result = new char[array.size()];
    for (int i = 0; i < array.size(); i++) {
        result[i] = (char) array.get(i).byteValue();
    }
    return result;
}