List of usage examples for org.apache.commons.lang ArrayUtils EMPTY_STRING_ARRAY
String[] EMPTY_STRING_ARRAY
To view the source code for org.apache.commons.lang ArrayUtils EMPTY_STRING_ARRAY.
Click Source Link
String
array. From source file:org.soaplab.services.cmdline.IOParameter.java
/************************************************************************** * **************************************************************************/ protected synchronized List<String> build(Map<String, Object> inputs, Job job, String tagPrefix) throws ParameterException { // clean-up/*from w w w . j a va2 s .c o m*/ // (TBD: this is bad, it makes this class not thread-safe...) ioData = new ArrayList<IOData>(); // get values String[] values = null; boolean isDirect = isValueDirect(inputs); Object value = adaptInput(getRealValue(inputs, isDirect), job); if (value == null) { String defaultValue = paramDef.dflt; isDirect = paramDef.is(SoaplabConstants.DEFAULT_FOR_DIRECT); // ignore default value for outputs (unless it is a name // of a standard stream) if (((IOParamDef) paramDef).isRegularOutput()) defaultValue = ""; // ignore default value for standard streams (because // it contains just a name of such stream) if (StringUtils.isNotEmpty(defaultValue) && !((IOParamDef) paramDef).isStandardStream()) { values = new String[] { addToIOData(isDirect, defaultValue, job, "") }; } else { if (((IOParamDef) paramDef).isRegularInput()) { // here we have to check mandatorness if (paramDef.is(ParamDef.MANDATORY)) { throw new ParameterException(paramDef.id, "Input is mandatory and cannot remain empty."); } values = ArrayUtils.EMPTY_STRING_ARRAY; } else { // except for regular INPUT, we need to create an IOData String ref = null; if (((IOParamDef) paramDef).isStdin()) { // ...and empty file for STDIN ref = addToIOData(true, "", job, ""); } else { // ...and only a name of a file for outputs // STDOUT and STDERR ref = addToIOData(false, null, job, ""); } if (ref == null || ((IOParamDef) paramDef).isStandardStream()) { values = ArrayUtils.EMPTY_STRING_ARRAY; } else { values = new String[] { ref }; } } } } else if (value.getClass().isArray() && !(value instanceof byte[])) { Object[] vals = (Object[]) value; values = new String[vals.length]; for (int i = 0; i < vals.length; i++) { values[i] = addToIOData(isDirect, vals[i], job, String.format("%03d", i)); } } else { values = new String[] { addToIOData(isDirect, value, job, "") }; } // check values checkRepeatability(values.length); if (values.length == 0) return CmdLineJob.EMPTY_LIST; // no argument is needed for STDIN if (((IOParamDef) paramDef).isStdin()) return CmdLineJob.EMPTY_LIST; // build args from values if (StringUtils.isBlank(paramDef.get(ParamDef.METHOD))) { // no METHOD defined, so do it traditionally, with tags List<String> result = new ArrayList<String>(); String tag = paramDef.get(ParamDef.TAG); for (int i = 0; i < values.length; i++) result.addAll(taggedArg(tagPrefix, tag, values[i])); return result; } else { // use parameter template (METHOD) to create one or more // command-line arguments return createArgByMethod(new DefaultParameterAccessor(paramDef.id, paramDef.get(ParamDef.TAG), values)); } }
From source file:org.soaplab.services.cmdline.StdParameter.java
/************************************************************************** * Extract and return values for this parameter from 'inputs', or * from default. Return an empty array (not null) if there was no * value in 'inputs' and no default value is defined. * * The returned value can have more values if this parameter is * repetitive (more precisely: if the Object representing this * parameter in 'inputs' is an array). This method also checks if * the repetitivness is allowed for this parameter. * * Parameter 'job' (where this parameter belongs to) is not used * here.//w w w. ja va 2 s . co m **************************************************************************/ protected String[] getValues(Map<String, Object> inputs, Job job) throws ParameterException { String[] values = null; Object value = inputs.get(paramDef.id); if (value == null) { String defaultValue = getDefaultValue(); values = (defaultValue == null ? ArrayUtils.EMPTY_STRING_ARRAY : new String[] { defaultValue }); } else if (value.getClass().isArray()) { Object[] vals = (Object[]) value; values = new String[vals.length]; for (int i = 0; i < vals.length; i++) values[i] = vals[i].toString(); } else { values = new String[] { value.toString() }; } // check values checkRepeatability(values.length); return values; }
From source file:org.soaplab.services.cmdline.StdParameter.java
/************************************************************************** * **************************************************************************/ public String[] createArg(Map<String, Object> inputs, Job job) throws ParameterException { if (paramDef.is(ParamDef.ENVAR)) return ArrayUtils.EMPTY_STRING_ARRAY; List<String> built = build(inputs, job, CMD); return built.toArray(new String[] {}); }
From source file:org.soaplab.services.Config.java
/************************************************************************** * Almost the same functionality as {@link #getString getString} * method - see there details about parameters. The different is * the return value - it allows to return several values of the * same property. In the configuration file, the property can be * repeated, or can have several comma-separated values. <p> * * @return all values of the given property, or - if such property * does not exist - return a one-element array with the * 'defaultValue' unless the 'defaultValue' is also null in which * case return an empty array/*w ww.j a v a 2 s . c o m*/ **************************************************************************/ public static String[] getStrings(String key, String defaultValue, String serviceName, Object owner) { String[] values = null; if (serviceName != null) { values = get().getStringArray(serviceName + "." + key); if (values.length > 0) return values; } if (owner != null) { values = get().getStringArray( (owner instanceof Class ? ((Class) owner).getName() : owner.getClass().getName()) + "." + key); if (values.length > 0) return values; } values = get().getStringArray(key); if (values.length > 0) return values; if (defaultValue == null) return ArrayUtils.EMPTY_STRING_ARRAY; else return new String[] { defaultValue }; }
From source file:org.sonar.api.ce.measure.test.TestSettings.java
@Override public String[] getStringArray(String key) { String value = getString(key); if (value != null) { String[] strings = StringUtils.splitByWholeSeparator(value, ","); String[] result = new String[strings.length]; for (int index = 0; index < strings.length; index++) { result[index] = StringUtils.trim(strings[index]); }// w w w .j ava 2 s. c om return result; } return ArrayUtils.EMPTY_STRING_ARRAY; }
From source file:org.sonar.api.config.Settings.java
/** * Value is split by comma and trimmed. Never returns null. * <p/>//from w ww. jav a 2s.c om * Examples : * <ul> * <li>"one,two,three " -> ["one", "two", "three"]</li> * <li>" one, two, three " -> ["one", "two", "three"]</li> * <li>"one, , three" -> ["one", "", "three"]</li> * </ul> */ public final String[] getStringArray(String key) { PropertyDefinition property = getDefinitions().get(key); if ((null != property) && (property.isMultiValues())) { String value = getString(key); if (value == null) { return ArrayUtils.EMPTY_STRING_ARRAY; } List<String> values = Lists.newArrayList(); for (String v : Splitter.on(",").trimResults().split(value)) { values.add(v.replace("%2C", ",")); } return values.toArray(new String[values.size()]); } return getStringArrayBySeparator(key, ","); }
From source file:org.sonar.api.config.Settings.java
/** * Value is split by carriage returns./*from w w w . j a v a2 s. com*/ * * @return non-null array of lines. The line termination characters are excluded. * @since 3.2 */ public final String[] getStringLines(String key) { String value = getString(key); if (Strings.isNullOrEmpty(value)) { return ArrayUtils.EMPTY_STRING_ARRAY; } return value.split("\r?\n|\r", -1); }
From source file:org.sonar.api.config.Settings.java
/** * Value is splitted and trimmed./* ww w. java 2s. c om*/ */ public final String[] getStringArrayBySeparator(String key, String separator) { String value = getString(key); if (value != null) { String[] strings = StringUtils.splitByWholeSeparator(value, separator); String[] result = new String[strings.length]; for (int index = 0; index < strings.length; index++) { result[index] = StringUtils.trim(strings[index]); } return result; } return ArrayUtils.EMPTY_STRING_ARRAY; }
From source file:org.sonar.batch.scan.filesystem.ExclusionFilters.java
private String[] computeTestInclusions() { if (exclusionSettings.testInclusions().length > 0) { // User defined params return exclusionSettings.testInclusions(); }/*from w w w .j a va 2 s . c om*/ return ArrayUtils.EMPTY_STRING_ARRAY; }
From source file:org.sonar.graph.DsmScanner.java
private String[] splitLine(String line) { if (line == null) { return ArrayUtils.EMPTY_STRING_ARRAY; }//w w w . j a va2 s . c om String[] tokens = line.split("\\" + CELL_SEPARATOR); String[] result = new String[tokens.length]; for (int i = 0; i < tokens.length; i++) { result[i] = tokens[i].trim(); } return result; }