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:com.clustercontrol.maintenance.factory.MaintenanceCollectDataRaw.java

/**
 * ?/*from   w w w . j a  v a 2  s  . c o m*/
 */
@Override
protected int _delete(Long boundary, boolean status, String ownerRoleId) {
    int ret = 0;
    JpaTransactionManager jtm = null;

    try {
        //AdminRole???ID??????
        if (RoleIdConstant.isAdministratorRole(ownerRoleId)) {
            jtm = new JpaTransactionManager();
            jtm.begin();
            ret = delete(boundary, status);
            jtm.commit();

        } else {
            ArrayList<MonitorInfo> monitorList = new MonitorSettingControllerBean().getMonitorList();

            ArrayList<String> monitorIdList = new ArrayList<>();

            for (MonitorInfo monitorInfo : monitorList) {
                if (RoleIdConstant.isAdministratorRole(ownerRoleId)
                        || monitorInfo.getOwnerRoleId().equals(ownerRoleId)) {
                    monitorIdList.add(monitorInfo.getMonitorId());
                }
            }

            if (monitorIdList.isEmpty()) {
                return -1;
            }
            jtm = new JpaTransactionManager();
            jtm.begin();

            for (int i = 0; i < monitorIdList.size(); i++) {
                ret += delete(boundary, status, monitorIdList.get(i));
                jtm.commit();
            }
        }
    } catch (Exception e) {
        m_log.warn("deleteCollectData() : " + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        if (jtm != null)
            jtm.rollback();
    } finally {
        if (jtm != null)
            jtm.close();
    }
    return ret;
}

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

@RequestMapping(value = "/get-by-brand/{brand_id}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody//from  w w w  .j  a v a2s  . co m
public ResponseEntity<Map<String, Object>> getAuctionsByBrand(
        @RequestParam(value = "page", required = false, defaultValue = "1") int page,
        @RequestParam(value = "limit", required = false, defaultValue = "6") int limit,
        @PathVariable("brand_id") int id) {
    Map<String, Object> map = new HashMap<String, Object>();
    try {
        Pagination pagination = new Pagination();
        pagination.setLimit(limit);
        pagination.setPage(page);
        pagination.setTotalCount(auc_service.countAuctionByBrand(id));
        ArrayList<Auction_Detail> auction = auc_service.getAuctionsByBrand(pagination, id);
        if (!auction.isEmpty()) {
            map.put("DATA", auction);
            map.put("STATUS", true);
            map.put("MESSAGE", "DATA FOUND!");
            map.put("PAGINATION", pagination);
        } 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);
}

From source file:edu.uah.itsc.aws.S3.java

/**
 * This method deletes files from a bucket. Array list of string of files to be deleted and bucket should be
 * provided/*w  w w. j a  v  a 2s.c om*/
 * 
 * @param selectedFiles
 * @param bucketName
 */
public void deleteFilesFromBucket(ArrayList<String> selectedFiles, String bucketName) {
    if (selectedFiles.isEmpty())
        return;
    DeleteObjectsRequest deleteRequest = new DeleteObjectsRequest(bucketName);
    ArrayList<KeyVersion> keys = new ArrayList<KeyVersion>();
    for (String selectedFile : selectedFiles) {
        KeyVersion keyVersion = new KeyVersion(selectedFile);
        keys.add(keyVersion);
    }
    deleteRequest.setKeys(keys);
    try {
        DeleteObjectsResult deleteResult = amazonS3Service.deleteObjects(deleteRequest);
        System.out.format("Successfully deleted %s items\n", deleteResult.getDeletedObjects().size());
    } catch (MultiObjectDeleteException e) {
        e.printStackTrace();
        for (DeleteError deleteError : e.getErrors()) {
            System.out.format("Object Key: %s\t%s\t%s\n", deleteError.getKey(), deleteError.getCode(),
                    deleteError.getMessage());
        }
    }
}

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

@RequestMapping(value = "/get-by-category/{cat_id}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody//w w w  . j a v  a 2s .c o m
public ResponseEntity<Map<String, Object>> getAuctionsByCategory(
        @RequestParam(value = "page", required = false, defaultValue = "1") int page,
        @RequestParam(value = "limit", required = false, defaultValue = "6") int limit,
        @PathVariable("cat_id") int id) {
    Map<String, Object> map = new HashMap<String, Object>();
    try {
        Pagination pagination = new Pagination();
        pagination.setLimit(limit);
        pagination.setPage(page);
        pagination.setTotalCount(auc_service.countAuctionByCategory(id));
        ArrayList<Auction_Detail> auction = auc_service.getAuctionsByCategory(pagination, id);
        if (!auction.isEmpty()) {
            map.put("DATA", auction);
            map.put("STATUS", true);
            map.put("MESSAGE", "DATA FOUND!");
            map.put("PAGINATION", pagination);
        } 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);
}

From source file:com.fitbur.testify.system.SpringSystemTest.java

public ServerContext getServerContext(TestContext testContext, String methodName) {
    Object testInstance = testContext.getTestInstance();
    return testContext.getAnnotation(App.class).map(p -> {
        Class<?> appType = p.value();
        ServiceLoader<ServerProvider> serviceLoader = ServiceLoader.load(ServerProvider.class);
        ArrayList<ServerProvider> serverProviders = Lists.newArrayList(serviceLoader);

        checkState(!serverProviders.isEmpty(),
                "ServiceProvider provider implementation not found in the classpath");

        checkState(serverProviders.size() == 1,
                "Multiple ServiceProvider provider implementations found in the classpath. "
                        + "Please insure there is only one ServiceProvider provider implementation "
                        + "in the classpath.");
        ServerProvider provider = serverProviders.get(0);

        interceptor = new SpringSystemServletInterceptor(testContext, methodName, serviceAnnotations,
                classTestNeeds, classTestNeedContainers);

        Class<?> proxyAppType = BYTE_BUDDY.subclass(appType).method(not(isDeclaredBy(Object.class)))
                .intercept(to(interceptor).filter(not(isDeclaredBy(Object.class)))).make()
                .load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();

        Set<Class<?>> handles = new HashSet<>();
        handles.add(proxyAppType);/*from  w  ww .j av a 2  s  .c  om*/
        SpringServletContainerInitializer initializer = new SpringServletContainerInitializer();

        SpringSystemServerDescriptor descriptor = new SpringSystemServerDescriptor(p, testContext, initializer,
                handles);

        Object configuration = provider.configuration(descriptor);
        testContext.getConfigMethod(configuration.getClass()).map(m -> m.getMethod()).ifPresent(m -> {
            AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
                try {
                    m.setAccessible(true);
                    m.invoke(testInstance, configuration);
                } catch (Exception e) {
                    checkState(false, "Call to config method '%s' in test class '%s' failed.", m.getName(),
                            descriptor.getTestClassName());
                    throw Throwables.propagate(e);
                }

                return null;
            });
        });

        ServerInstance serverInstance = provider.init(descriptor, configuration);
        serverInstance.start();

        SpringServiceLocator serviceLocator = interceptor.getServiceLocator();

        serviceLocator.addConstant(serverInstance.getClass().getSimpleName(), serverInstance);

        ServerContext serverContext = new ServerContext(provider, descriptor, serverInstance, serviceLocator,
                configuration);
        serviceLocator.addConstant(serverContext.getClass().getSimpleName(), serverContext);

        TestCaseInstance testCaseInstance = new TestCaseInstance(methodName, testInstance);
        serviceLocator.addConstant(testCaseInstance.getTestName(), testCaseInstance);

        return serverContext;

    }).get();
}

From source file:com.evolveum.midpoint.web.component.form.ValueChoosePanel.java

protected ObjectQuery createChooseQuery() {
    ArrayList<String> oidList = new ArrayList<>();
    ObjectQuery query = new ObjectQuery();
    // TODO we should add to filter currently displayed value
    // not to be displayed on ObjectSelectionPanel instead of saved value

    if (oidList.isEmpty()) {
        ObjectFilter customFilter = createCustomFilter();
        if (customFilter != null) {
            query.addFilter(customFilter);
            return query;
        }/*from  ww  w.ja va2 s  . co m*/

        return null;

    }

    ObjectFilter oidFilter = InOidFilter.createInOid(oidList);
    query.setFilter(NotFilter.createNot(oidFilter));

    ObjectFilter customFilter = createCustomFilter();
    if (customFilter != null) {
        query.addFilter(customFilter);
    }

    return query;
}

From source file:findmyquote.FindMyQuoteSpeechlet.java

/**
 * Prepares the speech to reply to the user. Obtain movie from QuoDB for the quote/phrase specified
 * by the user and return those events in both
 * speech and SimpleCard format.//from w  w w  . j  av a 2s . c o  m
 * 
 * @param intent
 *            the intent object which contains the phrase slot
 * @param session
 *            the session object
 * @return SpeechletResponse object with voice/card response to return to the user
 */
private SpeechletResponse handleFirstEventRequest(Intent intent, Session session) {
    String phrase = getPhrase(intent);
    if (!phrase.equals(null)) {

        String speechPrefixContent = "<p>For " + phrase + "</p> ";
        String cardPrefixContent = "For " + phrase + ", ";
        String cardTitle = "Movies for " + phrase;

        //replace spaces for path param request
        String apiReadyPhrase = phrase.replaceAll(" ", "%20");
        System.out.println("apiReadyPhrase: " + apiReadyPhrase);
        ArrayList<String> events = getJsonEventsFromQuoDB(apiReadyPhrase);
        String speechOutput = "";
        if (events.isEmpty()) {
            speechOutput = "QuoDB could not find a movie for your quote. Sorry. ";

            // Create the plain text output
            SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
            outputSpeech.setSsml("<speak>" + speechOutput + "</speak>");

            return SpeechletResponse.newTellResponse(outputSpeech);
        } else {
            StringBuilder speechOutputBuilder = new StringBuilder();
            speechOutputBuilder.append(speechPrefixContent);
            StringBuilder cardOutputBuilder = new StringBuilder();
            cardOutputBuilder.append(cardPrefixContent);
            for (int i = 0; i < PAGINATION_SIZE; i++) {
                speechOutputBuilder.append("<p>");
                speechOutputBuilder.append(events.get(i));
                speechOutputBuilder.append("</p> ");
                cardOutputBuilder.append(events.get(i));
                cardOutputBuilder.append("\n");
            }
            speechOutputBuilder
                    .append(" There more movies with a similar quote, would you like to get another movie?");
            cardOutputBuilder
                    .append(" There more movies with a similar quote, would you like to get another movie?");
            speechOutput = speechOutputBuilder.toString();

            String repromptText = "With Find My Quote, you can get movie information for any quote you say."
                    + " For example, you could say 'No, I am your father'";

            // Create the Simple card content.
            SimpleCard card = new SimpleCard();
            card.setTitle(cardTitle);
            card.setContent(cardOutputBuilder.toString());

            // After reading the first 3 events, set the count to 3 and add the events
            // to the session attributes
            session.setAttribute(SESSION_INDEX, PAGINATION_SIZE);
            session.setAttribute(SESSION_TEXT, events);

            SpeechletResponse response = newAskResponse("<speak>" + speechOutput + "</speak>", true,
                    repromptText, false);
            response.setCard(card);
            return response;
        }
    } else {

        String speechOutput = "IM sorry, I was not able to understand your quote.";

        // Create the plain text output
        SsmlOutputSpeech outputSpeech = new SsmlOutputSpeech();
        outputSpeech.setSsml("<speak>" + speechOutput + "</speak>");
        return SpeechletResponse.newTellResponse(outputSpeech);
    }

}

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

@RequestMapping(value = "/get-history/{usr_id}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody//from   w  ww .  j a  v a  2  s.  c  o  m
public ResponseEntity<Map<String, Object>> getAuctionsHistoryByUser(
        @RequestParam(value = "page", required = false, defaultValue = "1") int page,
        @RequestParam(value = "limit", required = false, defaultValue = "10") int limit,
        @PathVariable("usr_id") int id) {
    Map<String, Object> map = new HashMap<String, Object>();
    try {
        Pagination pagination = new Pagination();
        pagination.setLimit(limit);
        pagination.setPage(page);
        pagination.setTotalCount(auc_service.countAuctionHistoryByUser(id));
        ArrayList<Auction_history> auction = auc_service.getAuctionHistoryByUser(pagination, id);
        if (!auction.isEmpty()) {
            map.put("DATA", auction);
            map.put("STATUS", true);
            map.put("MESSAGE", "DATA FOUND!");
            map.put("PAGINATION", pagination);
        } 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);
}

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

@RequestMapping(value = "/get-history-view-by-admin/{auc_id}", method = RequestMethod.GET, produces = "application/json")
@ResponseBody/*from   www  . j  av a 2 s  .com*/
public ResponseEntity<Map<String, Object>> getAuctionsHistoryByAdmin(
        @RequestParam(value = "page", required = false, defaultValue = "1") int page,
        @RequestParam(value = "limit", required = false, defaultValue = "10") int limit,
        @PathVariable("auc_id") int id) {
    Map<String, Object> map = new HashMap<String, Object>();
    try {
        Pagination pagination = new Pagination();
        pagination.setLimit(limit);
        pagination.setPage(page);
        pagination.setTotalCount(auc_service.countAuctionHistoryByAdmin(id));
        ArrayList<Auction_history> auction = auc_service.getAuctionHistoryByAdmin(pagination, id);
        if (!auction.isEmpty()) {
            map.put("DATA", auction);
            map.put("STATUS", true);
            map.put("MESSAGE", "DATA FOUND!");
            map.put("PAGINATION", pagination);
        } 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);
}

From source file:com.microsoft.campaignmanager.CampaignManagerPreferences.java

/**
 * Sets the string array pref.//from   ww w  . ja v a2s . c o  m
 *
 * @param key the key
 * @param values the values
 */
private void setStringArrayPref(String key, ArrayList<String> values) {
    SharedPreferences.Editor editor = mPreferences.edit();
    JSONArray a = new JSONArray();
    for (int i = 0; i < values.size(); i++) {
        a.put(values.get(i));
    }
    if (!values.isEmpty()) {
        editor.putString(key, a.toString());
    } else {
        editor.putString(key, null);
    }
    editor.commit();
}