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:gobblin.util.DatasetFilterUtils.java

/**
 * A topic survives if (1) it doesn't match the blacklist, and
 * (2) either whitelist is empty, or it matches the whitelist.
 * Whitelist and blacklist use regex patterns (NOT glob patterns).
 *//*  www .j  av  a  2s  .  c  o  m*/
public static boolean survived(String topic, List<Pattern> blacklist, List<Pattern> whitelist) {
    if (stringInPatterns(topic, blacklist)) {
        return false;
    }
    return (whitelist.isEmpty() || stringInPatterns(topic, whitelist));
}

From source file:net.sf.jabref.logic.journals.Abbreviations.java

public static void initializeJournalNames(JabRefPreferences jabRefPreferences) {
    journalAbbrev = new JournalAbbreviationRepository();

    // the order of reading the journal lists is important
    // method: last added abbreviation wins
    // for instance, in the personal list one can overwrite abbreviations in the built in list

    // Read builtin list
    journalAbbrev.readJournalListFromResource(JOURNALS_FILE_BUILTIN);

    // read IEEE list
    if (jabRefPreferences.getBoolean(JabRefPreferences.USE_IEEE_ABRV)) {
        journalAbbrev.readJournalListFromResource(JOURNALS_IEEE_ABBREVIATION_LIST_WITH_CODE);
    } else {/*from  w ww .  jav a  2  s.c  om*/
        journalAbbrev.readJournalListFromResource(JOURNALS_IEEE_ABBREVIATION_LIST_WITH_TEXT);
    }

    // Read external lists
    List<String> lists = jabRefPreferences.getStringList(JabRefPreferences.EXTERNAL_JOURNAL_LISTS);
    if (!(lists.isEmpty())) {
        Collections.reverse(lists);
        for (String filename : lists) {
            try {
                journalAbbrev.readJournalListFromFile(new File(filename));
            } catch (FileNotFoundException e) {
                // The file couldn't be found... should we tell anyone?
                LOGGER.info("Cannot find external journal list file " + filename, e);
            }
        }
    }

    // Read personal list
    String personalJournalList = jabRefPreferences.get(JabRefPreferences.PERSONAL_JOURNAL_LIST);
    if ((personalJournalList != null) && !personalJournalList.trim().isEmpty()) {
        try {
            journalAbbrev.readJournalListFromFile(new File(personalJournalList));
        } catch (FileNotFoundException e) {
            LOGGER.info("Personal journal list file '" + personalJournalList + "' not found.", e);
        }
    }

}

From source file:Main.java

private static List<Object> interleave(Collection<? extends Object> collection, String separator) {
    List<Object> interleaved = new ArrayList<Object>();
    for (Object object : collection) {
        interleaved.add(object);/*from   w ww.ja v a2s .c o  m*/
        interleaved.add(separator);
    }
    if (!interleaved.isEmpty()) {
        interleaved.remove(interleaved.size() - 1);
    }
    return interleaved;
}

From source file:com.fizzed.stork.launcher.Merger.java

static public void merge(List<File> configFiles, File outputFile) throws IOException {
    // validate required arguments
    if (configFiles == null || configFiles.isEmpty()) {
        throw new IllegalArgumentException("No input config files were found");
    }/*from   ww w . j a v  a 2 s .  c o  m*/

    if (outputFile == null) {
        throw new IOException("no output file was specified");
    }

    ConfigurationFactory factory = new ConfigurationFactory();
    JsonNode mergedNode = null;

    // parse each configuration file into a configuration object
    for (File configFile : configFiles) {
        try {
            JsonNode updateNode = factory.createConfigNode(configFile);
            if (mergedNode == null) {
                mergedNode = updateNode;
            } else {
                mergedNode = factory.mergeNodes(mergedNode, updateNode);
            }
        } catch (Exception e) {
            throw new IOException("Config file [" + configFile + "] invalid");
        }
    }

    try {
        // write merged file back out
        factory.getMapper().writeValue(outputFile, mergedNode);
        System.out.println("Wrote merged config file: " + outputFile);
    } catch (Exception e) {
        throw new IOException("Unable to cleanly write merged config");
    }
}

From source file:com.comcast.cats.monitor.util.FileSearchUtil.java

public static List<String> getLinesByRegexList(String filePath, List<String> expressions) throws IOException {
    if ((null == expressions) || (expressions.isEmpty()) || (null == filePath) || (filePath.isEmpty())) {
        throw new IllegalArgumentException("Expressions/FilePath is NULL of EMPTY !!!");
    }//from w  w w .  j a  v a2  s  .  c o m

    String combainedExpression = null;

    for (String expression : expressions) {
        combainedExpression += OR + expression;
    }

    return getLinesByRegex(filePath, combainedExpression);
}

From source file:com.ciphertool.sentencebuilder.dao.BasicWordMapDao.java

/**
 * @param allWords/*from  ww  w .  j  a  va  2s  . com*/
 *            the List of all Words pulled in from the constructor
 * @return a Map of all Words keyed by their PartOfSpeech
 */
