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:com.vmware.bdd.specpolicy.TemplateClusterSpec.java

private static void createTemplate(Reader fileReader) {
    Gson gson = new Gson();
    templateClusterConfig = gson.fromJson(fileReader, ClusterCreate.class);
    NodeGroupCreate[] groups = templateClusterConfig.getNodeGroups();
    if (groups == null || groups.length == 0) {
        throw TemplateClusterException.TEMPLATE_NODEGROUPS_UNDEFINED();
    }//from ww w . j av a 2  s .  c om
    EnumSet<HadoopRole> allRoles = EnumSet.noneOf(HadoopRole.class);
    for (NodeGroupCreate group : groups) {
        List<String> roles = group.getRoles();
        if (roles == null || roles.isEmpty()) {
            throw TemplateClusterException.TEMPLATE_ROLES_EMPTY(group.getName());
        }
        EnumSet<HadoopRole> enumRoles = EnumSet.noneOf(HadoopRole.class);
        for (String role : roles) {
            HadoopRole configuredRole = HadoopRole.fromString(role);
            if (configuredRole == null) {
                throw ClusterConfigException.UNSUPPORTED_HADOOP_ROLE(role, templateClusterConfig.getDistro());
            }
            enumRoles.add(configuredRole);
        }
        GroupType type = GroupType.fromHadoopRole(enumRoles);
        group.setGroupType(type);
        templateGroups.put(type, group);
        allRoles.addAll(enumRoles);
    }
    if (!templateGroups.containsKey(GroupType.MASTER_JOBTRACKER_GROUP)) {
        templateGroups.put(GroupType.MASTER_JOBTRACKER_GROUP, templateGroups.get(GroupType.MASTER_GROUP));
    }
    if (allRoles.size() < HadoopRole.values().length) {
        throw TemplateClusterException.INCOMPLETE_TEMPLATE_GROUPS();
    }
}

From source file:com.weibo.api.motan.config.AbstractConfig.java

protected static void collectMethodConfigParams(Map<String, String> parameters, List<MethodConfig> methods) {
    if (methods == null || methods.isEmpty()) {
        return;//  w w  w  .j  a v a2 s . c  om
    }
    for (MethodConfig mc : methods) {
        if (mc != null) {
            mc.appendConfigParams(parameters,
                    MotanConstants.METHOD_CONFIG_PREFIX + mc.getName() + "(" + mc.getArgumentTypes() + ")");
        }
    }
}

From source file:gov.medicaid.services.util.Util.java

/**
 * Checks of the given list contains any elements.
 *
 * @param values the list to check/*from   w w w .j  av  a2s  . c o m*/
 * @return true if the list is null or empty
 */
@SuppressWarnings("rawtypes")
public static boolean isEmpty(List values) {
    return values == null || values.isEmpty();
}

From source file:Main.java

public static int[] toPrimitive(final List<Integer> array) {
    if (array == null) {
        return null;
    }/*  ww w  .  j  a v a 2  s .c  o  m*/
    if (array.isEmpty()) {
        return EMPTY_INT_ARRAY;
    }
    final int[] result = new int[array.size()];
    for (int i = 0; i < array.size(); i++) {
        result[i] = array.get(i).intValue();
    }
    return result;
}

From source file:com.logsniffer.reader.filter.FilteredLogEntryReader.java

/**
 * Returns a {@link FilteredLogEntryReader} wrapping the given reader in
 * case filters are defined. In case filters are null or empty the current
 * reader is returned back without wrapping.
 * //from   w w  w .  j  a  v a  2s  .co  m
 * @param targetReader
 *            the target reader to wrapp for filtering
 * @param filters
 *            filters maybe null or empty
 * @return a {@link FilteredLogEntryReader} wrapping the given reader in
 *         case filters are defined. In case filters are null or empty the
 *         current reader is returned back without wrapping.
 */
public static <ACCESSTYPE extends LogRawAccess<? extends LogInputStream>> LogEntryReader<ACCESSTYPE> wrappIfNeeded(
        final LogEntryReader<ACCESSTYPE> targetReader, final List<FieldsFilter> filters) {
    if (filters != null && !filters.isEmpty()) {
        return new FilteredLogEntryReader<>(targetReader, filters);
    }
    return targetReader;
}

From source file:edu.slu.tpen.transfer.JsonImporter.java

/**
 * Given a Tradamus canvas and a T-PEN folio, get the corresponding image URI which both are using.
 *
 * @param canvData JSON object containing Tradamus canvas data
 * @param f T-PEN folio/*from w w w .  ja va 2  s  .c o  m*/
 * @return true if they represent the same page
 */
