Example usage for org.apache.commons.lang StringUtils EMPTY

List of usage examples for org.apache.commons.lang StringUtils EMPTY

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils EMPTY.

Prototype

String EMPTY

To view the source code for org.apache.commons.lang StringUtils EMPTY.

Click Source Link

Document

The empty String "".

Usage

From source file:com.chadekin.jadys.commons.expression.SqlExpressionHandler.java

/**
 * Add an argument to the expression to be included to the actual builder, after verifying it is a valid expression
 * @param arg/*from www  . j ava 2 s .  c o  m*/
 * @return
 */
public default T addArgument(Object arg) {
    SqlExpressionItem expressionItem = getSqlExpressionItem();
    if (expressionItem == null) {
        setSqlExpressionItem(new SqlExpressionItem());
    }

    if (LOGICAL_OPERATORS.contains(arg)) {
        getSqlExpressionItem().appendLogicalOperator((JadysSqlOperation) arg);
    } else if (arg instanceof JadysSqlOperation) {
        JadysSqlOperation operator = (JadysSqlOperation) arg;
        TreeSet logicalOperators = getSqlExpressionItem().getLogicalOperator();
        if (!logicalOperators.isEmpty() && logicalOperators.last() == JadysSqlOperation.NOT) {
            operator = operator.getOpposite();
            getSqlExpressionItem().getLogicalOperator().remove(JadysSqlOperation.NOT);
        }
        getSqlExpressionItem().setOperator(operator);
    } else if (getSqlExpressionItem().getParam() == null) {
        String parameter = arg == null ? StringUtils.EMPTY : arg.toString();
        getSqlExpressionItem().setParam(parameter);
    } else if (arg == null) {
        setSqlExpressionItem(null);
    } else if (getSqlExpressionItem().getValue() == null) {
        getSqlExpressionItem().setValue(arg);
    }

    if (getSqlExpressionItem() != null && getSqlExpressionItem().isReady()) {
        finalizeExpression();
        setSqlExpressionItem(null);
    }
    return (T) this;
}

From source file:com.fengduo.bee.commons.util.ObjectUtils.java

/**
 * string?trim?//from   w w w.j  ava  2s.co m
 * 
 * @param object
 * @throws Exception
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void trimStringField(Object object, Class<?> clazz) throws Exception {
    if (object instanceof Map<?, ?>) {
        Map<Object, Object> target = new HashMap<Object, Object>();
        for (Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
            Object key = entry.getKey();
            Object value = entry.getValue();

            if (key instanceof String) {
                key = StringUtils.trim((String) key);
            } else {
                trim(key);
            }

            if (value instanceof String) {
                value = StringUtils.trim((String) value);
                value = StringUtils.replace((String) value, "\"", StringUtils.EMPTY);
            } else {
                trim(value);
            }
            target.put(key, value);
        }
        ((Map<?, ?>) object).clear();
        ((Map) object).putAll((Map) target);
        return;
    }
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        if (field.getType() == String.class) {
            boolean isFoolback = false;
            if (field.isAccessible() == false) {
                isFoolback = true;
                field.setAccessible(true);
            }
            String value = (String) field.get(object);
            if (StringUtils.isNotEmpty(value)) {
                value = value.trim();
                field.set(object, value);
            }
            if (isFoolback) {
                field.setAccessible(false);
            }
        }
    }
}

From source file:info.halo9pan.word2vec.hadoop.mr.ReadWordsMapper.java

@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
    String line = value.toString();
    for (String pattern : skipPatterns) {
        if (line.contains(pattern)) {
            Counter counter = context.getCounter(WordsCounter.SkipWords.toString(), pattern);
            counter.increment(1);//w  ww  .j  a v  a 2 s .  c om
        }
        line = line.replaceAll(pattern, StringUtils.EMPTY);
    }
    StringTokenizer itr = new StringTokenizer(line);
    while (itr.hasMoreTokens()) {
        word.set(itr.nextToken());
        context.write(word, ONE);
        Counter counter = context.getCounter(WordsCounter.class.getName(), WordsCounter.InputWords.toString());
        counter.increment(1);
    }
}

From source file:ch.puzzle.itc.mobiliar.presentation.deploy.LogView.java

public String getApplicationServerName() {
    if (deployment != null && deployment.getResource() != null) {
        return deployment.getResource().getName() + " " + deployment.getRelease().getName();
    } else {/*from w ww.j av  a  2  s.c  o  m*/
        return StringUtils.EMPTY;
    }
}