protected static HashMap<PartOfSpeechType, ArrayList<Word>> mapByPartOfSpeech(List<Word> allWords) {
    if (allWords == null || allWords.isEmpty()) {
        throw new IllegalArgumentException(
                "Error mapping Words by PartOfSpeech.  The supplied List of Words cannot be null or empty.");
    }

    HashMap<PartOfSpeechType, ArrayList<Word>> byPartOfSpeech = new HashMap<PartOfSpeechType, ArrayList<Word>>();
    for (Word w : allWords) {
        PartOfSpeechType pos = w.getId().getPartOfSpeech();

        // Add the part of speech to the map if it doesn't exist
        if (!byPartOfSpeech.containsKey(pos)) {
            byPartOfSpeech.put(pos, new ArrayList<Word>());
        }

        /*
         * Add the word to the map by reference a number of times equal to
         * the frequency value
         */
        for (int i = 0; i < w.getFrequencyWeight(); i++) {
            byPartOfSpeech.get(pos).add(w);
        }
    }
    return byPartOfSpeech;
}

From source file:de.oth.keycloak.initKeycloakServer.IT_TestAuth.java

@BeforeClass
public static void setUpClass() throws IOException {
    keycloak = initKeycloak(SERVER, REALM, USER, PWD, CLIENTSTR);
    String initFileStr = "integration_test_config.json";
    File initFile = new File(initFileStr);
    if (!initFile.isFile()) {
        URL url = TestRun.class.getClassLoader().getResource(initFileStr);
        if (url != null) {
            initFile = new File(url.getFile());
            if (!initFile.isFile()) {
                fail("test config is no file: " + initFileStr);
            }// w w w .  j  a  v a  2 s .  c  om
        } else {
            fail("can't load test config: " + initFileStr);
        }
    }

    RealmResource rRes = KeycloakAccess.getRealm(keycloak, GM_REALM, false);
    if (rRes != null) {
        rRes.remove();
    }
    rRes = KeycloakAccess.getRealm(keycloak, APP_REALM, false);
    if (rRes != null) {
        rRes.remove();
    }
    ObjectMapper mapper = new ObjectMapper();
    RealmsConfig realmsConfig = mapper.readValue(initFile, RealmsConfig.class);

    if (realmsConfig != null) {
        List<RealmConfig> realmList = realmsConfig.getRealms();
        if (realmList == null || realmList.isEmpty()) {
            fail("realmList is empty: " + initFileStr);
        }
        for (RealmConfig realmConf : realmList) {
            InitKeycloakServer.addRealm(keycloak, realmConf);
        }
    } else {
        fail("no realm config found in: " + initFileStr);
    }
}

From source file:com.ciphertool.sentencebuilder.dao.BasicWordMapDao.java

/**
 * @param allWords//from   www.j  a  va 2 s.  co m
 *            the List of all Words pulled in from the constructor
 * @return a Map of all Words keyed by their length
 */
protected static HashMap<Integer, ArrayList<Word>> mapByWordLength(List<Word> allWords) {
    if (allWords == null || allWords.isEmpty()) {
        throw new IllegalArgumentException(
                "Error mapping Words by length.  The supplied List of Words cannot be null or empty.");
    }

    HashMap<Integer, ArrayList<Word>> byWordLength = new HashMap<Integer, ArrayList<Word>>();

    for (Word w : allWords) {
        Integer length = w.getId().getWord().length();

        // Add the part of speech to the map if it doesn't exist
        if (!byWordLength.containsKey(length)) {
            byWordLength.put(length, new ArrayList<Word>());
        }

        /*
         * Add the word to the map by reference a number of times equal to
         * the frequency value
         */
        for (int i = 0; i < w.getFrequencyWeight(); i++) {
            byWordLength.get(length).add(w);
        }
    }

    return byWordLength;
}

From source file:Main.java

/**
 * @param n a root node to search beneath
 * @param name a node name to look for/*from ww w  .j a v a 2  s .  c om*/
 * @return the first instance of that node name in the tree beneath the root
 * (depth first)
 */
public static Node findFirstNodeRecursive(Node n, String name) {
    List<Node> nodes = new ArrayList<>();
    findRecursive(n, name, nodes, true);
    if (nodes.isEmpty()) {
        return null;
    }
    return nodes.get(0);
}

From source file:Main.java

/**
 * Gets the first direct child of the given node with a node named {@code nodeName} that has an
 * attribute named {@code attributeName} with a value that matches one of {@code attributeValues}.
 *
 * Only direct children are checked./*from   w  w  w .  j a va  2 s.c  o m*/
 *
 * @param nodeName matching nodes must have this name.
 * @param attributeName matching nodes must have an attribute with this name.
 *                      Use null to match nodes with any attributes.
 * @param attributeValues all matching child nodes' matching attribute will have a value that
 *                        matches one of these values. Use null to match nodes with any attribute
 *                        value.
 */
static Node getFirstMatchingChildNode(final Node node, final String nodeName, final String attributeName,
        final List<String> attributeValues) {
    if (node == null || nodeName == null) {
        return null;
    }

    final List<Node> nodes = getMatchingChildNodes(node, nodeName, attributeName, attributeValues);
    if (nodes != null && !nodes.isEmpty()) {
        return nodes.get(0);
    }
    return null;
}