Example usage for org.apache.commons.lang3 StringUtils isNoneEmpty

List of usage examples for org.apache.commons.lang3 StringUtils isNoneEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils isNoneEmpty.

Prototype

public static boolean isNoneEmpty(final CharSequence... css) 

Source Link

Document

Checks if none of the CharSequences are empty ("") or null.

 StringUtils.isNoneEmpty(null)             = false StringUtils.isNoneEmpty(null, "foo")      = false StringUtils.isNoneEmpty("", "bar")        = false StringUtils.isNoneEmpty("bob", "")        = false StringUtils.isNoneEmpty("  bob  ", null)  = false StringUtils.isNoneEmpty(" ", "bar")       = true StringUtils.isNoneEmpty("foo", "bar")     = true 

Usage

From source file:com.cisco.oss.foundation.http.netlifx.apache.ApacheNetflixHttpClient.java

private com.netflix.client.http.HttpRequest buildNetflixHttpRequest(HttpRequest httpRequest, Joiner joiner) {
    com.netflix.client.http.HttpRequest.Builder builder = com.netflix.client.http.HttpRequest.newBuilder();
    //        URI requestUri = buildUri(httpRequest, joiner);
    builder.entity(httpRequest.getEntity()).uri(httpRequest.getUri())
            .verb(httpMethodToVerb(httpRequest.getHttpMethod()));

    Map<String, Collection<String>> headers = httpRequest.getHeaders();
    for (Map.Entry<String, Collection<String>> stringCollectionEntry : headers.entrySet()) {
        String key = stringCollectionEntry.getKey();
        Collection<String> stringCollection = stringCollectionEntry.getValue();
        String value = joiner.join(stringCollection);
        builder.header(key, value);/* w ww  . ja v  a 2  s  . co  m*/
    }

    builder.header("FLOW_CONTEXT", FlowContextFactory.serializeNativeFlowContext());

    if (StringUtils.isNoneEmpty(httpRequest.getContentType())) {
        String contentType = httpRequest.getContentType();
        builder.header("Content-Type", contentType);
    }

    Map<String, Collection<String>> queryParams = httpRequest.getQueryParams();
    if (queryParams != null && !queryParams.isEmpty()) {

        for (Map.Entry<String, Collection<String>> stringCollectionEntry : queryParams.entrySet()) {
            String key = stringCollectionEntry.getKey();
            Collection<String> queryParamsValueList = stringCollectionEntry.getValue();
            //                if (request.isQueryParamsParseAsMultiValue()) {
            //                    for (String queryParamsValue : queryParamsValueList) {
            //                        uriBuilder.addParameter(key, queryParamsValue);
            //                        queryStringBuilder.append(key).append("=").append(queryParamsValue).append("&");
            //                    }
            //                }else{
            String value = joiner.join(queryParamsValueList);
            builder.queryParam(key, value);
            //                    queryStringBuilder.append(key).append("=").append(value).append("&");
            //                }
        }

    }

    return builder.build();
}

From source file:io.cloudslang.content.utils.NumberUtilities.java

/**
 * If the long integer string is null or empty, it returns the defaultLong otherwise it returns the long integer value (see toLong)
 *
 * @param longStr     the long integer to convert
 * @param defaultLong the default value if the longStr is null or the empty string
 * @return the long integer value of the string or the defaultLong if the long integer string is empty
 * @throws IllegalArgumentException if the passed long integer string is not a valid long integer
 *//*  w ww .  j  av  a 2s.co m*/
public static long toLong(@Nullable final String longStr, final long defaultLong) {
    return StringUtils.isNoneEmpty(longStr) ? toLong(longStr) : defaultLong;
}

