Example usage for java.util ArrayList isEmpty

List of usage examples for java.util ArrayList isEmpty

Introduction

In this page you can find the example usage for java.util ArrayList isEmpty.

Prototype

public boolean isEmpty() 

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:edu.lafayette.metadb.web.controlledvocab.ShowVocabList.java

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*///  w w  w .  j a  v a 2  s .c  o  m
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out = response.getWriter();
    String term = request.getParameter("term");
    term = term == null ? "" : term.toLowerCase();
    JSONArray vocabs = new JSONArray();
    try {
        String userName = null;
        HttpSession session = request.getSession(false);
        if (session != null)
            userName = (String) session.getAttribute("username");

        ArrayList<String> vocabList = new ArrayList<String>(ControlledVocabDAO.getControlledVocabs(userName));
        if (!vocabList.isEmpty()) {
            for (String v : vocabList) {
                if (v.toLowerCase().startsWith(term))
                    vocabs.put(v);
            }
        }
        out.print(vocabs);
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
    }
    out.flush();
}

From source file:com.brienwheeler.apps.main.MainBaseTest.java

@Test
public void testProcessBaseArgs() {
    String[] args = new String[] { P, TestDataConstants.PROPS_FILE1 };
    Main1 main = new Main1(args);

    System.clearProperty(TestDataConstants.PROPS_FILE1_PROP);
    Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE1_PROP));
    main.run();/*from   w w  w.j  av a2  s  .  c om*/
    Assert.assertEquals(TestDataConstants.PROPS_FILE1_VALUE,
            System.getProperty(TestDataConstants.PROPS_FILE1_PROP));
    ArrayList<String> processedArgs = main.getProcessedArgs();
    Assert.assertTrue(processedArgs.isEmpty());
}

From source file:com.btoddb.trellis.example.actors.MedianPersistenceProvider.java

DataPoint[] copyArrayAndInsertSorted(DataPoint[] oldRow, ArrayList<DataPoint> hpdList) {
    if (hpdList.isEmpty()) {
        return oldRow;
    }//from   w w w.j a v  a2 s  .com

    DataPoint[] newRow = new DataPoint[oldRow.length + hpdList.size()];
    int newIndex = 0;
    int nextHpdToCopy = 0;
    for (int oldIndex = 0; oldIndex < oldRow.length; oldIndex++) {
        for (int i = nextHpdToCopy; i < hpdList.size(); i++) {
            if (hpdList.get(i).getColName() <= oldRow[oldIndex].getColName()) {
                newRow[newIndex++] = hpdList.get(i);
                nextHpdToCopy = i + 1;
            } else {
                break;
            }
        }
        newRow[newIndex++] = oldRow[oldIndex];
    }

    for (int i = nextHpdToCopy; i < hpdList.size(); i++) {
        newRow[newIndex++] = hpdList.get(i);
    }

    return newRow;
}

From source file:com.dsh105.nexus.command.module.admin.ChannelCommand.java

