added StringUtil class contain isEmpyt( String ) implementation. This method is not available on Froyo and having a convenience function is useful. Modified all places in the code currently using "".equals().
This commit is contained in:
parent
d59648316c
commit
12b3211def
@ -4,6 +4,7 @@ import net.sf.openrocket.preset.TypedKey;
|
|||||||
import net.sf.openrocket.preset.TypedPropertyMap;
|
import net.sf.openrocket.preset.TypedPropertyMap;
|
||||||
import net.sf.openrocket.unit.Unit;
|
import net.sf.openrocket.unit.Unit;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
|
|
||||||
public class DoubleUnitColumnParser extends BaseUnitColumnParser {
|
public class DoubleUnitColumnParser extends BaseUnitColumnParser {
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ public class DoubleUnitColumnParser extends BaseUnitColumnParser {
|
|||||||
@Override
|
@Override
|
||||||
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
||||||
try {
|
try {
|
||||||
if (columnData == null || "".equals(columnData) ) {
|
if (StringUtil.isEmpty(columnData)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double value = Double.valueOf(columnData);
|
double value = Double.valueOf(columnData);
|
||||||
|
@ -4,6 +4,7 @@ import net.sf.openrocket.database.Databases;
|
|||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
import net.sf.openrocket.preset.TypedKey;
|
import net.sf.openrocket.preset.TypedKey;
|
||||||
import net.sf.openrocket.preset.TypedPropertyMap;
|
import net.sf.openrocket.preset.TypedPropertyMap;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
|
|
||||||
public class LineMaterialColumnParser extends BaseColumnParser {
|
public class LineMaterialColumnParser extends BaseColumnParser {
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class LineMaterialColumnParser extends BaseColumnParser {
|
|||||||
@Override
|
@Override
|
||||||
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
||||||
|
|
||||||
if (columnData == null || "".equals(columnData.trim())) {
|
if (StringUtil.isEmpty(columnData)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package net.sf.openrocket.preset.loader;
|
|||||||
|
|
||||||
import net.sf.openrocket.preset.ComponentPreset;
|
import net.sf.openrocket.preset.ComponentPreset;
|
||||||
import net.sf.openrocket.preset.TypedPropertyMap;
|
import net.sf.openrocket.preset.TypedPropertyMap;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Special DoubleUnitColumnParser for Mass column. Here we assume that if a mass of 0 is
|
* Special DoubleUnitColumnParser for Mass column. Here we assume that if a mass of 0 is
|
||||||
@ -17,7 +18,7 @@ public class MassColumnParser extends DoubleUnitColumnParser {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
||||||
if ( columnData == null || "".equals(columnData.trim()) || "?".equals(columnData.trim())) {
|
if ( StringUtil.isEmpty(columnData) || "?".equals(columnData.trim())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
double d = Double.valueOf(columnData);
|
double d = Double.valueOf(columnData);
|
||||||
|
@ -5,6 +5,7 @@ import net.sf.openrocket.material.Material;
|
|||||||
import net.sf.openrocket.preset.ComponentPreset;
|
import net.sf.openrocket.preset.ComponentPreset;
|
||||||
import net.sf.openrocket.preset.TypedKey;
|
import net.sf.openrocket.preset.TypedKey;
|
||||||
import net.sf.openrocket.preset.TypedPropertyMap;
|
import net.sf.openrocket.preset.TypedPropertyMap;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
|
|
||||||
public class MaterialColumnParser extends BaseColumnParser {
|
public class MaterialColumnParser extends BaseColumnParser {
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ public class MaterialColumnParser extends BaseColumnParser {
|
|||||||
@Override
|
@Override
|
||||||
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
||||||
|
|
||||||
if (columnData == null || "".equals(columnData.trim())) {
|
if (StringUtil.isEmpty(columnData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import net.sf.openrocket.preset.TypedPropertyMap;
|
|||||||
import net.sf.openrocket.unit.Unit;
|
import net.sf.openrocket.unit.Unit;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
import net.sf.openrocket.util.ArrayList;
|
import net.sf.openrocket.util.ArrayList;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@ -125,7 +126,7 @@ public abstract class RocksimComponentFileLoader {
|
|||||||
if (data.length == 0) {
|
if (data.length == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (data.length == 1 && "".equals(data[0].trim())) {
|
if (data.length == 1 && StringUtil.isEmpty(data[0]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
parseData(data);
|
parseData(data);
|
||||||
|
@ -4,6 +4,7 @@ import net.sf.openrocket.database.Databases;
|
|||||||
import net.sf.openrocket.material.Material;
|
import net.sf.openrocket.material.Material;
|
||||||
import net.sf.openrocket.preset.TypedKey;
|
import net.sf.openrocket.preset.TypedKey;
|
||||||
import net.sf.openrocket.preset.TypedPropertyMap;
|
import net.sf.openrocket.preset.TypedPropertyMap;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
|
|
||||||
public class SurfaceMaterialColumnParser extends BaseColumnParser {
|
public class SurfaceMaterialColumnParser extends BaseColumnParser {
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class SurfaceMaterialColumnParser extends BaseColumnParser {
|
|||||||
@Override
|
@Override
|
||||||
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
protected void doParse(String columnData, String[] data, TypedPropertyMap props) {
|
||||||
|
|
||||||
if (columnData == null || "".equals(columnData.trim())) {
|
if (StringUtil.isEmpty(columnData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import net.sf.openrocket.l10n.Translator;
|
|||||||
import net.sf.openrocket.logging.LogHelper;
|
import net.sf.openrocket.logging.LogHelper;
|
||||||
import net.sf.openrocket.startup.Application;
|
import net.sf.openrocket.startup.Application;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class defining a storable simulation variable type. This class defined numerous ready
|
* A class defining a storable simulation variable type. This class defined numerous ready
|
||||||
@ -270,7 +271,7 @@ public class FlightDataType implements Comparable<FlightDataType> {
|
|||||||
// found it from symbol
|
// found it from symbol
|
||||||
|
|
||||||
// if name was not given (empty string), can use the one we found
|
// if name was not given (empty string), can use the one we found
|
||||||
if ( s == null || s.isEmpty()){
|
if ( s == null || StringUtil.isEmpty(s)){
|
||||||
s = type.getName();
|
s = type.getName();
|
||||||
}
|
}
|
||||||
if ( u == null ){
|
if ( u == null ){
|
||||||
|
@ -11,6 +11,7 @@ import net.sf.openrocket.startup.Application;
|
|||||||
import net.sf.openrocket.unit.FixedUnitGroup;
|
import net.sf.openrocket.unit.FixedUnitGroup;
|
||||||
import net.sf.openrocket.unit.UnitGroup;
|
import net.sf.openrocket.unit.UnitGroup;
|
||||||
import net.sf.openrocket.util.ArrayList;
|
import net.sf.openrocket.util.ArrayList;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
import de.congrace.exp4j.Calculable;
|
import de.congrace.exp4j.Calculable;
|
||||||
import de.congrace.exp4j.ExpressionBuilder;
|
import de.congrace.exp4j.ExpressionBuilder;
|
||||||
import de.congrace.exp4j.UnknownFunctionException;
|
import de.congrace.exp4j.UnknownFunctionException;
|
||||||
@ -220,7 +221,7 @@ public class CustomExpression implements Cloneable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkSymbol(){
|
public boolean checkSymbol(){
|
||||||
if ("".equals(symbol.trim()))
|
if (StringUtil.isEmpty(symbol)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// No bad characters
|
// No bad characters
|
||||||
@ -246,7 +247,7 @@ public class CustomExpression implements Cloneable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkName(){
|
public boolean checkName(){
|
||||||
if ("".equals(name.trim()))
|
if (StringUtil.isEmpty(name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// No characters that could mess things up saving etc
|
// No characters that could mess things up saving etc
|
||||||
@ -295,7 +296,7 @@ public class CustomExpression implements Cloneable{
|
|||||||
* building the expression.
|
* building the expression.
|
||||||
*/
|
*/
|
||||||
public boolean checkExpression(){
|
public boolean checkExpression(){
|
||||||
if ("".equals(expression.trim())){
|
if (StringUtil.isEmpty(expression)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import net.sf.openrocket.startup.Application;
|
|||||||
import net.sf.openrocket.util.ArrayUtils;
|
import net.sf.openrocket.util.ArrayUtils;
|
||||||
import net.sf.openrocket.util.LinearInterpolator;
|
import net.sf.openrocket.util.LinearInterpolator;
|
||||||
import net.sf.openrocket.util.MathUtil;
|
import net.sf.openrocket.util.MathUtil;
|
||||||
|
import net.sf.openrocket.util.StringUtil;
|
||||||
|
|
||||||
public class RangeExpression extends CustomExpression {
|
public class RangeExpression extends CustomExpression {
|
||||||
private static final LogHelper log = Application.getLogger();
|
private static final LogHelper log = Application.getLogger();
|
||||||
@ -27,10 +28,10 @@ public class RangeExpression extends CustomExpression {
|
|||||||
public RangeExpression(OpenRocketDocument doc, String startTime, String endTime, String variableType) {
|
public RangeExpression(OpenRocketDocument doc, String startTime, String endTime, String variableType) {
|
||||||
super(doc);
|
super(doc);
|
||||||
|
|
||||||
if ("".equals(startTime.trim())){
|
if (StringUtil.isEmpty(startTime)){
|
||||||
startTime = "0";
|
startTime = "0";
|
||||||
}
|
}
|
||||||
if ("".equals(endTime.trim())){
|
if (StringUtil.isEmpty(endTime)){
|
||||||
endTime = "t";
|
endTime = "t";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
core/src/net/sf/openrocket/util/StringUtil.java
Normal file
21
core/src/net/sf/openrocket/util/StringUtil.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package net.sf.openrocket.util;
|
||||||
|
|
||||||
|
public class StringUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the argument is null or empty.
|
||||||
|
*
|
||||||
|
* This is implemented without using String.isEmpty() because that method
|
||||||
|
* is not available in Froyo.
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean isEmpty( String s ) {
|
||||||
|
if ( s == null ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return "".equals(s.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user