![]() |
|
|||||||
| 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
|
|||
|
|||
|
Remove a MediaFileAPI.List item with an Iterator
I am using Greg's API and in java, I am trying to remove some items from a MediaFileAPI.List using an Iterator to loop through the collection. When I try to remove an item, I get a java.lang.UnsupportedOperationException exception.
Anyone have any ideas??? Thanks, Jeff EDIT: From the research I have done, it appears that the MediaFileAPI.List is an AbstractList, and if no remove method is created, than that exception is thrown... Anyone have a good idea on editing the list without haveing the overhead of copying it to another array? Last edited by jphipps; 08-03-2009 at 07:34 PM. |
|
#2
|
||||
|
||||
|
The List types implemented by my API wrappers are not intended to be mutable; the add and remove methods are unsupported by design. If you need a mutable collection (i.e. one that supports adding and removing elements), create a new ArrayList or whatever passing my List into the constructor as the initial contents:
Code:
MediaFileAPI.List list1 = api.mediaFileAPI.GetMediaFiles(); // not mutable List<MediaFileAPI.MediaFile> list2 = new ArrayList<MediaFileAPI.MediaFile>(list1); // mutable
__________________
-- Greg |
|
#3
|
|||
|
|||
|
Thanks, I appreciate your help.. it works great... I was worried about the performance impact on createing a new List, but it runs pretty fast...
Thanks again, Jeff |
|
#4
|
|||
|
|||
|
Okay so that explains my issue with trying to draw elements from GetMediaFiles() within eclipse. But I am confused as GetMediaFiles() returns an object[] and I am not sure how to convert it in eclipse to an arraylist.
TIA |
|
#5
|
||||
|
||||
|
This page has examples of converting an array to a list and vice-versa.
http://snippets.dzone.com/posts/show/343
__________________
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. |
|
#6
|
|||
|
|||
|
Thanks for the example and sorry for the denseness but I am missing something and I guess having a hard time grasping arrays in eclipse
here is my code it tells me Videos[] cannot be resolved. Code:
Videos[] arrayofvideos = MediaFileAPI.GetMediaFiles("VDB").toArray(new Videos[]{});
|
|
#7
|
|||
|
|||
|
Quote:
From this example, it looks like you are trying to convert it into an Array - but up above you said you wanted an "arraylist" which is a different construct - a list interface backed by an Array. If you want it as an ArrayList instead of an Array you would do - List videos = new ArrayList(MediaFileAPI.GetMediaFiles("VDB")); as for an Array, that method for conversion looks correct. I have never used studio or this API before.. but are you use the class name is "Videos" and not "Video"? In other words does Code:
Video[] arrayofvideos = MediaFileAPI.GetMediaFiles("VDB").toArray(new Video[]{});
|
|
#8
|
|||
|
|||
|
After taking a quick look at the both the Sage API and Greg's API I can't find any reference to a Video or Videos class.
Is this what you want? Code:
MediaFileAPI.MediaFile[] videos = MediaFileAPI.GetMediaFiles("VDB").toArray(new MediaFileAPI.MediaFile[]{});
|
|
#9
|
|||
|
|||
|
That makes more sense thank you I am trying to learn but sometimes teaching myself it hard
|
|
#10
|
|||
|
|||
|
Greg's example above shows how to build a List from the MediaFileAPI.List that is generated from the GetMediaFiles() call.
I found using the List the best route, and you can use an Iterator or index to spin through it, and also remove items if needed... Thanks, Jeff |
|
#11
|
||||
|
||||
|
The native GetMediaFiles() API method returns an Array. My wrapper function returns a List, as indicated in the documentation for my package. (Eclipse should also be able to show you the javadocs for the methods you're calling.) Result types matter; you can't assign an Array object to a List variable, and vice versa. Know what data types you're dealing with, and declare your variables accordingly.
If this is your first venture into actual Java programming (as distinct from Studio coding), I strongly recommend a good Java tutorial. Here's one place to start: Learning the Java Language
__________________
-- Greg |
|
#12
|
||||
|
||||
|
Greg,
Whats's the difference between a List and an Array? 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. |
|
#13
|
|||
|
|||
|
Quote:
Code:
listName instanceof RandomAccess |
|
#14
|
|||
|
|||
|
To fully answer this would require a lot of space. Because the differences are fairly technical and you would have to read the JLS (Java Language Specification) to fully understand how they are treated differently by a JVM, etc.
Practically, it is easier to list the differences that apply to most programing situations. Arrays: Guaranteed constant time access and updating a specific element. In other words the size of the array will not impact how long it takes to get to a certain element. (For simplification sake we are not talking about really large array that may have parts swapped out by the OS). Elements may be accessed without method invocation. For example int x = intArray[5] would get you the 6th element of the array - arrays start at 0. You cannot grow an array. Arrays can hold primitive data types (ints,doubles,chars). Lists: Lists are an interface inside the collections package that are part of java.util Several classes in this package implement this interface and are optimized for various tasks (An array based list, a linked based list, etc). Lists MAY grow (It depends on the backing class) Lists can only hold Objects, ints, chars, etc must be placed in an object before being placed in a list. In this example, the api author has created a Class called List which seems to be a partial reimplementation of an ArrayList. Last edited by broconne; 08-04-2009 at 01:35 PM. |
|
#15
|
||||
|
||||
|
Quote:
For more on Arrays v. Lists, see the Java tutorial on Collections.
__________________
-- Greg |
|
#16
|
|||
|
|||
|
Quote:
Google collections as a nice way of doing the same thing now - but obviously google collections didn't exist back when this api was being written. API looks great, I just need to find a project to use it on :-) |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Menu item disappeared | sleonard | SageTV Customizations | 2 | 02-27-2009 12:01 AM |
| Can't get new submenu item to work | Jesse | SageMC Custom Interface | 2 | 12-17-2008 07:32 AM |
| Table With 1 Item Being Stretched/Resized | cncb | SageTV Studio | 3 | 03-25-2008 12:12 PM |
| finding the 'selected item' thingy... | xlr8shun | SageTV Studio | 3 | 03-04-2006 09:29 PM |