Module dk.tbsalling.ais.messages
Interface CachedDecodedValues
- All Known Implementing Classes:
AddressedBinaryMessage,AddressedSafetyRelatedMessage,AidToNavigationReport,AISMessage,ApplicationSpecificMessage,AssignedModeCommand,BaseStationReport,BerthingData,BinaryAcknowledge,BinaryBroadcastMessage,BinaryMessageMultipleSlot,BinaryMessageSingleSlot,ChannelManagement,ClassBCSStaticDataReport,DataLinkManagement,Error,ExtendedClassBEquipmentPositionReport,ExtendedShipStaticAndVoyageRelatedData,GNSSBinaryBroadcastMessage,GroupAssignmentCommand,InlandShipStaticAndVoyageRelatedData,Interrogation,LongRangeBroadcastMessage,NumberOfPersonsOnBoard,PositionReport,PositionReportClassAResponseToInterrogation,PositionReportClassAScheduled,PositionReportClassAAssignedSchedule,SafetyRelatedAcknowledge,SafetyRelatedBroadcastMessage,ShipAndVoyageData,StandardClassBCSPositionReport,StandardSARAircraftPositionReport,UnknownApplicationSpecificMessage,UTCAndDateInquiry,UTCAndDateResponse
public interface CachedDecodedValues
Created by tbsalling on 20/01/15.
-
Method Summary
Modifier and Type Method Description default <T> TgetDecodedValue(Supplier<T> getter, Consumer<T> setter, Supplier<Boolean> condition, Supplier<T> decoder)Decode a value and cache it for faster future calls.default <T> TgetDecodedValueByWeakReference(Supplier<WeakReference<T>> refGetter, Consumer<WeakReference<T>> refSetter, Supplier<Boolean> condition, Supplier<T> decoder)Decode a value and cache it for faster future calls.
-
Method Details
-
getDecodedValueByWeakReference
default <T> T getDecodedValueByWeakReference(Supplier<WeakReference<T>> refGetter, Consumer<WeakReference<T>> refSetter, Supplier<Boolean> condition, Supplier<T> decoder)Decode a value and cache it for faster future calls. Use weak references for the caching to allow the garbage collector to free up memory. The value can just be decoded again.- Type Parameters:
T- The return type.- Parameters:
refGetter- A getter which gets the weak reference to be used as cacherefSetter- A setter to set the weak reference caching the decoded value.decoder- A supplier which can extract the decoded value from a bit string.condition- Only return a non-null value if this condition is true.- Returns:
- The decoded (and now cached) value.
-
getDecodedValue
default <T> T getDecodedValue(Supplier<T> getter, Consumer<T> setter, Supplier<Boolean> condition, Supplier<T> decoder)Decode a value and cache it for faster future calls.- Type Parameters:
T- The return type.- Parameters:
getter- A getter which gets previously decoded values of this property.setter- A setter which stores or caches the decoded valuecondition- Only return a non-null value if this condition is true.decoder- A supplier which can extract the decoded value from a bit string.- Returns:
- The decoded value.
-