Skip to content

Commit

Permalink
Merge pull request #982 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
converter code cleanup
  • Loading branch information
ashitsalesforce authored Feb 13, 2024
2 parents 08a038e + 04005d5 commit 626bf4a
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,8 @@ public final class BooleanConverter implements Converter {

public BooleanConverter() {

this.defaultValue = null;
this.useDefault = false;

}

public BooleanConverter(Object defaultValue) {

this.defaultValue = defaultValue;
this.useDefault = true;

}


// ----------------------------------------------------- Instance Variables


/**
* The default value specified to our Constructor, if any.
*/
private Object defaultValue = null;


/**
* Should we return the default value on conversion errors?
*/
private boolean useDefault = true;


// --------------------------------------------------------- Public Methods


Expand Down Expand Up @@ -112,17 +86,11 @@ public Object convert(Class type, Object value) {
stringValue.equalsIgnoreCase("off") ||
stringValue.equalsIgnoreCase("0")) {
return (Boolean.FALSE);
} else if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(stringValue);
}
} catch (ClassCastException e) {
if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(e);
}
throw new ConversionException(e);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,8 @@ public final class DoubleConverter implements Converter {
// ----------------------------------------------------------- Constructors

public DoubleConverter() {

this.defaultValue = null;
this.useDefault = false;

}

public DoubleConverter(Object defaultValue) {

this.defaultValue = defaultValue;
this.useDefault = true;

}

// ----------------------------------------------------- Instance Variables

/**
* The default value specified to our Constructor, if any.
*/
private Object defaultValue = null;

/**
* Should we return the default value on conversion errors?
*/
private boolean useDefault = true;

// --------------------------------------------------------- Public Methods

/**
Expand All @@ -90,11 +67,7 @@ public Object convert(Class type, Object value) {
try {
return (Double.valueOf(value.toString()));
} catch (Exception e) {
if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(e);
}
throw new ConversionException(e);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,9 @@ public final class FileByteArrayConverter implements Converter {
// ----------------------------------------------------------- Constructors

public FileByteArrayConverter() {

this.defaultValue = null;
this.useDefault = false;
logger = LogManager.getLogger(this.getClass().getName());
}

public FileByteArrayConverter(Object defaultValue) {

this.defaultValue = defaultValue;
this.useDefault = true;

}

// ----------------------------------------------------- Instance Variables

/**
* The default value specified to our Constructor, if any.
*/
private Object defaultValue = null;

/**
* Should we return the default value on conversion errors?
*/
private boolean useDefault = true;

// --------------------------------------------------------- Public Methods

/**
Expand Down Expand Up @@ -133,11 +111,7 @@ public Object convert(Class type, Object value) {
logger.error(Messages.getMessage(this.getClass(), "insufficientAccessToContentGenericMsg", absolutePath));
}
}
if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(e);
}
throw new ConversionException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,8 @@
public final class IntegerConverter implements Converter {

public IntegerConverter() {

this.defaultValue = null;
this.useDefault = false;

}

public IntegerConverter(Object defaultValue) {

this.defaultValue = defaultValue;
this.useDefault = true;

}

// ----------------------------------------------------- Instance Variables

/**
* The default value specified to our Constructor, if any.
*/
private Object defaultValue = null;

/**
* Should we return the default value on conversion errors?
*/
private boolean useDefault = true;

// --------------------------------------------------------- Public Methods

/**
Expand Down Expand Up @@ -92,11 +69,7 @@ public Object convert(Class type, Object value) {
try {
return (Integer.parseInt(value.toString()));
} catch (Exception e) {
if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(e);
}
throw new ConversionException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,8 @@ public class SObjectReferenceConverter implements Converter {
// ----------------------------------------------------------- Constructors

public SObjectReferenceConverter() {

this.defaultValue = null;
this.useDefault = false;

}

public SObjectReferenceConverter(Object defaultValue) {

this.defaultValue = defaultValue;
this.useDefault = true;

}


// ----------------------------------------------------- Instance Variables


/**
* The default value specified to our Constructor, if any.
*/
private Object defaultValue = null;


/**
* Should we return the default value on conversion errors?
*/
private boolean useDefault = true;


// --------------------------------------------------------- Public Methods


Expand All @@ -90,11 +63,7 @@ public Object convert(Class type, Object value) {
SObjectReference sObjectRefValue = new SObjectReference(refValue);
return sObjectRefValue;
} catch (ClassCastException e) {
if (useDefault) {
return defaultValue;
} else {
throw new ConversionException(e);
}
throw new ConversionException(e);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ synchronized static public void registerConverters(Config cfg) {
ConvertUtils.register(new DateTimeConverter(tz, useEuroDates), Calendar.class);
ConvertUtils.register(new DateOnlyConverter(tz, useEuroDates), DateOnlyCalendar.class);
ConvertUtils.register(new DoubleConverter(), Double.class);
ConvertUtils.register(new IntegerConverter(null), Integer.class);
ConvertUtils.register(new IntegerConverter(), Integer.class);
ConvertUtils.register(new BooleanConverter(), Boolean.class);
ConvertUtils.register(new StringConverter(), String.class);
ConvertUtils.register(new FileByteArrayConverter(), byte[].class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,8 @@ public final class StringConverter implements Converter {
// ----------------------------------------------------------- Constructors

public StringConverter() {

this.defaultValue = null;
this.useDefault = false;

}

public StringConverter(Object defaultValue) {

this.defaultValue = defaultValue;
this.useDefault = true;

}


// ----------------------------------------------------- Instance Variables


/**
* The default value specified to our Constructor, if any.
*/
private Object defaultValue = null;


/**
* Should we return the default value on conversion errors?
*/
private boolean useDefault = true;


// --------------------------------------------------------- Public Methods


Expand Down Expand Up @@ -119,11 +92,7 @@ public Object convert(Class type, Object value) {
try {
return cleanseString(value.toString());
} catch (ClassCastException e) {
if (useDefault) {
return (defaultValue);
} else {
throw new ConversionException(e);
}
throw new ConversionException(e);
}

}
Expand Down

0 comments on commit 626bf4a

Please sign in to comment.