com.sunlightlabs.entities
Class JSONEntity

java.lang.Object
  extended by com.sunlightlabs.entities.JSONEntity
Direct Known Subclasses:
Committee, District, Issue, Legislator, Lobbyist

public abstract class JSONEntity
extends java.lang.Object

com.sunlightlabs.entities.JSONEntity steve Jul 22, 2009


Field Summary
static JSONEntity[] EMPTY_ARRAY
           
static java.lang.Class<JSONEntity> THIS_CLASS
           
 
Constructor Summary
JSONEntity(JSONObject data)
           
JSONEntity(java.util.Map<java.lang.String,java.lang.Object> data)
           
 
Method Summary
 boolean equivalent(JSONEntity l2)
          true if l2 is of the same class and has he same properties useful in testing
 java.lang.String[] getAllKeys()
          return an array of all property names
static JSONObject[] getArrayItems(JSONArray items)
          turn a JSONArray of JSONObjects into the Objects
static java.lang.String[] getArrayStringItems(JSONArray items)
          turn a JSONArray of JSONObjects into the Objects
static JSONObject getContainedJSONObject(JSONObject container)
          JSONArray wrap their elements - this unwraps
abstract  java.lang.String getEntityName()
          JSON name of the item
static JSONObject getJSONObject(com.sunlightlabs.api.ApiCall call, java.util.Map<java.lang.String,java.lang.String> params, java.lang.String apiCall, java.lang.String arrayName)
           
static JSONObject[] getJSONObjects(com.sunlightlabs.api.ApiCall call, java.util.Map<java.lang.String,java.lang.String> params, java.lang.String apiCall, java.lang.String arrayName)
          call the web site and
static java.lang.String[] getJSONStrings(com.sunlightlabs.api.ApiCall call, java.util.Map<java.lang.String,java.lang.String> params, java.lang.String apiCall, java.lang.String arrayName)
           
abstract  java.lang.String[] getKnownProperties()
          unofficial list of properties
 NameValuePair[] getNameValuePairs()
          extract properties as NameValuePairs
static java.util.Map<java.lang.String,java.lang.Object> getProperties(JSONObject obj)
          extract the properties from a JSOM object
 java.lang.String getProperty(java.lang.String key)
          return a property
 void show()
          show object on system.out
 void show(java.lang.Appendable out)
          show object on out
 void showProperties()
          show all properties on System.out
 void showProperties(java.lang.Appendable out)
          write all name value pairs to the appender
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THIS_CLASS

public static java.lang.Class<JSONEntity> THIS_CLASS

EMPTY_ARRAY

public static JSONEntity[] EMPTY_ARRAY
Constructor Detail

JSONEntity

public JSONEntity(JSONObject data)

JSONEntity

public JSONEntity(java.util.Map<java.lang.String,java.lang.Object> data)
Method Detail

getProperties

public static java.util.Map<java.lang.String,java.lang.Object> getProperties(JSONObject obj)
extract the properties from a JSOM object

Parameters:
obj - non-null json object
Returns:
non-null map of properteis

getArrayItems

public static JSONObject[] getArrayItems(JSONArray items)
turn a JSONArray of JSONObjects into the Objects

Parameters:
items - non-null JSONArray
Returns:
non-null array of JSONObject

getArrayStringItems

public static java.lang.String[] getArrayStringItems(JSONArray items)
turn a JSONArray of JSONObjects into the Objects

Parameters:
items - non-null JSONArray
Returns:
non-null array of JSONObject

getContainedJSONObject

public static JSONObject getContainedJSONObject(JSONObject container)
JSONArray wrap their elements - this unwraps

Parameters:
container - wrapped element
Returns:
contained element

getJSONStrings

public static java.lang.String[] getJSONStrings(com.sunlightlabs.api.ApiCall call,
                                                java.util.Map<java.lang.String,java.lang.String> params,
                                                java.lang.String apiCall,
                                                java.lang.String arrayName)
Parameters:
call -
params -
apiCall -
arrayName -
Returns:

getJSONObjects

public static JSONObject[] getJSONObjects(com.sunlightlabs.api.ApiCall call,
                                          java.util.Map<java.lang.String,java.lang.String> params,
                                          java.lang.String apiCall,
                                          java.lang.String arrayName)
call the web site and

Parameters:
call -
params -
apiCall -
arrayName -
Returns:

getJSONObject

public static JSONObject getJSONObject(com.sunlightlabs.api.ApiCall call,
                                       java.util.Map<java.lang.String,java.lang.String> params,
                                       java.lang.String apiCall,
                                       java.lang.String arrayName)
Parameters:
call -
params -
apiCall -
arrayName -
Returns:

getProperty

public java.lang.String getProperty(java.lang.String key)
return a property

Parameters:
key - non-null key
Returns:
possibly null property

getAllKeys

public java.lang.String[] getAllKeys()
return an array of all property names

Returns:
non-null array

getNameValuePairs

public NameValuePair[] getNameValuePairs()
extract properties as NameValuePairs

Returns:
non-null array if NameValuePairs

showProperties

public void showProperties()
show all properties on System.out


showProperties

public void showProperties(java.lang.Appendable out)
write all name value pairs to the appender

Parameters:
out - non-null appender

show

public void show()
show object on system.out


show

public void show(java.lang.Appendable out)
show object on out

Parameters:
out - non-null appender

getEntityName

public abstract java.lang.String getEntityName()
JSON name of the item

Returns:
non-null String

getKnownProperties

public abstract java.lang.String[] getKnownProperties()
unofficial list of properties


equivalent

public boolean equivalent(JSONEntity l2)
true if l2 is of the same class and has he same properties useful in testing

Parameters:
l2 - non-null test object
Returns:
true if they are the same