Created
November 19, 2016 16:12
-
-
Save CalebWhiting/2f77234fdf51c9b46fda3e09226ab45c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.unicus.api.wrapper; | |
import com.unicus.reflect.FieldReference; | |
import com.unicus.reflect.MethodReference; | |
import com.unicus.reflect.ReflectContext; | |
/** | |
* @author Caleb Whiting | |
*/ | |
public abstract class Wrapper { | |
private final Object reference; | |
public Wrapper(Object reference) { | |
this.reference = reference; | |
} | |
public Object getReference() { | |
return reference; | |
} | |
@Override | |
public boolean equals(Object obj) { | |
if (obj instanceof Wrapper) { | |
return ((Wrapper) obj).getReference().equals(getReference()); | |
} | |
return super.equals(obj) || obj.equals(getReference()); | |
} | |
@Override | |
public int hashCode() { | |
return getReference().hashCode(); | |
} | |
/* Ease of access methods */ | |
protected ReflectContext getContext() { | |
return ReflectContext.get(); | |
} | |
protected FieldReference getFieldReference(String key) { | |
return getContext().getFieldReference(key); | |
} | |
protected MethodReference getMethodReference(String key) { | |
return getContext().getMethodReference(key); | |
} | |
protected Object getFieldValue(String key) { | |
return getFieldReference(key).getValue(getReference()); | |
} | |
protected int getFieldInt(String key) { | |
return getFieldReference(key).getInt(getReference()); | |
} | |
protected double getFieldDouble(String key) { | |
return getFieldReference(key).getDouble(getReference()); | |
} | |
protected long getFieldLong(String key) { | |
return getFieldReference(key).getLong(getReference()); | |
} | |
protected byte getFieldByte(String key) { | |
return getFieldReference(key).getByte(getReference()); | |
} | |
protected float getFieldFloat(String key) { | |
return getFieldReference(key).getFloat(getReference()); | |
} | |
protected short getFieldShort(String key) { | |
return getFieldReference(key).getShort(getReference()); | |
} | |
protected String getFieldString(String key) { | |
return getFieldReference(key).getString(getReference()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment