com.evernote.edam.type.LazyMap Maven / Gradle / Ivy
The newest version!
/**
* Autogenerated by Thrift
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
*/
package com.evernote.edam.type;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import com.evernote.thrift.*;
import com.evernote.thrift.protocol.*;
/**
* A structure that wraps a map of name/value pairs whose values are not
* always present in the structure in order to reduce space when obtaining
* batches of entities that contain the map.
*
* When the server provides the client with a LazyMap, it will fill in either
* the keysOnly field or the fullMap field, but never both, based on the API
* and parameters.
*
* When a client provides a LazyMap to the server as part of an update to
* an object, the server will only update the LazyMap if the fullMap field is
* set. If the fullMap field is not set, the server will not make any changes
* to the map.
*
* Check the API documentation of the individual calls involving the LazyMap
* for full details including the constraints of the names and values of the
* map.
*
*
* - keysOnly
* - The set of keys for the map. This field is ignored by the
* server when set.
*
*
* - fullMap
* - The complete map, including all keys and values.
*
*
*/
public class LazyMap implements TBase, java.io.Serializable, Cloneable {
private static final TStruct STRUCT_DESC = new TStruct("LazyMap");
private static final TField KEYS_ONLY_FIELD_DESC = new TField("keysOnly", TType.SET, (short)1);
private static final TField FULL_MAP_FIELD_DESC = new TField("fullMap", TType.MAP, (short)2);
private Set keysOnly;
private Map fullMap;
// isset id assignments
public LazyMap() {
}
/**
* Performs a deep copy on other.
*/
public LazyMap(LazyMap other) {
if (other.isSetKeysOnly()) {
Set __this__keysOnly = new HashSet();
for (String other_element : other.keysOnly) {
__this__keysOnly.add(other_element);
}
this.keysOnly = __this__keysOnly;
}
if (other.isSetFullMap()) {
Map __this__fullMap = new HashMap();
for (Map.Entry other_element : other.fullMap.entrySet()) {
String other_element_key = other_element.getKey();
String other_element_value = other_element.getValue();
String __this__fullMap_copy_key = other_element_key;
String __this__fullMap_copy_value = other_element_value;
__this__fullMap.put(__this__fullMap_copy_key, __this__fullMap_copy_value);
}
this.fullMap = __this__fullMap;
}
}
public LazyMap deepCopy() {
return new LazyMap(this);
}
public void clear() {
this.keysOnly = null;
this.fullMap = null;
}
public int getKeysOnlySize() {
return (this.keysOnly == null) ? 0 : this.keysOnly.size();
}
public java.util.Iterator getKeysOnlyIterator() {
return (this.keysOnly == null) ? null : this.keysOnly.iterator();
}
public void addToKeysOnly(String elem) {
if (this.keysOnly == null) {
this.keysOnly = new HashSet();
}
this.keysOnly.add(elem);
}
public Set getKeysOnly() {
return this.keysOnly;
}
public void setKeysOnly(Set keysOnly) {
this.keysOnly = keysOnly;
}
public void unsetKeysOnly() {
this.keysOnly = null;
}
/** Returns true if field keysOnly is set (has been asigned a value) and false otherwise */
public boolean isSetKeysOnly() {
return this.keysOnly != null;
}
public void setKeysOnlyIsSet(boolean value) {
if (!value) {
this.keysOnly = null;
}
}
public int getFullMapSize() {
return (this.fullMap == null) ? 0 : this.fullMap.size();
}
public void putToFullMap(String key, String val) {
if (this.fullMap == null) {
this.fullMap = new HashMap();
}
this.fullMap.put(key, val);
}
public Map getFullMap() {
return this.fullMap;
}
public void setFullMap(Map fullMap) {
this.fullMap = fullMap;
}
public void unsetFullMap() {
this.fullMap = null;
}
/** Returns true if field fullMap is set (has been asigned a value) and false otherwise */
public boolean isSetFullMap() {
return this.fullMap != null;
}
public void setFullMapIsSet(boolean value) {
if (!value) {
this.fullMap = null;
}
}
@Override
public boolean equals(Object that) {
if (that == null)
return false;
if (that instanceof LazyMap)
return this.equals((LazyMap)that);
return false;
}
public boolean equals(LazyMap that) {
if (that == null)
return false;
boolean this_present_keysOnly = true && this.isSetKeysOnly();
boolean that_present_keysOnly = true && that.isSetKeysOnly();
if (this_present_keysOnly || that_present_keysOnly) {
if (!(this_present_keysOnly && that_present_keysOnly))
return false;
if (!this.keysOnly.equals(that.keysOnly))
return false;
}
boolean this_present_fullMap = true && this.isSetFullMap();
boolean that_present_fullMap = true && that.isSetFullMap();
if (this_present_fullMap || that_present_fullMap) {
if (!(this_present_fullMap && that_present_fullMap))
return false;
if (!this.fullMap.equals(that.fullMap))
return false;
}
return true;
}
@Override
public int hashCode() {
return 0;
}
public int compareTo(LazyMap other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
int lastComparison = 0;
LazyMap typedOther = (LazyMap)other;
lastComparison = Boolean.valueOf(isSetKeysOnly()).compareTo(typedOther.isSetKeysOnly());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetKeysOnly()) { lastComparison = TBaseHelper.compareTo(this.keysOnly, typedOther.keysOnly);
if (lastComparison != 0) {
return lastComparison;
}
}
lastComparison = Boolean.valueOf(isSetFullMap()).compareTo(typedOther.isSetFullMap());
if (lastComparison != 0) {
return lastComparison;
}
if (isSetFullMap()) { lastComparison = TBaseHelper.compareTo(this.fullMap, typedOther.fullMap);
if (lastComparison != 0) {
return lastComparison;
}
}
return 0;
}
public void read(TProtocol iprot) throws TException {
TField field;
iprot.readStructBegin();
while (true)
{
field = iprot.readFieldBegin();
if (field.type == TType.STOP) {
break;
}
switch (field.id) {
case 1: // KEYS_ONLY
if (field.type == TType.SET) {
{
TSet _set8 = iprot.readSetBegin();
this.keysOnly = new HashSet(2*_set8.size);
for (int _i9 = 0; _i9 < _set8.size; ++_i9)
{
String _elem10;
_elem10 = iprot.readString();
this.keysOnly.add(_elem10);
}
iprot.readSetEnd();
}
} else {
TProtocolUtil.skip(iprot, field.type);
}
break;
case 2: // FULL_MAP
if (field.type == TType.MAP) {
{
TMap _map11 = iprot.readMapBegin();
this.fullMap = new HashMap(2*_map11.size);
for (int _i12 = 0; _i12 < _map11.size; ++_i12)
{
String _key13;
String _val14;
_key13 = iprot.readString();
_val14 = iprot.readString();
this.fullMap.put(_key13, _val14);
}
iprot.readMapEnd();
}
} else {
TProtocolUtil.skip(iprot, field.type);
}
break;
default:
TProtocolUtil.skip(iprot, field.type);
}
iprot.readFieldEnd();
}
iprot.readStructEnd();
validate();
}
public void write(TProtocol oprot) throws TException {
validate();
oprot.writeStructBegin(STRUCT_DESC);
if (this.keysOnly != null) {
if (isSetKeysOnly()) {
oprot.writeFieldBegin(KEYS_ONLY_FIELD_DESC);
{
oprot.writeSetBegin(new TSet(TType.STRING, this.keysOnly.size()));
for (String _iter15 : this.keysOnly)
{
oprot.writeString(_iter15);
}
oprot.writeSetEnd();
}
oprot.writeFieldEnd();
}
}
if (this.fullMap != null) {
if (isSetFullMap()) {
oprot.writeFieldBegin(FULL_MAP_FIELD_DESC);
{
oprot.writeMapBegin(new TMap(TType.STRING, TType.STRING, this.fullMap.size()));
for (Map.Entry _iter16 : this.fullMap.entrySet())
{
oprot.writeString(_iter16.getKey());
oprot.writeString(_iter16.getValue());
}
oprot.writeMapEnd();
}
oprot.writeFieldEnd();
}
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("LazyMap(");
boolean first = true;
if (isSetKeysOnly()) {
sb.append("keysOnly:");
if (this.keysOnly == null) {
sb.append("null");
} else {
sb.append(this.keysOnly);
}
first = false;
}
if (isSetFullMap()) {
if (!first) sb.append(", ");
sb.append("fullMap:");
if (this.fullMap == null) {
sb.append("null");
} else {
sb.append(this.fullMap);
}
first = false;
}
sb.append(")");
return sb.toString();
}
public void validate() throws TException {
// check for required fields
}
}