Created
September 28, 2016 08:03
-
-
Save NiKoTron/4c234bbc5d1c46fbabdb869d3743f0ce to your computer and use it in GitHub Desktop.
This file contains 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 ru.wowworks.wowworker.utils.type; | |
import com.squareup.moshi.FromJson; | |
import com.squareup.moshi.ToJson; | |
import io.realm.RealmList; | |
import io.realm.RealmObject; | |
public class RealmString extends RealmObject { | |
private String value; | |
public RealmString(){} | |
public RealmString(String value){ | |
this.value = value; | |
} | |
@Override | |
public boolean equals(Object o) { | |
if (this == o) return true; | |
if (!(o instanceof RealmString) && !(o instanceof String)) return false; | |
if(o instanceof RealmString) { | |
RealmString that = (RealmString) o; | |
return value != null ? value.equals(that.value) : that.value == null; | |
} | |
String that = (String) o; | |
return value != null && value.equals(that); | |
} | |
@Override | |
public int hashCode() { | |
return value != null ? value.hashCode() : 0; | |
} | |
@Override | |
public String toString() { | |
return value; | |
} | |
public String getValue() { | |
return value; | |
} | |
public void setValue(String value) { | |
this.value = value; | |
} | |
public static class MoshiAdapter { | |
@ToJson | |
public String toJson(RealmString string) { | |
return string.getValue(); | |
} | |
@FromJson | |
public RealmString fromJson(String string) { | |
return new RealmString(string); | |
} | |
@ToJson | |
public String[] toJsonArray(RealmList<RealmString> stringList) { | |
String[] array = new String[stringList.size()]; | |
for (int i = 0; i < array.length; i++) { | |
array[i] = stringList.get(i).getValue(); | |
} | |
return array; | |
} | |
@FromJson | |
public RealmList<RealmString> fromJsonArray(String[] stringArray) { | |
RealmList<RealmString> list = new RealmList<>(); | |
for (int i = 0; i < stringArray.length; i++) { | |
list.add(new RealmString(stringArray[i])); | |
} | |
return list; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment