Skip to content

Commit

Permalink
Improved: ‘ObjectType’ contains unneeded code
Browse files Browse the repository at this point in the history
(OFBIZ-10771)

The ObjectType class contains utilities that extends the Java reflection API by 
defining methods which accepts string representation of Java types and classes.
It appears that this class contains unneeded code which is either dead or is 
redundant with the services already defined in the reflection API

Removes the useless isOrSubOf, instanceOf and interfaceOf methods. 
Additionally it removes the getInstance method which is not used anywhere in 
the framework or in the plugins.

Also includes similar changes in 
AbstractConverter.java
Converters.java 
DateTimeConverters.java 
GenericEntity.java
IfInstanceOf.java

Thanks: Mathieu

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1851701 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
JacquesLeRoux committed Jan 20, 2019
1 parent 4e5ffc7 commit c4c5c8a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 258 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
*******************************************************************************/
package org.apache.ofbiz.base.conversion;

import org.apache.ofbiz.base.util.ObjectType;

/** Abstract Converter class. This class handles converter registration
* and it implements the <code>canConvert</code>, <code>getSourceClass</code>,
* and <code>getTargetClass</code> methods.
Expand All @@ -42,7 +40,7 @@ public T convert(Class<? extends T> targetClass, S obj) throws ConversionExcepti
}

public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && ObjectType.instanceOf(targetClass, this.getTargetClass());
return getSourceClass().isAssignableFrom(sourceClass) && getTargetClass().isAssignableFrom(targetClass);
}

public Class<? super S> getSourceClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import org.apache.ofbiz.base.lang.SourceMonitored;
import org.apache.ofbiz.base.util.Debug;
import org.apache.ofbiz.base.util.ObjectType;
import org.apache.ofbiz.base.util.UtilGenerics;

/** A <code>Converter</code> factory and repository. */
Expand Down Expand Up @@ -203,7 +202,7 @@ protected PassThruConverterCreator() {
}

public <S, T> Converter<S, T> createConverter(Class<S> sourceClass, Class<T> targetClass) {
if (ObjectType.instanceOf(sourceClass, targetClass)) {
if (targetClass.isAssignableFrom(sourceClass)) {
return new PassThruConverter<>(sourceClass, targetClass);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.Locale;
import java.util.TimeZone;

import org.apache.ofbiz.base.util.ObjectType;
import org.apache.ofbiz.base.util.TimeDuration;
import org.apache.ofbiz.base.util.UtilDateTime;
import org.apache.ofbiz.base.util.UtilValidate;
Expand All @@ -42,7 +41,7 @@ public CalendarToDate() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public Date convert(Calendar obj) throws ConversionException {
Expand Down Expand Up @@ -80,7 +79,7 @@ public CalendarToTimestamp() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public Timestamp convert(Calendar obj) throws ConversionException {
Expand Down Expand Up @@ -170,7 +169,7 @@ public DateToTimestamp() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Timestamp convert(java.util.Date obj) throws ConversionException {
Expand Down Expand Up @@ -279,7 +278,7 @@ public NumberToDate() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.util.Date convert(Number obj) throws ConversionException {
Expand All @@ -304,7 +303,7 @@ public NumberToSqlDate() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Date convert(Number obj) throws ConversionException {
Expand All @@ -323,7 +322,7 @@ public NumberToSqlTime() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Time convert(Number obj) throws ConversionException {
Expand All @@ -338,7 +337,7 @@ public NumberToTimestamp() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Timestamp convert(Number obj) throws ConversionException {
Expand Down Expand Up @@ -560,7 +559,7 @@ public StringToSqlDate() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Date convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
Expand Down Expand Up @@ -593,7 +592,7 @@ public StringToSqlTime() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Time convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
Expand Down Expand Up @@ -622,7 +621,7 @@ public StringToTimestamp() {

@Override
public boolean canConvert(Class<?> sourceClass, Class<?> targetClass) {
return ObjectType.instanceOf(sourceClass, this.getSourceClass()) && targetClass == this.getTargetClass();
return getSourceClass().isAssignableFrom(sourceClass) && targetClass == getTargetClass();
}

public java.sql.Timestamp convert(String obj, Locale locale, TimeZone timeZone, String formatString) throws ConversionException {
Expand Down

0 comments on commit c4c5c8a

Please sign in to comment.