Package org.ka2ddo.yaac.weather
Class WeatherDistributor
This class collects weather data from the local weather station and makes it available
to other listening classes.
- Author:
- Andrew Pavlin, KA2DDO
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,
V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
Modifier and TypeFieldDescriptionstatic final String[]
Types of weather stations (abbreviations) to be appended to generic weather station data strings. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Register a WeatherListener to be notified of updates in the weather data.entrySet()
Returns aSet
view of the mappings contained in this map.Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.get
(WeatherEnum e) Fetch a numeric value from the weather data.static WeatherDistributor
Get the WeatherDistributor singleton.static String[]
Returns an array of localized weather station model names, in the same order as the standard abbreviations.boolean
isEmpty()
Returnstrue
if this map contains no key-value mappings.keySet()
Returns a Set view of the keys contained in this map.void
loadCurrentWeather
(Map<? extends Enum, ?> extensions) Copy weather data from some other map into the currentWeather map in this WeatherDistributor.Build a PositionlessWeatherReport from the current state of the collected local weather data.parseWeatherData
(String line, Map<Enum, Object> currentWeather) Decode weather data in Peet Bros format into the distributor's cache.put
(WeatherEnum e, Object value) Store a new value into the weather map.void
Deregister a WeatherListener so it will no longer be informed of changes in the local weather data.int
size()
Returns the number of key-value mappings in this map.values()
Returns a Collection view of the values contained in this map.Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, hashCode, put, putAll, remove, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Field Details
-
WEATHER_STATION_TYPES
Types of weather stations (abbreviations) to be appended to generic weather station data strings. The key "WeatherStationType."+the abbreviation is the key to look up the localized name string for each supported abbreviation.
-
-
Method Details
-
getInstance
Get the WeatherDistributor singleton.- Returns:
- WeatherDistributor singleton object
-
parseWeatherData
Decode weather data in Peet Bros format into the distributor's cache.- Parameters:
line
- String to parsecurrentWeather
- Map for storing the extracted weather data- Returns:
- Map containing the weather data
-
loadCurrentWeather
Copy weather data from some other map into the currentWeather map in this WeatherDistributor.- Parameters:
extensions
- Map of WeatherEnums to values
-
get
Fetch a numeric value from the weather data.- Parameters:
e
- WeatherEnum for the data item wanted- Returns:
- Number of the value of the requested weather data item, or null if the item isn't known
-
put
Store a new value into the weather map.- Parameters:
e
- WeatherEnum identifying the field to be updatedvalue
- Object value to be stored; note that most WeatherEnums require a Number subclass as their value- Returns:
- the previous value stored for the WeatherEnum key
- Throws:
ClassCastException
- if trying to store a non-numeric value for a WeatherEnum that expects a Number
-
addWeatherListener
Register a WeatherListener to be notified of updates in the weather data.- Parameters:
l
- WeatherListener to register
-
removeWeatherListener
Deregister a WeatherListener so it will no longer be informed of changes in the local weather data.- Parameters:
l
- WeatherListener to deregister
-
makeWeatherMsg
Build a PositionlessWeatherReport from the current state of the collected local weather data.- Returns:
- PositionlessWeatherReport containing the current local weather, or null if there is no weather data to report
-
getWeatherModelNameStrings
Returns an array of localized weather station model names, in the same order as the standard abbreviations.- Returns:
- String array of model names
-
entrySet
Returns aSet
view of the mappings contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremove
operation, or through thesetValue
operation on a map entry returned by the iterator) the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove
,Set.remove
,removeAll
,retainAll
andclear
operations. It does not support theadd
oraddAll
operations. -
size
public int size()Returns the number of key-value mappings in this map. If the map contains more thanInteger.MAX_VALUE
elements, returnsInteger.MAX_VALUE
. -
isEmpty
public boolean isEmpty()Returnstrue
if this map contains no key-value mappings. -
get
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.More formally, if this map contains a mapping from a key
k
to a valuev
such that(key==null ? k==null : key.equals(k))
, then this method returnsv
; otherwise it returnsnull
. (There can be at most one such mapping.)If this map permits null values, then a return value of
null
does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key tonull
. ThecontainsKey
operation may be used to distinguish these two cases.- Specified by:
get
in interfaceMap<Enum,
Object> - Overrides:
get
in classAbstractMap<Enum,
Object> - Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
null
if this map contains no mapping for the key - Throws:
ClassCastException
- if the key is of an inappropriate type for this map (optional)NullPointerException
- if the specified key is null and this map does not permit null keys (optional)
-
keySet
Returns a Set view of the keys contained in this map. The set is backed by the map, so changes to the map are reflected in the set, and vice-versa. If the map is modified while an iteration over the set is in progress (except through the iterator's ownremove
operation), the results of the iteration are undefined. The set supports element removal, which removes the corresponding mapping from the map, via theIterator.remove
,Set.remove
,removeAll
,retainAll
, andclear
operations. It does not support theadd
oraddAll
operations. -
values
Returns a Collection view of the values contained in this map. The collection is backed by the map, so changes to the map are reflected in the collection, and vice-versa. If the map is modified while an iteration over the collection is in progress (except through the iterator's ownremove
operation), the results of the iteration are undefined. The collection supports element removal, which removes the corresponding mapping from the map, via theIterator.remove
,Collection.remove
,removeAll
,retainAll
andclear
operations. It does not support theadd
oraddAll
operations.
-