|
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 |
#201
|
||||
|
||||
Correct use of SortLexical
Sean,
I'm trying to use SortLexical() and am having trouble getting the types to work out. My code is below: Code:
/** * Sort an ArrayList of Episodes by date recorded. * <p> * @param episodes An ArrayList of Episodes to be sorted. * @param descending false to sort from oldest to newest, true to sort from newest to oldest. * @return A sorted ArrayList or null if error. */ public static ArrayList<Episode> sortByDateRecorded(ArrayList<Episode> episodes, boolean descending) { ArrayList<Episode> SortedEpisodes = new ArrayList<Episode>(); if (!(SortedEpisodes instanceof ArrayList)) { System.out.println("sortByDateRecorded: Bad new SortedEpisodes."); return null; } SortedEpisodes = Database.SortLexical(episodes, descending, "tmiranda.mob.Episode.getDateRecorded"); if (SortedEpisodes==null) { System.out.println("sortByDateRecorded: null SortedEpisodes."); return null; } System.out.println("sortByDateRecorded: Returning SortedEpisodes."); return SortedEpisodes; }
__________________
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. |
#202
|
||||
|
||||
Quote:
The other thing is the the method that you pass in the sort lexical, must be in the STV format (i'm pretty sure), so tmiranda_mob_Episode_getDateRecorded. I've never used SortLexical myself, and the javadoc is a little ambiqious... but think the value that you'd want for the method would simply be "getDateRecorded", or "tmiranda_mob_Episode_getDateRecorded" and the first arg must be the Object (ie Episode). Hope this helps.
__________________
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 |
#203
|
||||
|
||||
Sean,
1. How do I check if new worked or not? Do I just assume it worked? Check for null? 2. I tried the following for the line in question and nothing worked: Code:
SortedEpisodes = Database.SortLexical((Object)episodes, descending, "tmiranda_mob_Episode_getDateRecorded"); (Object)SortedEpisodes = Database.SortLexical((Object)episodes, descending, "tmiranda_mob_Episode_getDateRecorded"); (Object)SortedEpisodes = Database.SortLexical(episodes, descending, "tmiranda_mob_Episode_getDateRecorded");
__________________
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. |
#204
|
|||
|
|||
Can i see the code where you get what you are sorting please. Are you passing it correctly is what I am wondering as what you did should work. I am wondering if you are really passing an array list or not.
|
#205
|
||||
|
||||
Plucky,
The method is completely listed in the post. It won't compile so I don't think it has anything to do with what I'm passing into it 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. |
#206
|
|||
|
|||
I see that now sorry missed it
anyhow I am pretty sure you need to pass it like this been a while since I last used this call Code:
SortedEpisodes = Database.SortLexical((Object)episodes, true, "tmiranda_mob_Episode_getDateRecorded"); but in descending i know it wants a true or false edit don't think you need to cast it at all to an object or object[] |
#207
|
|||
|
|||
After reading the java docs again it will return an object[] not an array. If it is passed an array as you are it will return an object[]
|
#208
|
||||
|
||||
Quote:
you need something like this... (this is freehand, so may now compile as is) Code:
Object result[] = Database.SortLexical(episodes, true, "tmiranda_mob_Episode_getDateRecorded"); if (result!=null) { // covert to array, if that's what your want... return Arrays.asList(result); } ie Code:
List<Episode> list = new ArrayList<Episode>(); or public static List<Episode> sortByDateRecorded(List<Episode> episodes, boolean descending) {
__________________
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 |
#209
|
|||
|
|||
Also sorry tom I completely missed your descending was a boolean
|
#210
|
||||
|
||||
Sean, Plucky,
Thanks, but I could not get it to compile with the results specified as Object[]. The following did compile, but I have no idea if it will do what I want. I stripped away all but the bare essentials. Notice that SortLexical is returning "Object results" not "Object results[]". Code:
public static List<Episode> sortTest1(List<Episode> a, boolean b) { Object results = Database.SortLexical(a, b, "tmiranda_mob_Episode_getDateRecorded"); return Arrays.asList((Episode)results); } Thanks for the tip on List instead of ArrayList. 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. |
#211
|
||||
|
||||
Quote:
The easy fix it to change your return on the function to be Object[] and then cast results to Object[] Code:
public static Object[] sortTest1(List<Episode> a, boolean b) { Object results = Database.SortLexical(a, b, "tmiranda_mob_Episode_getDateRecorded"); return (Object[])results; } So, my solution would be to change the return type to Object[]
__________________
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 |
#212
|
||||
|
||||
Sean,
The method is not being called by the STV, it's used inside my Java code so I need to deal with the type conversion. This compiles, but do you think it will work or is it just doing the same thing that you said in your last post was probably invalid? My return statement looks different than yours Code:
public static List<Episode> sortByDateRecorded(List<Episode> episodes, boolean descending) { Object Results = Database.SortLexical(episodes, descending, "tmiranda_mob_Episode_getDateRecorded"); if (Results==null) { System.out.println("sortByDateRecorded: null Results."); return null; } return Arrays.asList((Episode)Results); }
__________________
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. Last edited by tmiranda; 06-04-2010 at 08:53 PM. |
#213
|
||||
|
||||
Tom, try this..
Code:
public static List<Episode> sortByDateRecorded(List<Episode> episodes, boolean descending) { Episode Results[] = (Episode[])Database.SortLexical(episodes, descending, "tmiranda_mob_Episode_getDateRecorded"); if (Results==null) { System.out.println("sortByDateRecorded: null Results."); return null; } return Arrays.asList(Results); }
__________________
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 |
#214
|
||||
|
||||
Sean,
Just to put a bow around this issue. I did not try what you suggested but I think I know the solution - I need to learn more Java What I really need to do is implement a custom comparator so I can use sort() on my list directly rather than relying on using another method to do the sort. I think that will be a lot cleaner than using Sage's "SortByMethod", what think you? Am I on the right track? 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. |
#215
|
||||
|
||||
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 |
#216
|
||||
|
||||
The project I am working on is a learning exercise so I might as well learn how to use comparitors. I read up on it yesterday and it does not seem too difficult. I need to learn more because I see all kinds of warnings to make sure you do not do something that gives results inconsistent with the equals() method, and I'm sure what equals() should return for a custom collection.
__________________
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. |
#217
|
||||
|
||||
Sean,
I think I found a bug. I'm getting a null pointer exception from FavoriteAPI.IsAutoDeleteAfterConversion(). I also noticed that the name of the API does not fully match the name of the corresponding Sage FavoriteAPI IsDeleteAfterAutomaticConversion() so I may be doing something wrong. Here is the test code: Code:
Object[] SageFavorites = FavoriteAPI.GetFavorites(); if (SageFavorites==null || SageFavorites.length==0) { Log.getInstance().write(Log.LOGLEVEL_TRACE, "sync: No SageFavorites."); return true; } Log.getInstance().write(Log.LOGLEVEL_TRACE, "sync: Found SageFavorites = " + SageFavorites.length); System.out.println("START TEST:"); for (Object F : SageFavorites) { FavoriteAPI.IsAutoDeleteAfterConversion(F); } System.out.println("END TEST:"); Code:
Sun 7/18 8:57:27.245 [SageTV@eee4dc] BU: sync: Found SageFavorites = 102 Sun 7/18 8:57:27.246 [SageTV@eee4dc] START TEST: Sun 7/18 8:57:27.246 [SageTV@eee4dc] java.lang.NullPointerException Sun 7/18 8:57:27.246 [SageTV@eee4dc] at sage.e$e.a(Unknown Source) Sun 7/18 8:57:27.246 [SageTV@eee4dc] at sage.e.a(Unknown Source) Sun 7/18 8:57:27.247 [SageTV@eee4dc] at sage.SageTV.api(Unknown Source) Sun 7/18 8:57:27.247 [SageTV@eee4dc] at sagex.remote.EmbeddedSageAPIProvider.callService(EmbeddedSageAPIProvider.java:16) Sun 7/18 8:57:27.247 [SageTV@eee4dc] at sagex.SageAPI.call(SageAPI.java:163) Sun 7/18 8:57:27.247 [SageTV@eee4dc] at sagex.api.FavoriteAPI.IsAutoDeleteAfterConversion(FavoriteAPI.java:201) Sun 7/18 8:57:27.247 [SageTV@eee4dc] at tmiranda.backup.BUFavorite.sync(BUFavorite.java:118) Sun 7/18 8:57:27.247 [SageTV@eee4dc] at tmiranda.backup.plugin.start(plugin.java:71) Sun 7/18 8:57:27.247 [SageTV@eee4dc] at sage.plugin.a.byte(Unknown Source) Sun 7/18 8:57:27.248 [SageTV@eee4dc] at sage.SageTV.run(Unknown Source) Sun 7/18 8:57:27.248 [SageTV@eee4dc] at java.lang.Thread.run(Unknown Source) Sun 7/18 8:57:27.252 [SageTV@eee4dc] java.lang.NullPointerException Sun 7/18 8:57:27.252 [SageTV@eee4dc] at sage.e$e.a(Unknown Source) Sun 7/18 8:57:27.253 [SageTV@eee4dc] at sage.e.a(Unknown Source) Sun 7/18 8:57:27.253 [SageTV@eee4dc] at sage.SageTV.api(Unknown Source) Sun 7/18 8:57:27.253 [SageTV@eee4dc] at sagex.remote.EmbeddedSageAPIProvider.callService(EmbeddedSageAPIProvider.java:16) Sun 7/18 8:57:27.253 [SageTV@eee4dc] at sagex.SageAPI.call(SageAPI.java:163) Sun 7/18 8:57:27.253 [SageTV@eee4dc] at sagex.api.FavoriteAPI.IsAutoDeleteAfterConversion(FavoriteAPI.java:201) Sun 7/18 8:57:27.253 [SageTV@eee4dc] at tmiranda.backup.BUFavorite.sync(BUFavorite.java:118) Sun 7/18 8:57:27.254 [SageTV@eee4dc] at tmiranda.backup.plugin.start(plugin.java:71) Sun 7/18 8:57:27.254 [SageTV@eee4dc] at sage.plugin.a.byte(Unknown Source) Sun 7/18 8:57:27.259 [SageTV@eee4dc] at sage.SageTV.run(Unknown Source) Sun 7/18 8:57:27.259 [SageTV@eee4dc] at java.lang.Thread.run(Unknown Source) Sun 7/18 8:57:27.260 [SageTV@eee4dc] java.lang.NullPointerException Sun 7/18 8:57:27.260 [SageTV@eee4dc] at sage.e$e.a(Unknown Source) Sun 7/18 8:57:27.260 [SageTV@eee4dc] at sage.e.a(Unknown Source) Sun 7/18 8:57:27.261 [SageTV@eee4dc] at sage.SageTV.api(Unknown Source) Sun 7/18 8:57:27.261 [SageTV@eee4dc] at sagex.remote.EmbeddedSageAPIProvider.callService(EmbeddedSageAPIProvider.java:16) Sun 7/18 8:57:27.261 [SageTV@eee4dc] at sagex.SageAPI.call(SageAPI.java:163) Sun 7/18 8:57:27.270 [SageTV@eee4dc] at sagex.api.FavoriteAPI.IsAutoDeleteAfterConversion(FavoriteAPI.java:201) Sun 7/18 8:57:27.271 [SageTV@eee4dc] at tmiranda.backup.BUFavorite.sync(BUFavorite.java:118) Sun 7/18 8:57:27.271 [SageTV@eee4dc] at tmiranda.backup.plugin.start(plugin.java:71) Sun 7/18 8:57:27.271 [SageTV@eee4dc] at sage.plugin.a.byte(Unknown Source) Sun 7/18 8:57:27.271 [SageTV@eee4dc] at sage.SageTV.run(Unknown Source) Sun 7/18 8:57:27.271 [SageTV@eee4dc] at java.lang.Thread.run(Unknown Source) Sun 7/18 8:57:27.272 [SageTV@eee4dc] java.lang.NullPointerException Sun 7/18 8:57:27.272 [SageTV@eee4dc] at sage.e$e.a(Unknown Source) Sun 7/18 8:57:27.272 [SageTV@eee4dc] at sage.e.a(Unknown Source) Sun 7/18 8:57:27.273 [SageTV@eee4dc] at sage.SageTV.api(Unknown Source) Sun 7/18 8:57:27.273 [SageTV@eee4dc] at sagex.remote.EmbeddedSageAPIProvider.callService(EmbeddedSageAPIProvider.java:16) Sun 7/18 8:57:27.273 [SageTV@eee4dc] at sagex.SageAPI.call(SageAPI.java:163) Sun 7/18 8:57:27.283 [SageTV@eee4dc] at sagex.api.FavoriteAPI.IsAutoDeleteAfterConversion(FavoriteAPI.java:201) Sun 7/18 8:57:27.284 [SageTV@eee4dc] at tmiranda.backup.BUFavorite.sync(BUFavorite.java:118) Sun 7/18 8:57:27.284 [SageTV@eee4dc] at tmiranda.backup.plugin.start(plugin.java:71) Sun 7/18 8:57:27.293 [SageTV@eee4dc] at sage.plugin.a.byte(Unknown Source) Sun 7/18 8:57:27.293 [SageTV@eee4dc] at sage.SageTV.run(Unknown Source) Sun 7/18 8:57:27.293 [SageTV@eee4dc] at java.lang.Thread.run(Unknown Source) Sun 7/18 8:57:27.294 [SageTV@eee4dc] java.lang.NullPointerException Sun 7/18 8:57:27.294 [SageTV@eee4dc] at sage.e$e.a(Unknown Source) Sun 7/18 8:57:27.295 [SageTV@eee4dc] at sage.e.a(Unknown Source) Sun 7/18 8:57:27.295 [SageTV@eee4dc] at sage.SageTV.api(Unknown Source) Sun 7/18 8:57:27.295 [SageTV@eee4dc] at sagex.remote.EmbeddedSageAPIProvider.callService(EmbeddedSageAPIProvider.java:16) Sun 7/18 8:57:27.295 [SageTV@eee4dc] at sagex.SageAPI.call(SageAPI.java:163) Sun 7/18 8:57:27.295 [SageTV@eee4dc] at sagex.api.FavoriteAPI.IsAutoDeleteAfterConversion(FavoriteAPI.java:201) Sun 7/18 8:57:27.296 [SageTV@eee4dc] at tmiranda.backup.BUFavorite.sync(BUFavorite.java:118) Sun 7/18 8:57:27.296 [SageTV@eee4dc] at tmiranda.backup.plugin.start(plugin.java:71) Sun 7/18 8:57:27.296 [SageTV@eee4dc] at sage.plugin.a.byte(Unknown Source) Sun 7/18 8:57:27.296 [SageTV@eee4dc] at sage.SageTV.run(Unknown Source) Sun 7/18 8:57:27.296 [SageTV@eee4dc] at java.lang.Thread.run(Unknown Source) Sun 7/18 8:57:27.297 [SageTV@eee4dc] java.lang.NullPointerException Sun 7/18 8:57:27.298 [SageTV@eee4dc] at sage.e$e.a(Unknown Source) Sun 7/18 8:57:27.298 [SageTV@eee4dc] at sage.e.a(Unknown Source) Sun 7/18 8:57:27.299 [SageTV@eee4dc] at sage.SageTV.api(Unknown Source) Sun 7/18 8:57:27.299 [SageTV@eee4dc] at sagex.remote.EmbeddedSageAPIProvider.callService(EmbeddedSageAPIProvider.java:16) Sun 7/18 8:57:27.299 [SageTV@eee4dc] at sagex.SageAPI.call(SageAPI.java:163) Sun 7/18 8:57:27.309 [SageTV@eee4dc] at sagex.api.FavoriteAPI.IsAutoDeleteAfterConversion(FavoriteAPI.java:201) Sun 7/18 8:57:27.309 [SageTV@eee4dc] at tmiranda.backup.BUFavorite.sync(BUFavorite.java:118) Sun 7/18 8:57:27.309 [SageTV@eee4dc] at tmiranda.backup.plugin.start(plugin.java:71) Sun 7/18 8:57:27.309 [SageTV@eee4dc] at sage.plugin.a.byte(Unknown Source) Sun 7/18 8:57:27.309 [SageTV@eee4dc] at sage.SageTV.run(Unknown Source) Sun 7/18 8:57:27.310 [SageTV@eee4dc] at java.lang.Thread.run(Unknown Source)
__________________
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. |
#218
|
||||
|
||||
The apis are generated from the javadoc (you probably knew that) and it was wrong up until 7.0.12. The apis need to be regenerated so they have the right method name.
__________________
Server: Intel Core i5 760 Quad, Gigabyte GA-H57M-USB3, 4GB RAM, Gigabyte GeForce 210, 120GB SSD (OS), 1TB SATA, HD HomeRun. Extender: STP-HD300, Harmony 550 Remote, Netgear MCA1001 Ethernet over Coax. SageTV: SageTV Server 7.1.8 on Ubuntu Linux 11.04, SageTV Placeshifter for Mac 6.6.2, SageTV Client 7.0.15 for Windows, Linux Placeshifter 7.1.8 on Server and Client, Java 1.6. Plugins: Jetty, Nielm's Web Server, Mobile Web Interface. |
#219
|
||||
|
||||
John,
I suspected that, but being a java noobie I thought it was better to blame myself for doing something wrong before I blamed somebody else Thanks for confirming this. 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. |
#220
|
||||
|
||||
Tom, I refreshed the sagex-apis based on what sage has published (hopefully it's the 7.0.12 apis).
The files should be available for download in the repository and the google code project. I suspect that the null pointer is related to fact that the API name was wrong (which would have been that was in the previous JavaDoc on which the previous build was made)
__________________
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 |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Hauppauge Remote Issue | yacht_boy | Hardware Support | 4 | 05-01-2008 09:25 PM |
MCE remote transmitting keypresses twice | arnabbiswas | Hardware Support | 1 | 02-22-2007 10:55 AM |
MCE Remote not work fully with Placeshifter | devinteske | SageTV Placeshifter | 5 | 02-08-2007 11:45 PM |
Harmony Remote IR Reciever Help | brundag5 | Hardware Support | 2 | 01-13-2007 09:08 PM |
How to get SageTV to release focus to NVDVD for remote | IncredibleHat | SageTV Software | 4 | 07-06-2006 07:47 AM |