Example usage for org.apache.commons.lang ArrayUtils isEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isEmpty.

Prototype

public static boolean isEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is empty or null.

Usage

From source file:hudson.plugins.plot.CSVSeries.java

/**
 * Load the series from a properties file.
 *//*w  ww  .  j a v a2s . c  om*/
@Override
public List<PlotPoint> loadSeries(FilePath workspaceRootDir, int buildNumber, PrintStream logger) {
    CSVReader reader = null;
    InputStream in = null;
    InputStreamReader inputReader = null;

    try {
        List<PlotPoint> ret = new ArrayList<PlotPoint>();

        FilePath[] seriesFiles = null;
        try {
            seriesFiles = workspaceRootDir.list(getFile());
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Exception trying to retrieve series files", e);
            return null;
        }

        if (ArrayUtils.isEmpty(seriesFiles)) {
            LOGGER.info("No plot data file found: " + workspaceRootDir.getName() + " " + getFile());
            return null;
        }

        try {
            if (LOGGER.isLoggable(defaultLogLevel))
                LOGGER.log(defaultLogLevel, "Loading plot series data from: " + getFile());

            in = seriesFiles[0].read();
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Exception reading plot series data from " + seriesFiles[0], e);
            return null;
        }

        if (LOGGER.isLoggable(defaultLogLevel))
            LOGGER.log(defaultLogLevel, "Loaded CSV Plot file: " + getFile());

        // load existing plot file
        inputReader = new InputStreamReader(in);
        reader = new CSVReader(inputReader);
        String[] nextLine;

        // save the header line to use it for the plot labels.
        String[] headerLine = reader.readNext();

        // read each line of the CSV file and add to rawPlotData
        int lineNum = 0;
        while ((nextLine = reader.readNext()) != null) {
            // skip empty lines
            if (nextLine.length == 1 && nextLine[0].length() == 0)
                continue;

            for (int index = 0; index < nextLine.length; index++) {
                String yvalue;
                String label = null;

                if (index > nextLine.length)
                    continue;

                yvalue = nextLine[index];

                if (index < headerLine.length)
                    label = headerLine[index];

                if (label == null || label.length() <= 0) {
                    // if there isn't a label, use the index as the label
                    label = "" + index;
                }

                // LOGGER.finest("Loaded point: " + point);

                // create a new point with the yvalue from the csv file and
                // url from the URL_index in the properties file.
                if (!excludePoint(label, index)) {
                    PlotPoint point = new PlotPoint(yvalue, getUrl(url, label, index, buildNumber), label);
                    if (LOGGER.isLoggable(defaultLogLevel))
                        LOGGER.log(defaultLogLevel, "CSV Point: [" + index + ":" + lineNum + "]" + point);
                    ret.add(point);
                } else {
                    if (LOGGER.isLoggable(defaultLogLevel))
                        LOGGER.log(defaultLogLevel, "excluded CSV Column: " + index + " : " + label);
                }
            }
            lineNum++;
        }

        return ret;

    } catch (IOException ioe) {
        LOGGER.log(Level.SEVERE, "Exception loading series", ioe);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException ignore) {
                // ignore
            }
        }
        IOUtils.closeQuietly(inputReader);
        IOUtils.closeQuietly(in);
    }

    return null;
}

From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java

/**
 * Every node contains folder URI as user object. If you have a node,
 * you may get the URI just by asking for user object. To find the node
 * for the particular folder URI, you have to traverse the tree.
 *///from  w  w  w .  j ava2s.co m
public void reloadModel(String filter) {
    clear();

    ResourceDescriptor[] labelDescriptors = MindRaider.labelCustodian.getLabelDescriptors();

    if (!ArrayUtils.isEmpty(labelDescriptors)) {
        for (ResourceDescriptor folderDescriptor : labelDescriptors) {
            String folderUri = folderDescriptor.getUri();
            if (filter == null || (filter != null
                    && folderDescriptor.getLabel().toLowerCase().startsWith(filter.toLowerCase()))) {
                addNodeToTree(folderDescriptor.getLabel(), folderUri);
            }
        }

        // now expand 0 rows - 0 row is enough (sub nodes has no children)
        expandRow(0);
        setSelectionRow(0);

        ((LabelNodeUserObject) labelsRootNode.getUserObject()).setNotebooksWithLabels(getRowCount() - 1);
    }
    validate();
}

From source file:mitm.djigzo.web.services.security.ClearSavedRequestAuthenticationProcessingFilter.java