private static String getFolioURI(Map<String, Object> canvData, Folio f) throws IOException, SQLException {
    List<Object> images = getArray(canvData, "images", true);
    if (images == null || images.isEmpty()) {
        // This is a text-only (imageless) transcription.  T-PEN has no way of handling this.
        throw new IOException("Malformed JSON input: canvas with no images.");
    }

    String folioURI = Folio.getRbTok("SERVERURL") + f.getImageURLResize();

    for (Object o : images) {
        if (!(o instanceof Map)) {
            throw new IOException("Malformed JSON input: images entry is not an object.");
        }
        String imageURI = (String) ((Map<String, Object>) o).get("uri");
        if (imageURI == null) {
            throw new IOException("Malformed JSON input: missing URI for image.");
        }
        if (imageURI.equals(folioURI)) {
            return folioURI;
        }
    }
    return null;
}

From source file:net.giovannicapuano.galax.util.Utils.java

/**
 * Convert geographic coordinates to a human-readable address.
 *///  w  w w  .  ja  va2 s .com
public static String coordinatesToAddress(double latitude, double longitude, Context context) {
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
    if (!Geocoder.isPresent())
        return "";

    try {
        List<Address> addresses = geocoder.getFromLocation(latitude, longitude, 1);

        if (addresses != null && !addresses.isEmpty()) {
            Address returnedAddress = addresses.get(0);
            StringBuilder address = new StringBuilder();
            for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); ++i)
                address.append(returnedAddress.getAddressLine(i)).append("\n");
            return address.toString();
        } else {
            return "";
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

From source file:com.asakusafw.testdriver.tools.runner.BatchTestVerifier.java

/**
 * Program entry./*from  w w  w  .j a  v  a 2  s  . co m*/
 * @param args program arguments
 * @return the exit code
 */
public static int execute(String[] args) {
    Conf conf;
    try {
        conf = parseArguments(args);
    } catch (Exception e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.setWidth(Integer.MAX_VALUE);
        formatter.printHelp(MessageFormat.format("java -classpath ... {0}", //$NON-NLS-1$
                BatchTestRunner.class.getName()), OPTIONS, true);
        LOG.error(MessageFormat.format(Messages.getString("BatchTestVerifier.errorInvalidArgument"), //$NON-NLS-1$
                Arrays.toString(args)), e);
        return 1;
    }
    try {
        BatchTestVerifier verifier = new BatchTestVerifier(conf.context);
        List<Difference> diffList = verifier.verify(conf.exporter, conf.data, conf.rule);
        if (diffList.isEmpty()) {
            LOG.info(Messages.getString("BatchTestVerifier.infoSuccess")); //$NON-NLS-1$
            return 0;
        } else {
            for (Difference diff : diffList) {
                LOG.error(diff.toString());
            }
            return 1;
        }
    } catch (Exception e) {
        LOG.error(MessageFormat.format(Messages.getString("BatchTestVerifier.errorFailedToVerifyResult"), //$NON-NLS-1$
                Arrays.toString(args)), e);
        return 1;
    }
}

From source file:com.github.drochetti.javassist.maven.ClassnameExtractor.java

/**
 * Wrapping passed list (as reference) of class file names and extract full qualified class name on
 * {@link Iterator#next()}./*w ww  .  j  av  a 2 s.c  o m*/
 * <p>
 * It is possible that {@link Iterator#hasNext()} returns <code>true</code>
 * and {@link Iterator#next()} returns <code>null</code>.
 * 
 * @param parentDirectory
 * @param classFiles
 * @return list of full qualified class names based on passed classFiles or
 *         <code>null</code>
 * @throws IOException
 * @see {@link #extractClassNameFromFile(File, File)}
 */
// DANGEROUS call by reference
public static List<String> listClassnames(final File parentDirectory, final List<File> classFileList)
        throws IOException {
    if (null == classFileList || classFileList.isEmpty()) {
        return Collections.emptyList();
    }
    final List<String> list = new ArrayList<String>(classFileList.size());
    for (final File file : classFileList) {
        list.add(extractClassNameFromFile(parentDirectory, file));
    }
    return list;
}

From source file:com.github.rinde.opt.localsearch.Insertions.java

/**
 * Inserts <code>item</code> in the specified indices in the
 * <code>originalList</code>.
 * @param originalList The list which will be inserted by <code>item</code>.
 * @param insertionIndices List of insertion indices in ascending order.
 * @param item The item to insert.//  w  w  w . j  av a2  s .com
 * @param <T> The list item type.
 * @return A list based on the original list but inserted with item in the
 *         specified places.
 */
public static <T> ImmutableList<T> insert(List<T> originalList, List<Integer> insertionIndices, T item) {
    checkArgument(!insertionIndices.isEmpty(), "At least one insertion index must be defined.");
    int prev = 0;
    final ImmutableList.Builder<T> builder = ImmutableList.<T>builder();
    for (int i = 0; i < insertionIndices.size(); i++) {
        final int cur = insertionIndices.get(i);
        checkArgument(cur >= 0 && cur <= originalList.size(),
                "The specified indices must be >= 0 and <= %s (list size), it is %s.", originalList.size(),
                cur);
        checkArgument(cur >= prev, "The specified indices must be in ascending order. Received %s.",
                insertionIndices);
        builder.addAll(originalList.subList(prev, cur));
        builder.add(item);
        prev = cur;
    }
    builder.addAll(originalList.subList(prev, originalList.size()));
    return builder.build();
}