From source file:net.granoeste.scaffold.app.ScaffoldAlertDialogFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    int iconId = getArguments().getInt(ICON_ID, 0);
    String title = getArguments().getString(TITLE);
    String message = getArguments().getString(MESSAGE);
    boolean hasPositive = getArguments().getBoolean(HAS_POSITIVE, false);
    boolean hasNeutral = getArguments().getBoolean(HAS_NEUTRAL, false);
    boolean hasNegative = getArguments().getBoolean(HAS_NEGATIVE, false);
    String positiveText = getArguments().getString(POSITIVE_TEXT);
    String neutralText = getArguments().getString(NEUTRAL_TEXT);
    String negativeText = getArguments().getString(NEGATIVE_TEXT);
    boolean cancelable = getArguments().getBoolean(CANCELABLE, true);
    boolean canceledOnTouchOutside = getArguments().getBoolean(CANCELED_ON_TOUCH_OUTSIDE, false);

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    if (iconId > 0) {
        builder.setIcon(iconId);//  w  w  w.  j ava 2s .  c o  m
    }
    if (StringUtils.isNoneEmpty(title)) {
        builder.setTitle(title);
    }
    if (StringUtils.isNoneEmpty(message)) {
        builder.setMessage(message);
    }
    if (hasPositive) {
        if (StringUtils.isEmpty(positiveText)) {
            positiveText = getResources().getString(R.string.yes);
        }
        builder.setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    if (hasNeutral) {
        if (StringUtils.isEmpty(neutralText)) {
            neutralText = getResources().getString(R.string.no);
        }
        builder.setNeutralButton(neutralText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    if (hasNegative) {
        if (StringUtils.isEmpty(negativeText)) {
            negativeText = getResources().getString(hasNeutral ? R.string.cancel : R.string.no);
        }
        builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    builder.setCancelable(cancelable);
    if (cancelable) {
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(final DialogInterface dialog) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogCancel(dialog, getTag());
                    }
                }
            }
        });
    }
    //        View customView = getCustomView();
    if (mCustomView != null) {
        builder.setView(mCustomView);
    }

    Dialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(canceledOnTouchOutside);

    return dialog;
}

From source file:com.github.wasiqb.coteafs.appium.service.AppiumServer.java

/**
 * @author wasiq.bhamla/*from   w  ww.  java 2  s . co m*/
 * @since Oct 27, 2017 3:15:05 PM
 * @param logLevel
 * @param level
 */
private void setArgument(final ServerArgument flag, final String value) {
    if (StringUtils.isNoneEmpty(value)) {
        this.builder = this.builder.withArgument(flag, value);
    }
}

From source file:com.devicehive.resource.impl.DeviceCommandResourceImpl.java

@Override
public void query(String guid, String startTs, String endTs, String command, String status, String sortField,
        String sortOrderSt, Integer take, Integer skip, @Suspended final AsyncResponse asyncResponse) {
    LOGGER.debug("Device command query requested for device {}", guid);

    final Date timestampSt = TimestampQueryParamParser.parse(startTs);
    final Date timestampEnd = TimestampQueryParamParser.parse(endTs);

    DeviceVO device = deviceService.getDeviceWithNetworkAndDeviceClass(guid);
    if (device == null) {
        ErrorResponse errorCode = new ErrorResponse(NOT_FOUND.getStatusCode(),
                String.format(Messages.DEVICE_NOT_FOUND, guid));
        Response response = ResponseFactory.response(NOT_FOUND, errorCode);
        asyncResponse.resume(response);/*  w w w .  j a v a  2 s .c  o m*/
    } else {
        List<String> searchCommands = StringUtils.isNoneEmpty(command) ? Collections.singletonList(command)
                : Collections.EMPTY_LIST;
        commandService.find(Collections.singletonList(guid), searchCommands, timestampSt, timestampEnd, status)
                .thenApply(commands -> {
                    final Comparator<DeviceCommand> comparator = CommandResponseFilterAndSort
                            .buildDeviceCommandComparator(sortField);
                    final Boolean reverse = sortOrderSt == null ? null : "desc".equalsIgnoreCase(sortOrderSt);

                    final List<DeviceCommand> sortedDeviceCommands = CommandResponseFilterAndSort
                            .orderAndLimit(new ArrayList<>(commands), comparator, reverse, skip, take);
                    return ResponseFactory.response(OK, sortedDeviceCommands, Policy.COMMAND_LISTED);
                }).thenAccept(asyncResponse::resume);
    }
}

From source file:io.cloudslang.content.utils.NumberUtilities.java

/**
 * If the double string is null or empty, it returns the defaultDouble otherwise it returns the duoble value (see toDouble)
 *
 * @param doubleStr     the double to convert
 * @param defaultDouble the default value if the doubleStr is null or the empty string
 * @return the double value of the string or the defaultDouble is the double string is empty
 * @throws IllegalArgumentException if the passed double string is not a valid double
 *//*  w  w w . j  a v a 2 s.com*/
public static double toDouble(@Nullable final String doubleStr, final double defaultDouble) {
    return StringUtils.isNoneEmpty(doubleStr) ? toDouble(doubleStr) : defaultDouble;
}

From source file:com.edp.service.product.BpmnJsonConverter.java

