SageTV Community  

Go Back   SageTV Community > SageTV Development and Customizations > SageTV Studio
Forum Rules FAQs Community Downloads Today's Posts Search

Notices

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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 12-04-2010, 12:21 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #2  
Old 12-04-2010, 12:47 PM
Fuzzy's Avatar
Fuzzy Fuzzy is offline
SageTVaholic
 
Join Date: Sep 2005
Location: Jurupa Valley, CA
Posts: 9,957
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
Reply With Quote
  #3  
Old 12-04-2010, 12:56 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
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.
Reply With Quote
  #4  
Old 12-04-2010, 01:01 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
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.
Reply With Quote
  #5  
Old 12-04-2010, 01:03 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
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
Reply With Quote
  #6  
Old 12-04-2010, 01:04 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
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.
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.
Reply With Quote
  #7  
Old 12-04-2010, 03:05 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by stuckless View Post
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.
Understood.

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.
Reply With Quote
  #8  
Old 12-04-2010, 03:31 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by tmiranda View Post
Understood.

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
It's all good unless you don't stop recursing
Reply With Quote
  #9  
Old 12-04-2010, 03:50 PM
tmiranda's Avatar
tmiranda tmiranda is offline
SageTVaholic
 
Join Date: Jul 2005
Location: Central Florida, USA
Posts: 5,851
Quote:
Originally Posted by stuckless View Post
It's all good unless you don't stop recursing
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.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
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


All times are GMT -6. The time now is 02:24 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2023, vBulletin Solutions Inc.
Copyright 2003-2005 SageTV, LLC. All rights reserved.