@Override
public Authentication attemptAuthentication(HttpServletRequest request) throws AuthenticationException {
    Authentication authentication = super.attemptAuthentication(request);

    HttpSession session = request.getSession(false);

    if (session != null) {
        SavedRequest savedRequest = (SavedRequest) session
                .getAttribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY);

        if (savedRequest != null) {
            String[] savedEmails = savedRequest.getParameterValues(usernameRequestParameter);

            if (!ArrayUtils.isEmpty(savedEmails)) {
                String email = EmailAddressUtils.canonicalize(obtainUsername(request));

                for (String savedEmail : savedEmails) {
                    savedEmail = EmailAddressUtils.canonicalize(savedEmail);

                    if (!StringUtils.equals(email, savedEmail)) {
                        session.removeAttribute(AbstractProcessingFilter.SPRING_SECURITY_SAVED_REQUEST_KEY);

                        break;
                    }/*from   ww w  . j a v a2 s  . c o  m*/
                }
            }
        }
    }

    return authentication;
}

From source file:com.etcc.csc.presentation.datatype.PaymentContext.java

public BigDecimal getAuthorizedInvoiceFeeAmount() {
    BigDecimal total = new BigDecimal(0.0);
    if (!ArrayUtils.isEmpty(invoices)) {
        for (int i = 0; i < invoices.length; i++) {
            if (invoices[i].isAuthorized()) {
                total = total.add(BigDecimalUtil.nullSafe(invoices[i].getFeeAmount()));
            }/*www .  j av a  2s .  com*/
        }
    }
    return total;
}

From source file:edu.jhuapl.openessence.web.util.ControllerUtils.java

/**
 * @param jdes         The data entry source
 * @param parameterMap map of parameters to parse
 * @return a map of string to value of the parse parameters (as a DbKeyValMap)
 *//*  www .  j a v  a 2s  .c o  m*/
public static DbKeyValMap parseKeyValueMap(final JdbcOeDataEntrySource jdes, final Map<String, ?> parameterMap)
        throws ErrorMessageException {
    final DbKeyValMap dbKeyValMap = new DbKeyValMap();
    // TODO: Can you get here without pks?
    for (final String primaryKey : jdes.getParentTableDetails().getPks()) {
        final Object parameters = parameterMap.get(primaryKey);

        final String parameter;
        if (parameters instanceof String[]) {
            // Parameter map from request
            if (!ArrayUtils.isEmpty((String[]) parameters) && ((String[]) parameters).length == 1) {
                // Behavior of get parameter, should only have one. (error thrown otherwise)
                parameter = ((String[]) parameters)[0];
            } else {
                throw new ErrorMessageException(
                        String.format("Expecting one value for primary key: %s", primaryKey));
            }
        } else {
            // Map from json
            parameter = (String) parameters;
        }

        if (parameter == null) {
            throw new ErrorMessageException(String.format("No request value for primary key: %s", primaryKey));
        }

        final Dimension dimension = jdes.getEditDimension(primaryKey);
        if (dimension == null) {
            throw new IllegalStateException(primaryKey + " is not an edit dimension");
        }

        dbKeyValMap.putAll(formatData(primaryKey, parameter, dimension.getSqlType(), true));
    }

    return dbKeyValMap;
}

From source file:io.cloudslang.engine.partitions.services.PartitionTemplateImpl.java

private void runCallbackOnRollingPartitions() {
    if (!ArrayUtils.isEmpty(callbacks)) {
        if (logger.isDebugEnabled())
            logger.debug("Run callbacks on roll partition group [" + groupName + "]");
        for (PartitionCallback callback : callbacks)
            try {
                callback.doCallback(previousTable(), activeTable());
            } catch (RuntimeException ex) {
                logger.error("Partition group [" + groupName + "]: callback ["
                        + callback.getClass().getSimpleName() + "] failed on rolling partitions", ex);
            }/*from w w  w  .  j  av a  2 s.  c o  m*/
    }
}

From source file:com.bstek.dorado.util.Assert.java

/**
 * ???message?<br>/*from  w w w  . j a  v a 2s .com*/
 * ??nulllength0
 * @param array 
 * @param message ??
 */
public static void notEmpty(Object[] array, String message) {
    if (array == null || ArrayUtils.isEmpty(array)) {
        throw new IllegalArgumentException(message);
    }
}

From source file:net.shopxx.controller.shop.GoodsController.java