public ObjectNode convertToJson(BpmnModel model) {
    ObjectNode modelNode = objectMapper.createObjectNode();
    double maxX = 0.0;
    double maxY = 0.0;

    for (GraphicInfo flowInfo : model.getLocationMap().values()) {
        if ((flowInfo.getX() + flowInfo.getWidth()) > maxX) {
            maxX = flowInfo.getX() + flowInfo.getWidth();
        }//w  w  w  .  j av a  2  s  .co m

        if ((flowInfo.getY() + flowInfo.getHeight()) > maxY) {
            maxY = flowInfo.getY() + flowInfo.getHeight();
        }
    }

    maxX += 50;
    maxY += 50;

    if (maxX < 1485) {
        maxX = 1485;
    }

    if (maxY < 700) {
        maxY = 700;
    }

    modelNode.put("bounds", BpmnJsonConverterUtil.createBoundsNode(maxX, maxY, 0, 0));
    modelNode.put("resourceId", "canvas");

    ObjectNode stencilNode = objectMapper.createObjectNode();
    stencilNode.put("id", "BPMNDiagram");
    modelNode.put("stencil", stencilNode);

    ObjectNode stencilsetNode = objectMapper.createObjectNode();
    stencilsetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    stencilsetNode.put("url", "../editor/stencilsets/bpmn2.0/bpmn2.0.json");
    modelNode.put("stencilset", stencilsetNode);

    ArrayNode shapesArrayNode = objectMapper.createArrayNode();

    Process mainProcess = null;

    if (model.getPools().size() > 0) {
        mainProcess = model.getProcess(model.getPools().get(0).getId());
    } else {
        mainProcess = model.getMainProcess();
    }

    ObjectNode propertiesNode = objectMapper.createObjectNode();

    if (StringUtils.isNotEmpty(mainProcess.getId())) {
        propertiesNode.put(PROPERTY_PROCESS_ID, mainProcess.getId());
    }

    if (StringUtils.isNotEmpty(mainProcess.getName())) {
        propertiesNode.put(PROPERTY_NAME, mainProcess.getName());
    }

    if (StringUtils.isNotEmpty(mainProcess.getDocumentation())) {
        propertiesNode.put(PROPERTY_DOCUMENTATION, mainProcess.getDocumentation());
    }

    if (mainProcess.isExecutable() == false) {
        propertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, "No");
    }

    if (StringUtils.isNoneEmpty(model.getTargetNamespace())) {
        propertiesNode.put(PROPERTY_PROCESS_NAMESPACE, model.getTargetNamespace());
    }

    BpmnJsonConverterUtil.convertMessagesToJson(model.getMessages(), propertiesNode);

    BpmnJsonConverterUtil.convertListenersToJson(mainProcess.getExecutionListeners(), true, propertiesNode);
    BpmnJsonConverterUtil.convertEventListenersToJson(mainProcess.getEventListeners(), propertiesNode);
    BpmnJsonConverterUtil.convertSignalDefinitionsToJson(model, propertiesNode);
    BpmnJsonConverterUtil.convertMessagesToJson(model, propertiesNode);

    if (CollectionUtils.isNotEmpty(mainProcess.getDataObjects())) {
        BpmnJsonConverterUtil.convertDataPropertiesToJson(mainProcess.getDataObjects(), propertiesNode);
    }

    modelNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);

    boolean poolHasDI = false;

    if (model.getPools().size() > 0) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());

            if (graphicInfo != null) {
                poolHasDI = true;

                break;
            }
        }
    }

    if ((model.getPools().size() > 0) && poolHasDI) {
        for (Pool pool : model.getPools()) {
            GraphicInfo graphicInfo = model.getGraphicInfo(pool.getId());

            if (graphicInfo == null) {
                continue;
            }

            ObjectNode poolNode = BpmnJsonConverterUtil.createChildShape(pool.getId(), STENCIL_POOL,
                    graphicInfo.getX() + graphicInfo.getWidth(), graphicInfo.getY() + graphicInfo.getHeight(),
                    graphicInfo.getX(), graphicInfo.getY());
            shapesArrayNode.add(poolNode);

            ObjectNode poolPropertiesNode = objectMapper.createObjectNode();
            poolPropertiesNode.put(PROPERTY_OVERRIDE_ID, pool.getId());
            poolPropertiesNode.put(PROPERTY_PROCESS_ID, pool.getProcessRef());

            if (pool.isExecutable() == false) {
                poolPropertiesNode.put(PROPERTY_PROCESS_EXECUTABLE, PROPERTY_VALUE_NO);
            }

            if (StringUtils.isNotEmpty(pool.getName())) {
                poolPropertiesNode.put(PROPERTY_NAME, pool.getName());
            }

            poolNode.put(EDITOR_SHAPE_PROPERTIES, poolPropertiesNode);

            ArrayNode laneShapesArrayNode = objectMapper.createArrayNode();
            poolNode.put(EDITOR_CHILD_SHAPES, laneShapesArrayNode);

            ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
            poolNode.put("outgoing", outgoingArrayNode);

            Process process = model.getProcess(pool.getId());

            if (process != null) {
                Map<String, ArrayNode> laneMap = new HashMap<String, ArrayNode>();

                for (Lane lane : process.getLanes()) {
                    GraphicInfo laneGraphicInfo = model.getGraphicInfo(lane.getId());

                    if (laneGraphicInfo == null) {
                        continue;
                    }

                    ObjectNode laneNode = BpmnJsonConverterUtil.createChildShape(lane.getId(), STENCIL_LANE,
                            laneGraphicInfo.getX() + laneGraphicInfo.getWidth(),
                            laneGraphicInfo.getY() + laneGraphicInfo.getHeight(), laneGraphicInfo.getX(),
                            laneGraphicInfo.getY());
                    laneShapesArrayNode.add(laneNode);

                    ObjectNode lanePropertiesNode = objectMapper.createObjectNode();
                    lanePropertiesNode.put(PROPERTY_OVERRIDE_ID, lane.getId());

                    if (StringUtils.isNotEmpty(lane.getName())) {
                        lanePropertiesNode.put(PROPERTY_NAME, lane.getName());
                    }

                    laneNode.put(EDITOR_SHAPE_PROPERTIES, lanePropertiesNode);

                    ArrayNode elementShapesArrayNode = objectMapper.createArrayNode();
                    laneNode.put(EDITOR_CHILD_SHAPES, elementShapesArrayNode);
                    laneNode.put("outgoing", objectMapper.createArrayNode());

                    laneMap.put(lane.getId(), elementShapesArrayNode);
                }

                for (FlowElement flowElement : process.getFlowElements()) {
                    Lane laneForElement = null;
                    GraphicInfo laneGraphicInfo = null;

                    FlowElement lookForElement = null;

                    if (flowElement instanceof SequenceFlow) {
                        SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                        lookForElement = model.getFlowElement(sequenceFlow.getSourceRef());
                    } else {
                        lookForElement = flowElement;
                    }

                    for (Lane lane : process.getLanes()) {
                        if (lane.getFlowReferences().contains(lookForElement.getId())) {
                            laneGraphicInfo = model.getGraphicInfo(lane.getId());

                            if (laneGraphicInfo != null) {
                                laneForElement = lane;
                            }

                            break;
                        }
                    }

                    if (flowElement instanceof SequenceFlow || (laneForElement != null)) {
                        processFlowElement(flowElement, process, model, laneMap.get(laneForElement.getId()),
                                laneGraphicInfo.getX(), laneGraphicInfo.getY());
                    }
                }

                processArtifacts(process, model, shapesArrayNode, 0.0, 0.0);
            }

            for (MessageFlow messageFlow : model.getMessageFlows().values()) {
                if (messageFlow.getSourceRef().equals(pool.getId())) {
                    outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
                }
            }
        }

        processMessageFlows(model, shapesArrayNode);
    } else {
        processFlowElements(model.getMainProcess(), model, shapesArrayNode, 0.0, 0.0);
        processMessageFlows(model, shapesArrayNode);
    }

    modelNode.put(EDITOR_CHILD_SHAPES, shapesArrayNode);

    return modelNode;
}