From source file:com.amalto.core.save.context.Save.java

private static void saveUpdateReport(MutableDocument updateReportDocument, SaverSource saverSource,
        SaverSession session) {/*from w w w .j a v  a  2  s.c om*/
    MetadataRepository metadataRepository = saverSource
            .getMetadataRepository(UpdateReport.UPDATE_REPORT_DATA_MODEL);
    ComplexTypeMetadata updateReportType = metadataRepository.getComplexType(UpdateReport.UPDATE_REPORT_TYPE);
    if (updateReportType == null) {
        throw new IllegalStateException("Could not find UpdateReport type."); //$NON-NLS-1$
    }

    Collection<FieldMetadata> keyFields = updateReportType.getKeyFields();
    long updateReportTime = 0;
    for (FieldMetadata keyField : keyFields) {
        String keyFieldName = keyField.getName();
        Accessor keyAccessor = updateReportDocument.createAccessor(keyFieldName);
        if (!keyAccessor.exist()) {
            throw new RuntimeException(
                    "Unexpected state: update report does not have value for key '" + keyFieldName + "'."); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if ("TimeInMillis".equals(keyFieldName)) { //$NON-NLS-1$
            if (StringUtils.EMPTY.equals(keyAccessor.get())) { // No update report need to save.
                return;
            } else {
                updateReportTime = Long.parseLong(keyAccessor.get());
            }
        }
    }
    if (updateReportTime < 1) { // This is unexpected (would mean update report "TimeInMillis" is not present).
        throw new IllegalStateException("Missing update report time value."); //$NON-NLS-1$
    }
    // Call session's save to save all items in correct order (one transaction per data cluster for the XML db).
    session.save(UpdateReport.UPDATE_REPORT_DATA_MODEL, updateReportDocument);
}

From source file:main.java.framework.java.measurement.FileVisitor.java

@Override
@ParametersAreNonnullByDefault//from   w w  w.ja v a 2s.  c om
public void scanFile(JavaFileScannerContext context) {
    this.context = context;
    this.project = getProjectKey();
    this.packageName = StringUtils.EMPTY;
    this.imports = new ArrayList<>();
    CompilationUnitTree tree = context.getTree();
    scan(tree);
}

From source file:com.microsoft.alm.plugin.idea.common.ui.workitem.SelectWorkItemsModel.java

public String getServerName() {
    if (latestServerContext != null) {
        return latestServerContext.getServerUri().toString();
    }/*from w  w  w .j  a  va 2  s .  c om*/
    return StringUtils.EMPTY;
}

From source file:com.alibaba.doris.admin.service.impl.ValueParseUtil.java

/**
 * ?String ?://from  w ww  . jav a2  s .c  o m
 * 
 * <pre>
 * short, int, long, float : 0
 * char, byte: 0
 * String: null
 * Map, List: null
 * Integer, Long, Float : null
 * Date: null
 * array: null
 * </pre>
 * 
 * @param strValue
 * @param clazz
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T parseStringValue(String strValue, Class<T> clazz, boolean autoDefault) {

    if (DEF_NULL.equals(strValue)) {
        if (!clazz.isPrimitive()) {
            return null;
        }
        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    }

    if (DEF_EMPTY.equals(strValue)) {
        if (clazz.isArray()) {
            return (T) Array.newInstance(clazz.getComponentType(), 0);
        }

        if (Map.class.isAssignableFrom(clazz)) {
            return (T) Collections.EMPTY_MAP;
        }

        if (List.class.isAssignableFrom(clazz)) {
            return (T) new ArrayList<Object>();
        }

        if (Set.class.isAssignableFrom(clazz)) {
            return (T) new HashSet<Object>();
        }

        if (String.class.equals(clazz)) {
            return (T) StringUtils.EMPTY;
        }

        if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) {
            return (T) Character.valueOf(' ');
        }

        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    }

    if (StringUtils.isBlank(strValue)) {// ?
        if (autoDefault) {
            return (T) getInternalDefaultValue(clazz);
        } else {
            return null;
        }
    } else {

        if (String.class.equals(clazz)) {
            return (T) strValue;
        }

        if (Short.TYPE.equals(clazz) || Short.class.equals(clazz)) {
            return (T) Short.valueOf(strValue);
        }

        if (Integer.TYPE.equals(clazz) || Integer.class.equals(clazz)) {
            return (T) Integer.valueOf(strValue);
        }
        if (Long.TYPE.equals(clazz) || Long.class.equals(clazz)) {
            return (T) Long.valueOf(strValue);
        }
        if (Boolean.TYPE.equals(clazz) || Boolean.class.equals(clazz)) {
            return (T) Boolean.valueOf(strValue);
        }
        if (Float.TYPE.equals(clazz) || Float.class.equals(clazz)) {
            return (T) Float.valueOf(strValue);
        }
        if (Double.TYPE.equals(clazz) || Double.class.equals(clazz)) {
            return (T) Double.valueOf(strValue);
        }
        if (Byte.TYPE.equals(clazz) || Byte.class.equals(clazz)) {
            return (T) Byte.valueOf(strValue);
        }
        if (Character.TYPE.equals(clazz) || Character.class.equals(clazz)) {
            return (T) Character.valueOf(strValue.charAt(0));
        }

        if (clazz.isArray()) {
            final Class<?> componentType = clazz.getComponentType();
            // String[]
            if (String.class.equals(componentType)) {
                return (T) StringUtils.split(strValue, ',');
            }
            // ?char[]
            if (Character.TYPE.equals(componentType)) {
                return (T) strValue.toCharArray();
            }

            if (Character.class.equals(componentType)) {
                final char[] tmp = strValue.toCharArray();
                final Character[] result = new Character[tmp.length];
                for (int i = 0; i < result.length; i++) {
                    result[i] = tmp[i];
                }
                return (T) result;
            }

            if (Byte.TYPE.equals(componentType) || Byte.class.equals(componentType)) {
                return (T) (strValue == null ? null : strValue.getBytes());
            }
        }
    }

    return null;

}

From source file:jenkins.plugins.coverity.ScmOptionBlock.java

public String checkScmConfig() {
    // Checking the required fields for specific SCM systems

    String errorText = StringUtils.EMPTY;
    Boolean delim = true;/*from   w  ww .  j  av  a  2 s . c om*/
    if (this.scmSystem.equals("accurev") && this.accRevRepo == null) {
        errorText += "[SCM] Please specify AccuRev's source control repository under 'Advanced' \n";
        delim = false;
    }

    if (this.scmSystem.equals("perforce") && this.p4Port == null) {
        errorText += "[SCM] Please specify Perforce's port environment variable under 'Advanced'\n ";
        delim = false;
    }

    if (delim) {
        errorText = "Pass";
    }
    return errorText;
}

From source file:com.fengduo.bee.service.impl.file.FileServiceImpl.java

public File getFile(String path) {
    if (StringUtils.isEmpty(path)) {
        return null;
    }//from   www  . jav a  2 s  .  com
    if (StringUtils.contains(path, STATIC_TMP_IMG)) {
        path = StringUtils.replace(path, STATIC_TMP_IMG, StringUtils.EMPTY);
    }
    File file = new File(UPLOAD_TMP_PATH + path);
    if (file == null || !file.isFile()) {
        return null;
    }
    if (file.getParentFile() == null || !file.getParentFile().exists()) {
        return null;
    }
    return file;
}