Added some documentation to the Gate class.

This commit is contained in:
Tobias Ottenweller 2013-05-18 19:54:43 +02:00
parent f1d623df60
commit 00573c2763

View File

@ -30,11 +30,14 @@ public class Gate implements ConfigurationSerializable
protected boolean isOpen = false; protected boolean isOpen = false;
protected String id; protected String id;
/**
* You should never create two gates with the same 'id'. Also see 'setId(String id)'.
* @param id This parameter must not be 'null'. An exception will be thrown otherwise!
*/
public Gate(String id) public Gate(String id)
{ {
setId(id); setId(id);
} }
@ -46,14 +49,25 @@ public class Gate implements ConfigurationSerializable
/* /*
* SETTER & GETTER * SETTER & GETTER
*/ */
/**
*
* @return This method might return a 'null' value.
*/
public Location getLocation() public Location getLocation()
{ {
return location; return location;
} }
/**
*
* @param location Supplying 'null' is permitted.
* @throws Exception Will throw an exception if the gate is open and an invalid (no gate frame) location is
* supplied. Note that the supplied 'location' will be set even if an exception is thrown. Note that this
* gate will be closed if an exception is thrown.
*/
public void setLocation(Location location) throws Exception public void setLocation(Location location) throws Exception
{ {
this.location = location; this.location = location;
@ -63,27 +77,53 @@ public class Gate implements ConfigurationSerializable
validate(); validate();
} }
} }
/**
*
* @return This method might return a 'null' value.
*/
public Location getExit() public Location getExit()
{ {
return exit; return exit;
} }
/**
*
* @param exit Supplying 'null' is permitted.
* @throws Exception An exception will be thrown if 'null' value is supplied and this gate is open. Note that the
* supplied 'exit' will be set even if an exception is thrown. Note that this gate will be closed if an
* exception is thrown.
*/
public void setExit(Location exit) throws Exception public void setExit(Location exit) throws Exception
{ {
this.exit = exit; this.exit = exit;
validate(); validate();
} }
public String getId() { /**
*
* @return This method will never return 'null'.
*/
public String getId()
{
return id; return id;
} }
public void setId(String id) { /**
* Every gate should have an unique 'id'. You should therefore check if another gate with the same 'id' exists.
* Note that this method will not check if another gate with the same 'id' exists!
* @param id This parameter must not be 'null'. An exception will be thrown otherwise!
*/
public void setId(String id)
{
if (id == null) {
throw new IllegalArgumentException("gate 'id' cannot be 'null'");
}
this.id = id; this.id = id;
} }
@ -132,8 +172,11 @@ public class Gate implements ConfigurationSerializable
validate(); validate();
} }
/**
*
* @return Will never return 'null' but might return an empty Set.
*/
public Set<Location> getGateBlockLocations() public Set<Location> getGateBlockLocations()
{ {
return gateBlockLocations; return gateBlockLocations;
@ -189,7 +232,7 @@ public class Gate implements ConfigurationSerializable
*/ */
/** /**
* Checks if valus attributes do add up; will close gate on wrong values. * Checks if values attributes do add up; will close gate on wrong values.
*/ */
public void validate() throws Exception public void validate() throws Exception
{ {
@ -240,10 +283,15 @@ public class Gate implements ConfigurationSerializable
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private Gate(Map<String, Object> map) public Gate(Map<String, Object> map)
{ {
try { try {
id = map.get(idKey).toString(); id = map.get(idKey).toString();
if (id == null) {
throw new Exception("gates need to have an id");
}
isHidden = (Boolean)map.get(isHiddenKey); isHidden = (Boolean)map.get(isHiddenKey);
isOpen = (Boolean)map.get(isOpenKey); isOpen = (Boolean)map.get(isOpenKey);