@RequestMapping(value = "/history", method = RequestMethod.GET)
public @ResponseBody List<Map<String, Object>> history(Long[] goodsIds) {
    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
    if (ArrayUtils.isEmpty(goodsIds) || goodsIds.length > MAX_HISTORY_GOODS_COUNT) {
        return data;
    }/*from  www.j a va  2 s . c  om*/

    List<Goods> goodsList = goodsService.findList(goodsIds);
    for (Goods goods : goodsList) {
        Map<String, Object> item = new HashMap<String, Object>();
        item.put("name", goods.getName());
        item.put("price", goods.getPrice());
        item.put("thumbnail", goods.getThumbnail());
        item.put("url", goods.getUrl());
        data.add(item);
    }
    return data;
}

From source file:com.vmware.bdd.service.impl.ClusterLdapUserMgmtCfgService.java

public void configureUserMgmt(String clusterName, List<NodeEntity> nodeEntityList) {
    Map<String, String> userMgmtCfg = getUserMgmtCfg(clusterName);
    Map<String, Map<String, String>> serviceUserCfg = serviceUserConfigService
            .getServiceUserConfigs(clusterName);

    //only when user didn't config ldap group in command line and service user in spec file, will the userMgmtCfg be null
    //it means if userMgmt is null, no ldap user or group is configured
    if (userMgmtCfg == null) {
        LOGGER.info("no need to do usermgmt configuration.");
        return;/*from www.  j  a va 2s  .c  om*/
    }

    if (CollectionUtils.isEmpty(nodeEntityList)) {
        LOGGER.info("the target node list is empty, skip usermgmt configuration.");
        return;
    }

    String adminGroupName = userMgmtCfg.get(UserMgmtConstants.ADMIN_GROUP_NAME);

    Set<String> groupNameSet = new HashSet<>();

    String[] userMgmtGroups = clusterUserMgmtValidService.getGroupNames(userMgmtCfg);
    if (!ArrayUtils.isEmpty(userMgmtGroups)) {
        groupNameSet.addAll(Arrays.asList(userMgmtGroups));
    }

    Set<String> serviceUserGroupSet = serviceUserConfigService.getServiceUserGroups(serviceUserCfg);
    if (!CollectionUtils.isEmpty(serviceUserGroupSet)) {
        groupNameSet.addAll(serviceUserGroupSet);
    }

    String[] groupNames = new String[groupNameSet.size()];
    groupNameSet.toArray(groupNames);

    String sssdConfContent = sssdConfigurationGenerator.getConfigurationContent(
            userMgmtServerService.getByName(UserMgmtConstants.DEFAULT_USERMGMT_SERVER_NAME, false), groupNames);

    File taskDir = CommandUtil.createWorkDir(System.currentTimeMillis());

    File localSssdConfFile = new File(taskDir, "sssd.conf");

    try (FileWriter fileWriter = new FileWriter(localSssdConfFile);) {
        //write sssd.conf for all nodes
        fileWriter.write(sssdConfContent);

    } catch (IOException ioe) {
        throw new RuntimeException("failed to write sssd.conf for usermgmt configuration.", ioe);
    }

    try {
        // scp to one node's tmp folder
        // cp to /etc/sssd
        // sudo authconfig --enablesssd --enablesssdauth --enablemkhomedir --updateall
        nodeLdapUserMgmtConfService.configureLdap(nodeEntityList, localSssdConfFile.getAbsolutePath(),
                adminGroupName);
    } finally {
        try {
            localSssdConfFile.delete();
        } catch (Exception ex) {
            LOGGER.warn("the local sssd file can not be deleted! please delete it manually!: "
                    + localSssdConfFile.getAbsolutePath(), ex);
        }
    }

    String disableLocalUserFlag = userMgmtCfg.get(UserMgmtConstants.DISABLE_LOCAL_USER_FLAG);

    if (disableLocalUserFlag != null) {
        boolean disableLocalUser = Boolean.parseBoolean(disableLocalUserFlag);
        if (disableLocalUser) {
            nodeLdapUserMgmtConfService.disableLocalUsers(nodeEntityList);
        }
    }
}

From source file:de.hybris.platform.category.impl.DefaultCategoryService.java

private boolean shouldAddPathElement(final Class element, final Class... includeOnlyCategories) {
    boolean result = false;
    if (ArrayUtils.isEmpty(includeOnlyCategories)) {
        result = true;//from   w w  w .jav a 2  s.  c  o m
    } else {
        if (ArrayUtils.contains(includeOnlyCategories, element)) {
            result = true;
        }
    }
    return result;
}