@Override
public boolean onCommand(CommandPerformEvent event) {
    if (event.getArgs().length < 1 || event.getArgs().length > 3) {
        event.errorWithPing("Please specify both a channel and a command to disable ({0}).",
                event.getCommandPrefix() + event.getCommand() + " <channel> <command>");
        return true;
    }/*from   w w w.jav  a 2 s  .com*/

    String channel = event.getArgs()[0];
    ChannelConfig channelConfig = Nexus.getInstance().getChannelConfiguration().getChannel(channel);
    if (channelConfig == null) {
        event.errorWithPing("Commands cannot be disabled in a channel I am not present in ({0}).", channel);
        return true;
    }
    channel = channelConfig.getChannelName();

    if (event.getArgs().length == 1) {
        ArrayList<String> disabledCommands = channelConfig.getDisabledCommands();
        if (disabledCommands.isEmpty()) {
            event.respondWithPing("All commands are enabled in {0}.", channel);
        } else {
            event.respondWithPing("Disabled commands in {0}: " + StringUtil.join(disabledCommands, ", "),
                    channel);
        }
        return true;
    }

    String command = event.getArgs()[1];

    if (!command.equalsIgnoreCase("ALL")) {
        // Check if the command is valid
        CommandModule module = event.getManager().getModuleFor(command);
        if (module == null) {
            event.errorWithPing("{0} is not a valid command! Use {1} for help info.", command,
                    event.getCommandPrefix() + "help");
            return true;
        }
        command = module.info().command();
    }

    if (event.getArgs().length == 3) {
        boolean enable = BooleanUtils.toBoolean(event.getArgs()[2], "enable", "disable");
        channelConfig.setCommandStatus(command, enable);
        event.respondWithPing("{0} " + (enable ? "enabled" : "disabled") + " in {1}.",
                (command.equalsIgnoreCase("ALL") ? "All commands" : event.getCommandPrefix() + command),
                channel);
        return true;
    }

    if (command.equalsIgnoreCase("ALL")) {
        event.errorWithPing("Please use {0} to see if a command is disabled in a channel.",
                event.getCommandPrefix() + event.getCommand() + "<channel> <command>");
    }
    boolean enabled = channelConfig.isEnabled(command);
    event.respondWithPing("{0} is currently " + (enabled ? "enabled" : "disabled") + " in {1}.", command,
            channel);
    return true;
}

From source file:adalid.commons.properties.PropertiesHandler.java

private static File[] velocityFolders() {
    File file;/* w w w .  ja v a 2 s.co m*/
    ArrayList<File> files = new ArrayList<>();
    file = new File(USER_VELOCITY_RESOURCES_DIR);
    if (FilUtils.isVisibleDirectory(file)) {
        files.add(file);
    }
    String pathnames[] = getPathArray(VELOCITY_FOLDER_KEY);
    if (pathnames != null && pathnames.length > 0) {
        for (String pathname : pathnames) {
            file = new File(pathname);
            if (FilUtils.isVisibleDirectory(file)) {
                files.add(file);
            } else {
                logInvalidDirectory(VELOCITY_FOLDER_KEY, pathname);
            }
        }
    }
    if (files.isEmpty()) {
        logMissingProperty(VELOCITY_FOLDER_KEY);
        return null;
    }
    return files.toArray(new File[0]);
}

From source file:classif.random.DTWKNNClassifierRandom.java

@Override
protected void buildSpecificClassifier(Instances data) {
    indexPrototypeInTrainData = new ArrayList<Integer>();
    ArrayList<String> classes = new ArrayList<String>(classedData.keySet());

    RandomDataGenerator gen = new RandomDataGenerator();
    for (String clas : classes) {
        ArrayList<Sequence> cData = classedData.get(clas);
        // if the class is empty, skip it
        if (cData.isEmpty())
            continue;
        int maxElements = Math.min(nbPrototypesPerClass, cData.size());
        int[] selectedElements = gen.nextPermutation(cData.size(), maxElements);
        for (int i = 0; i < selectedElements.length; i++) {
            int indexInFullData = indexClassedDataInFullData.get(clas).get(selectedElements[i]);
            indexPrototypeInTrainData.add(indexInFullData);
            //            System.out.println("prototype "+i+" of class "+clas+" is element "+selectedElements[i]+" index in data="+indexInFullData);
            ClassedSequence prot = new ClassedSequence(cData.get(selectedElements[i]), clas);
            prototypes.add(prot);//from w w w  . j av a  2 s .  co  m
        }
    }

}

From source file:uk.ac.soton.itinnovation.sad.service.controllers.WorkflowsController.java

