Android Open Source - RealtimeStorage-Android Item Attribute






From Project

Back to project page RealtimeStorage-Android.

License

The source code is released under:

MIT License

If you think the Android project RealtimeStorage-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package co.realtime.storage;
//  w w  w . jav  a 2 s  .  co  m
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonValue;

/**
 * Class representing item's attribute. Can hold values of instance String and Number
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class ItemAttribute implements Comparable<ItemAttribute>{
  Boolean isString;
  Object value;

  public ItemAttribute(String str){
    isString = true;
    value = str;
  }

  public ItemAttribute(Number num){
    isString = false;
    value = num;
  }    

  /**
   * Returns the value of attribute
   * @return the value
   */
  @JsonValue
  @SuppressWarnings("unchecked")
  public <T> T get(){
    return (T) (this.isString ? (String)this.value : (Number)this.value);
  }

  /**
   * Checks if attribute is string type
   * @return true if is string type
   */
  @JsonIgnore
  public Boolean isString(){
    return this.isString;
  }
  
  /**
   * Checks if attribute is number type
   * @return true if is number type
   */
  @JsonIgnore
  public Boolean isNumber(){
    return !this.isString;
  }

  public String toString(){
    return (this.isString) ? (String)this.value : ((Number)this.value).toString();
  }

  //@SuppressWarnings({ "unchecked", "rawtypes" })
  @Override
  public int compareTo(ItemAttribute si) {
    if(this.isString)
      return ((String)this.value).compareTo(si.toString());
    if(si.isString())
      return this.value.toString().compareTo(si.toString());
    if (((Number)this.value).doubleValue() < ((Number)si.get()).doubleValue())
      return -1;        
    if (((Number)this.value).doubleValue() > ((Number)si.get()).doubleValue())
      return 1;        
    return 0;
    /*
    if(this.isString){
      return ((String)this.value).compareTo(si.toString());
    } else {
      if(si.isNumber()){
        if (((Number)this.value).doubleValue() < ((Number)si.get()).doubleValue())
          return -1;        
        if (((Number)this.value).doubleValue() > ((Number)si.get()).doubleValue())
          return 1;        
        return 0;
      } else { //Number vs String
        return this.value.toString().compareTo(si.toString());
      }
    }*/    
  }
  /*
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((value == null) ? 0 : value.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null){
      return false;
    }
    if (obj instanceof ItemAttribute){
      ItemAttribute other = (ItemAttribute) obj;
      if (value == null) {
        if (other.value != null) {
          return false;
        } else { 
          return true;
        }
      }
      if (this.compareTo(other)!=0) {
        return false;
      } else {
        return true;
      }
    }else{      
      return false;
    }
  }
   */
}




Java Source Code List

adapters.TodoCustomAdapter.java
co.realtime.sample.ApplicationTest.java
co.realtime.sample.MainActivity.java
co.realtime.storage.ApplicationTest.java
co.realtime.storage.EventCollection.java
co.realtime.storage.Event.java
co.realtime.storage.Filter.java
co.realtime.storage.ItemAttribute.java
co.realtime.storage.ItemRef.java
co.realtime.storage.ItemSnapshot.java
co.realtime.storage.LHMItemsComparator.java
co.realtime.storage.OnRestCompleted.java
co.realtime.storage.PostBodyBuilder.java
co.realtime.storage.ProcessRestResponse.java
co.realtime.storage.RestWebservice.java
co.realtime.storage.Rest.java
co.realtime.storage.StorageContext.java
co.realtime.storage.StorageRef.java
co.realtime.storage.TableRef.java
co.realtime.storage.TableSnapshot.java
co.realtime.storage.entities.Heartbeat.java
co.realtime.storage.entities.IORMapping.java
co.realtime.storage.entities.KeySchema.java
co.realtime.storage.entities.Key.java
co.realtime.storage.entities.TableMetadata.java
co.realtime.storage.entities.Throughput.java
co.realtime.storage.ext.OnBooleanResponse.java
co.realtime.storage.ext.OnError.java
co.realtime.storage.ext.OnHeartbeat.java
co.realtime.storage.ext.OnItemSnapshot.java
co.realtime.storage.ext.OnPresence.java
co.realtime.storage.ext.OnReconnected.java
co.realtime.storage.ext.OnReconnecting.java
co.realtime.storage.ext.OnTableCreation.java
co.realtime.storage.ext.OnTableMetadata.java
co.realtime.storage.ext.OnTableSnapshot.java
co.realtime.storage.ext.OnTableUpdate.java
co.realtime.storage.ext.StorageException.java
config.Config.java
handlers.StorageHandler.java
helpers.ListNameHelper.java
listeners.ClickListener.java
listeners.EditorListener.java
ui.MyViewPager.java