DatabaseNetwork

public class DatabaseNetwork

This class is solely for storing the bare, ID-only form of a network in the database. After being retrieved from the database or received from a network request, it should immediately be used to create a Network object, with the additional information that comes with. Storing only IDs in the database makes the DatabaseNetwork.nearLocation, DatabaseNetwork.fromLocation and DatabaseNetwork.languageId references pointers to database entries with more information. This reduces the risk of conflicting information and reduces the overhead of updating data in more than one spot in the database.

Fields

fromLocation

public FromLocation fromLocation

The location where the users of this network are from. It may be null to indicate that no location is specified only if DatabaseNetwork.isLanguageBased is false

id

public long id

The network’s ID. This is used as its unique identifier in the database.

isLanguageBased

public boolean isLanguageBased

Denotes whether this network’s from attribute is based on where an individual is from or on what language they speak. true: Based on what language they speak false: Based on what location they are from

languageId

public long languageId

The ID of the language the users of this network speak. It may be set to -1 to indicate no language being specified only if DatabaseNetwork.isLanguageBased is false

nearLocation

public NearLocation nearLocation

The location where the users of this network currently reside. It must not be null.

Constructors

DatabaseNetwork

public DatabaseNetwork()

Empty constructor for database use only. This should never be called by our code.

DatabaseNetwork

public DatabaseNetwork(NearLocation nearLocation, FromLocation fromLocation, long id)

Create a new DatabaseNetwork for a network of people who come from the same area

Parameters:
  • nearLocation – Where the network’s members currently reside
  • fromLocation – Where the network’s members are from
  • id – ID for this network

DatabaseNetwork

public DatabaseNetwork(NearLocation nearLocation, long langId, long id)

Create a new DatabaseNetwork for a network of people who speak the same language

Parameters:
  • nearLocation – Where the network’s members currently reside
  • langId – ID for the language the network’s members speak
  • id – ID for this network

DatabaseNetwork

public DatabaseNetwork(JSONObject json)

If the key location_cur is present (old JSON version): Initialize instance fields with the data in the provided JSON. The following keys are mandatory and used: location_cur, whose value is expected to be a JSON describing a NearLocation object and can be passed to NearLocation.NearLocation(JSONObject), and network_class, whose value is expected to be either 0, indicating a location-based network, or 1, indicating a language-based network. If the network is language-based, they key language_origin must exist with a value of a JSON object containing a key id whose value is the ID of a Language. If the network is location-based, the key location_origin must exist and have a value of a JSON object representing a FromLocation that can be passed to FromLocation.FromLocation(JSONObject). NOTE: This JSON format is deprecated and should not be used if possible. If the key location_cur is not present (new JSON version): Initialize instance fields with the data in the provided JSON. The following keys are mandatory and used: All keys required by NearLocation.NearLocation(JSONObject) and the key network_class, whose value is expected to be either _l, indicating a language-based network, or one of cc, rc, and co, indicating a location-based network. If the network is language-based, the key id_language_origin must exist with a value of the ID of a Language. If the network is location-based, all keys required by FromLocation.FromLocation(JSONObject) must be present.

Parameters:
  • json – JSON object describing the network in terms of IDs
Throws:
  • JSONException – May be thrown in response to improperly formatted JSON

Methods

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

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, ...]