/**
 * Returns all workflows on the service, url mapping: /workflows
 *
 * @return all workflows as JSON//from  www  .  ja  v a 2s. com
 */
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public JsonResponse getWorkflows() {

    logger.debug("Returning all workflows");

    try {
        JSONObject response = new JSONObject();
        ArrayList<SADWorkflow> allWorkflows = schedulingService.getWorkflows();

        if (allWorkflows.isEmpty()) {
            logger.debug("No workflows were found.");
            response.put("num", 0);
            return new JsonResponse("ok", response);

        } else {
            int allWorkflowsSize = allWorkflows.size();
            response.put("num", allWorkflowsSize);
            JSONArray allWorkflowsAsJsonArray = new JSONArray();

            for (SADWorkflow theWorkflow : allWorkflows) {
                allWorkflowsAsJsonArray.add(schedulingService.workflowAsJson(theWorkflow));
            }

            if (allWorkflowsSize < 2) {
                logger.debug("Returning " + allWorkflows.size() + " workflow");
            } else {
                logger.debug("Returning " + allWorkflows.size() + " workflows");
            }
            response.put("list", allWorkflowsAsJsonArray);
            return new JsonResponse("ok", response);
        }

    } catch (Throwable ex) {
        return new JsonResponse("error", Util.dealWithException("Failed to return all workflows", ex, logger));
    }
}

From source file:edu.lafayette.metadb.model.dataman.DataImporter.java

/**
 * Import a list of attribtues into a project.
 * @param projectName The destination project.
 * @param header The list of attributes, which are typically headers in an imported data file.
 * @return a Result containing the result of the import.
 *///  w w  w.j  a  va2s  .c o  m
private static Result importAttributes(String projectName, String[] header) {
    Result res = new Result(false);
    if (header == null)
        return res;

    try {
        ArrayList<String> errorFields = new ArrayList<String>();
        for (String attribute : header) {
            String[] pair = attribute.split("\\.", 2);
            String element = pair[0].replace(" ", "_");
            String label = "";
            if (pair.length > 1)
                label = pair[1].replace(" ", "_");
            if (!AdminDescAttributesDAO.createAdminDescAttribute(projectName, element, label, "descriptive",
                    false, false, false, false, false, false, false, false)) {
                String field = element + (pair.length > 1 ? "" : "." + label);
                errorFields.add(field);
                if (!AdminDescAttributesDAO.createAdminDescAttribute(projectName, "description", field,
                        "descriptive", false, false, false, false, false, false, false, true))
                    throw new Exception("Cannot import header: " + projectName + " description " + field);
            }
        }
        if (!errorFields.isEmpty())
            res.setData(errorFields);
        else
            res.setResult(true);
    } catch (Exception e) {
        MetaDbHelper.logEvent(e);
        res.setResult(false);
    }
    return res;
}

From source file:fixio.netty.pipeline.TestRequestHandlerTest.java

@Test
public void testSkipOtherMessage() throws Exception {
    when(fixMessage.getMessageType()).thenReturn(MessageTypes.HEARTBEAT);

    ArrayList<Object> out = new ArrayList<>();
    handler.decode(ctx, fixMessage, out);

    verifyZeroInteractions(ctx);//from  w  w  w . j  a v a  2s.c  o m
    assertTrue(out.isEmpty());
}

From source file:org.khmeracademy.btb.auc.pojo.controller.Category_controller.java

@RequestMapping(value = "/get", method = RequestMethod.GET, produces = "application/json")
@ResponseBody//from  w w w . ja v a2s  .com
public ResponseEntity<Map<String, Object>> getCategories() {
    Map<String, Object> map = new HashMap<String, Object>();
    try {
        ArrayList<Category> cate = cate_service.getCategories();
        if (!cate.isEmpty()) {
            map.put("DATA", cate);
            map.put("STATUS", true);
            map.put("MESSAGE", "DATA FOUND!");
        } else {
            map.put("STATUS", true);
            map.put("MESSAGE", "DATA NOT FOUND");
        }
    } catch (Exception e) {
        map.put("STATUS", false);
        map.put("MESSAGE", "Error!");
        e.printStackTrace();
    }
    return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
}