From source file:com.devicehive.service.UserService.java

@Transactional(propagation = Propagation.REQUIRED)
public UserVO createUser(@NotNull UserVO user, String password) {
    if (user.getId() != null) {
        throw new IllegalParametersException(Messages.ID_NOT_ALLOWED);
    }/* w ww . ja  v a  2 s .c om*/
    final String userLogin = StringUtils.trim(user.getLogin());
    user.setLogin(userLogin);
    Optional<UserVO> existing = userDao.findByName(user.getLogin());
    if (existing.isPresent()) {
        throw new ActionNotAllowedException(Messages.DUPLICATE_LOGIN);
    }
    if (StringUtils.isNoneEmpty(password)) {
        String salt = passwordService.generateSalt();
        String hash = passwordService.hashPassword(password, salt);
        user.setPasswordSalt(salt);
        user.setPasswordHash(hash);
    }
    final String googleLogin = StringUtils.isNotBlank(user.getGoogleLogin()) ? user.getGoogleLogin() : null;
    final String facebookLogin = StringUtils.isNotBlank(user.getFacebookLogin()) ? user.getFacebookLogin()
            : null;
    final String githubLogin = StringUtils.isNotBlank(user.getGithubLogin()) ? user.getGithubLogin() : null;
    if (googleLogin != null || facebookLogin != null || githubLogin != null) {
        Optional<UserVO> userWithSameIdentity = userDao.findByIdentityName(userLogin, googleLogin,
                facebookLogin, githubLogin);
        if (userWithSameIdentity.isPresent()) {
            throw new ActionNotAllowedException(Messages.DUPLICATE_IDENTITY_LOGIN);
        }
        user.setGoogleLogin(googleLogin);
        user.setFacebookLogin(facebookLogin);
        user.setGithubLogin(githubLogin);
    }
    user.setLoginAttempts(Constants.INITIAL_LOGIN_ATTEMPTS);
    hiveValidator.validate(user);
    userDao.persist(user);
    return user;
}

