![]() |
|
SageTV Studio Discussion related to the SageTV Studio application produced by SageTV. Questions, issues, problems, suggestions, etc. relating to the Studio software application should be posted here. |
![]() |
|
Thread Tools | Search this Thread | Display Modes |
#1
|
||||
|
||||
Proper way to implement equals()?
I've started fooling around with the plugin to remove all dependencies when you remove a single plugin. One of the things I've discovered is when I create a List (or Set) of Objects that contain Sage Plugins, methods like .contains() do not work presumably because .equals() is not working. I know I can create some custom methods to scan a List<Object> for a specific Plugin but the better way is probably to make a proper .equals() method.
The question is how do I tell Java to use my custom .equals() method when the Object contains a Sage Plugin? I'm using Sean's sagex APIs so the Plugins are all generic Objects. I'm probably missing something obvious. Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#2
|
||||
|
||||
Could you do the matching using the plugin name instead of the plugin object itself?
__________________
Buy Fuzzy a beer! (Fuzzy likes beer) unRAID Server: i7-6700, 32GB RAM, Dual 128GB SSD cache and 13TB pool, with SageTVv9, openDCT, Logitech Media Server and Plex Media Server each in Dockers. Sources: HRHR Prime with Charter CableCard. HDHR-US for OTA. Primary Client: HD-300 through XBoxOne in Living Room, Samsung HLT-6189S Other Clients: Mi Box in Master Bedroom, HD-200 in kids room |
#3
|
||||
|
||||
I'd personally, store a list of plugin ids. Using a string id for the plugin will ensure that equals and, remove, indexOf, etc, will all work without you having to do any work.
Then when you need a plugin instance, you can call, GetAvailablePluginForID(PluginID) and get a real reference, when needed.
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#4
|
||||
|
||||
The IDs probably are a better way to go....
I didn't do that initially because in Studio comparing two Plugins with == works as expected so I assumed (incorrectly) that means that .equals would work in Java.
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#5
|
||||
|
||||
You can override Object.equals() on classes you define. You can't override it for an existing class (without subclassing it). So if you're calling PluginAPI methods that return arrays of sage.Plugin, there's nothing you can do to cause those returned objects to use a different .equals() method. They'll use the one that's defined for the sage.Plugin class.
(If you're using my API wrappers, the same considerations apply. The .equals() method means whatever the underlying wrapped object says it means, and consumers of those objects don't get to redefine it.) You may be making an unwarranted assumption that there's a one-to-one correspondence between sage.Plugin objects and PluginIDs. That's not necessarily true; a sage.Plugin object is just a container for some information about a plugin. There's no guarantee that if you ask for the same information again, you'll get back the identical (in the sense of Object.equals()) sage.Plugin object. In particular, I'm pretty sure that sage.Plugin objects obtained from GetAvailablePlugins() will not be .equals() to those obtained from GetInstalledPlugins(), even for the same PluginID. So in the end I think you're going to have to bite the bullet and compare PluginIDs directly rather than relying on .equals() and its derivatives to detect when two different sage.Plugin objects refer to the same (conceptual) plugin.
__________________
-- Greg |
#6
|
||||
|
||||
Well, if you are using sagex apis, and you are working remotely, then .equals() will not work. Mainly because remotely, you never have a handle to the actual sagetv object, but rather a reference object that knows nothing about what it is referencing.
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#7
|
||||
|
||||
Quote:
This Plugin is turning out to be a good review on how to write recursive methods. I wrote a recursive constructor that seems to work as I expect. Is it bad practice to use recursive contructors in Java? I want to make sure I'm not going down the wrong path. Tom
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
#8
|
||||
|
||||
Quote:
![]()
__________________
Batch Metadata Tools (User Guides) - SageTV App (Android) - SageTV Plex Channel - My Other Android Apps - sagex-api wrappers - Google+ - Phoenix Renamer Downloads SageTV V9 | Android MiniClient |
#9
|
||||
|
||||
My parents taught me to stop recursing when I was small
![]()
__________________
Sage Server: 8th gen Intel based system w/32GB RAM running Ubuntu Linux, HDHomeRun Prime with cable card for recording. Runs headless. Accessed via RD when necessary. Four HD-300 Extenders. |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Still has no equals... | TwistedMelon | SageTV HD Theater - Media Player | 3 | 11-06-2009 05:19 PM |
How to implement a ew FRQ file?? | scoob101 | SageTV EPG Service | 3 | 02-23-2009 01:22 PM |
How best to implement SageTV | acater | Hardware Support | 2 | 06-01-2006 03:31 AM |
2 sources today equals a messed up guide | SprDtyF350 | SageTV EPG Service | 3 | 12-11-2005 09:00 PM |
How do you find out what Default equals? | OPTIMO | SageTV Software | 4 | 09-22-2004 08:57 PM |