Network

public class Network implements Serializable, Postable

This class stores all the information related to a network. It is fully expanded, meaning that its instance fields like Network.nearLocation store expanded objects (i.e. Place, not the stripped-down forms for database storage.

Fields

fromLocation

public Place fromLocation

Where users of the network are from. Must be specified if the network is location-based.

id

public long id

ID of network. Must always be specified.

language

public Language language

What language the users of the network speak. Must be specified if the network is language- based.

nearLocation

public Place nearLocation

The current location of users in the network. Must always be specified.

Constructors

Network

public Network(Place nearLocation, Place fromLocation, long id)

Create a location-based network from the provided objects

Parameters:
  • nearLocation – Where the network’s users currently reside
  • fromLocation – Where the network’s users are all from
  • id – ID of the network

Network

public Network(Place nearLocation, Language lang, long id)

Create a language-based network from the provided objects

Parameters:
  • nearLocation – Where the network’s users currently reside
  • lang – What language the network’s users all speak
  • id – ID of the network

Methods

getDatabaseNetwork

public DatabaseNetwork getDatabaseNetwork()

Get a DatabaseNetwork with the IDs stored by the Network from which the method is called.

Returns:The DatabaseNetwork associated with this Network

getPostJson

public JSONObject getPostJson()

Generate a JSON representation of the object suitable for use in POST requests. Wrapper for Network.toJSON().

Throws:
  • JSONException – May be thrown if something that should be a value in the JSON is not a valid value in the JSON format.
Returns:

JSON that can be passed to the server in the body of a POST request

See also: Network.toJSON();

isLanguageBased

public boolean isLanguageBased()

Check whether this network is of people who speak the same language

Returns:true if the network is defined in terms of language, false otherwise

isLocationBased

public boolean isLocationBased()

Check whether this network is of people who come from the same place

Returns:true if the network is defined by where members are from, false otherwise

toJSON

public JSONObject toJSON()

Generate a JSON describing the object. The JSON will conform to the following format:

{
             "id_city_cur": 0,
             "city_cur": "string",
             "id_region_cur": 0,
             "region_cur": "string",
             "id_country_cur": 0,
             "country_cur": "string",
             "id_city_origin": 0,
             "city_origin": "string",
             "id_region_origin": 0,
             "region_origin": "string",
             "id_country_origin": 0,
             "country_origin": "string",
             "id_language_origin": 0,
             "language_origin": "string",
             "network_class": "string"
          }

where missing IDs are passed as Location.NOWHERE. This format is suitable for submission to the server using the /network/new POST endpoint.

Throws:
  • JSONException – Unclear when this would be thrown
Returns:

JSON representation of the object

toString

public String toString()

Represent the object as a string suitable for debugging, but not for display to user.

Returns:String representation of the form Class[var=value, var=value, var=value, ...]