From source file:cn.afterturn.easypoi.excel.export.base.ExportCommonService.java

/**
 * ??//from  w w w. ja v  a  2 s  . c  o m
 */
public void sortAllParams(List<ExcelExportEntity> excelParams) {
    // ?,group ?,??
    // groupName?,?
    Map<String, List<ExcelExportEntity>> groupMap = new HashMap<String, List<ExcelExportEntity>>();
    for (int i = excelParams.size() - 1; i > -1; i--) {
        // ??
        if (excelParams.get(i).getList() != null) {
            Collections.sort(excelParams.get(i).getList());
        } else if (StringUtils.isNoneEmpty(excelParams.get(i).getGroupName())) {
            if (!groupMap.containsKey(excelParams.get(i).getGroupName())) {
                groupMap.put(excelParams.get(i).getGroupName(), new ArrayList<ExcelExportEntity>());
            }
            groupMap.get(excelParams.get(i).getGroupName()).add(excelParams.get(i));
            excelParams.remove(i);
        }
    }
    Collections.sort(excelParams);
    if (groupMap.size() > 0) {
        // group ?
        for (Iterator it = groupMap.entrySet().iterator(); it.hasNext();) {
            Map.Entry<String, List<ExcelExportEntity>> entry = (Map.Entry) it.next();
            Collections.sort(entry.getValue());
            // ?excelParams
            boolean isInsert = false;
            String groupName = "START";
            for (int i = 0; i < excelParams.size(); i++) {
                // groupName ,
                if (excelParams.get(i).getOrderNum() > entry.getValue().get(0).getOrderNum()
                        && !groupName.equals(excelParams.get(i).getGroupName())) {
                    if (StringUtils.isNotEmpty(excelParams.get(i).getGroupName())) {
                        groupName = excelParams.get(i).getGroupName();
                    }
                    excelParams.addAll(i, entry.getValue());
                    isInsert = true;
                    break;
                } else if (!groupName.equals(excelParams.get(i).getGroupName())
                        && StringUtils.isNotEmpty(excelParams.get(i).getGroupName())) {
                    groupName = excelParams.get(i).getGroupName();
                }
            }
            //???
            if (!isInsert) {
                excelParams.addAll(entry.getValue());
            }
        }
    }
}

From source file:com.cisco.oss.foundation.http.netlifx.netty.NettyNetflixHttpClient.java

private HttpClientRequest<ByteBuf> buildNetflixHttpRequest(HttpRequest request, Joiner joiner) {
    HttpClientRequest<ByteBuf> httpRequest = null;
    HttpMethod httpMethod = HttpMethod.valueOf(request.getHttpMethod().name());

    URI uri = buildUri(request, joiner);

    httpRequest = HttpClientRequest.create(httpMethod, uri.toString());
    byte[] entity = request.getEntity();
    if (entity != null) {
        httpRequest.withContent(entity);
    }//from   w ww  . ja  va2s  .co  m

    Map<String, Collection<String>> headers = request.getHeaders();
    for (Map.Entry<String, Collection<String>> stringCollectionEntry : headers.entrySet()) {
        String key = stringCollectionEntry.getKey();
        Collection<String> stringCollection = stringCollectionEntry.getValue();
        String value = joiner.join(stringCollection);
        httpRequest.withHeader(key, value);
    }

    if (StringUtils.isNoneEmpty(request.getContentType())) {
        String contentType = request.getContentType();
        httpRequest.withHeader("Content-Type", contentType);
    }

    return httpRequest;
}