Skip to content

Instantly share code, notes, and snippets.

@viniciusdacal
Forked from jamiechapman/ParseProxyObject.java
Last active October 26, 2015 05:14
Show Gist options
  • Save viniciusdacal/9412431 to your computer and use it in GitHub Desktop.
Save viniciusdacal/9412431 to your computer and use it in GitHub Desktop.
// By Jamie Chapman, @chappers57
// License: open, do as you wish, just don't blame me if stuff breaks ;-)
public class ParseProxyObject implements Serializable {
private static final long serialVersionUID = 1L;
private HashMap<String, Object> values = new HashMap<String, Object>();
private String ObjectId;
private Date CreatedAt;
private Date UpdatedAt;
public HashMap<String, Object> getValues() {
return values;
}
public void setValues(HashMap<String, Object> values) {
this.values = values;
}
public ParseProxyObject(ParseObject object) {
this.ObjectId = object.getObjectId();
this.CreatedAt = object.getCreatedAt();
this.UpdatedAt = object.getUpdatedAt();
// Loop the keys in the ParseObject
for(String key : object.keySet()) {
@SuppressWarnings("rawtypes")
Class classType = object.get(key).getClass();
if(classType == byte[].class || classType == String.class ||
classType == Integer.class || classType == Boolean.class) {
values.put(key, object.get(key));
} else if(classType == ParseUser.class) {
ParseProxyObject parseUserObject = new ParseProxyObject((ParseObject)object.get(key));
values.put(key, parseUserObject);
} else {
// You might want to add more conditions here, for embedded ParseObject, ParseFile, etc.
}
}
}
public String getString(String key) {
if(has(key)) {
return (String) values.get(key);
} else {
return "";
}
}
public int getInt(String key) {
if(has(key)) {
return (Integer)values.get(key);
} else {
return 0;
}
}
public Boolean getBoolean(String key) {
if(has(key)) {
return (Boolean)values.get(key);
} else {
return false;
}
}
public byte[] getBytes(String key) {
if(has(key)) {
return (byte[])values.get(key);
} else {
return new byte[0];
}
}
public ParseProxyObject getParseUser(String key) {
if(has(key)) {
return (ParseProxyObject) values.get(key);
} else {
return null;
}
}
public Boolean has(String key) {
return values.containsKey(key);
}
public String getObjectId() {
return ObjectId;
}
public Date getCreatedAt() {
return CreatedAt;
}
public Date getUpdatedAt() {
return UpdatedAt;
}
}
@rustanacexd
Copy link

Thanks for this! I'm trying it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment