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 01-12-2011, 11:01 AM
Tiki's Avatar
Tiki Tiki is offline
Sage Icon
 
Join Date: Feb 2005
Location: Southwest Florida, USA
Posts: 2,009
Help with Java Maps

The Sage API contains a method called GetMediaFilesWithImportPrefix(). It returns a map if the last parameter passed to it (GroupFolders) is TRUE, otherwise it returns a vector.

I want to iterate through this map or vector and remove any media files that reside in a specific path. I have no problem dealing with the vector, but not sure how to iterate through a map and remove the unwanted items.

If it matters, I want to do this in studio (though I think I will need to call some java methods to accomplish this).

Can anyone point me in the right direction?
__________________
Server: Ryzen 2400G with integrated graphics, ASRock X470 Taichi Motherboard, HDMI output to Vizio 1080p LCD, Win10-64Bit (Professional), 16GB RAM
Capture Devices (7 tuners): Colossus (x1), HDHR Prime (x2)
,USBUIRT (multi-zone)
Source:
Comcast/Xfinity X1 Cable
Primary Client: Server Other Clients: (1) HD200, (1) HD300
Retired Equipment: MediaMVP, PVR150 (x2), PVR150MCE,
HDHR, HVR-2250, HD-PVR
Reply With Quote
  #2  
Old 01-12-2011, 11:15 AM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Maps are basically collections of Map.Entry objects where the Entry has a getKey() and a getValue()

if you don't care about the key, then you can simply iterate the map values by calling Map.values() (ie, java_util_Map_values(Map) ) which returns a collection of the values in the map without the keys.

If you need the keys... then you can use Map.entrySet() (ie, java_util_Map_entrySet(Map) ) which gives you a collection of Entry objects.

You can't remove from the map while you are iterating over it (at least not easily), so I'd build a second Map to hold the values that you want. As you interate over the Map.Entry objects, just add to the new map...
java_util_Map_put(NewMap, java_util_Map_Entry_getKey(MapEntry), java_util_Map_Entry_getValue(MapEntry))

Hope this helps you get started.
Reply With Quote
  #3  
Old 01-12-2011, 11:41 AM
Tiki's Avatar
Tiki Tiki is offline
Sage Icon
 
Join Date: Feb 2005
Location: Southwest Florida, USA
Posts: 2,009
Is it valid to iterate through the entry set as if it were an array?

Code:
Map = GetMediaFilesWithImportPrefix(a,b,c,d,e)
EntrySet = java_util_Map_entrySet(Map)

i=0
if i < Size(EntrySet) 'Start of Loop
  value = java_util_Map_Entry_getValue(EntrySet(i))
  key= java_util_Map_Entry_getKey(EntrySet(i))
  do something with value and key
  ...
  i=i+1
    if i< Size(EntrySet)  'End of Loop
This is how loops are generally accomplished in Studio code... not sure if I can do a java-style iterator
__________________
Server: Ryzen 2400G with integrated graphics, ASRock X470 Taichi Motherboard, HDMI output to Vizio 1080p LCD, Win10-64Bit (Professional), 16GB RAM
Capture Devices (7 tuners): Colossus (x1), HDHR Prime (x2)
,USBUIRT (multi-zone)
Source:
Comcast/Xfinity X1 Cable
Primary Client: Server Other Clients: (1) HD200, (1) HD300
Retired Equipment: MediaMVP, PVR150 (x2), PVR150MCE,
HDHR, HVR-2250, HD-PVR
Reply With Quote
  #4  
Old 01-12-2011, 12:01 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by Tiki View Post
Is it valid to iterate through the entry set as if it were an array?

Code:
Map = GetMediaFilesWithImportPrefix(a,b,c,d,e)
EntrySet = java_util_Map_entrySet(Map)

i=0
if i < Size(EntrySet) 'Start of Loop
  value = java_util_Map_Entry_getValue(EntrySet(i))
  key= java_util_Map_Entry_getKey(EntrySet(i))
  do something with value and key
  ...
  i=i+1
    if i< Size(EntrySet)  'End of Loop
This is how loops are generally accomplished in Studio code... not sure if I can do a java-style iterator
That should work fine to iterate it that way.
Reply With Quote
  #5  
Old 01-12-2011, 12:19 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
You may need to use GetElement(EntrySet, i) or java_util_Set_get(EntrySet, i).
Reply With Quote
  #6  
Old 01-12-2011, 12:26 PM
Tiki's Avatar
Tiki Tiki is offline
Sage Icon
 
Join Date: Feb 2005
Location: Southwest Florida, USA
Posts: 2,009
Quote:
Originally Posted by stuckless View Post
You may need to use GetElement(EntrySet, i) or java_util_Set_get(EntrySet, i).
Thanks, I used GetElement(entrySet, i) and it seems to be working, though I still have some other issues I need to work out...

Thanks for the help.
__________________
Server: Ryzen 2400G with integrated graphics, ASRock X470 Taichi Motherboard, HDMI output to Vizio 1080p LCD, Win10-64Bit (Professional), 16GB RAM
Capture Devices (7 tuners): Colossus (x1), HDHR Prime (x2)
,USBUIRT (multi-zone)
Source:
Comcast/Xfinity X1 Cable
Primary Client: Server Other Clients: (1) HD200, (1) HD300
Retired Equipment: MediaMVP, PVR150 (x2), PVR150MCE,
HDHR, HVR-2250, HD-PVR
Reply With Quote
  #7  
Old 01-12-2011, 03:05 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Java Sets don't have a defined element order and don't implement the get(i) method, so I'm not sure what GetElement() would do with them. Possibly something along the lines of copying the set into a temporary array and returning the ith element of the array.

Sets are however Iterable, so it may be more formally correct to call the set's iterator() method and use the returned Iterator's hasNext() and next() methods to access successive elements.
__________________
-- Greg
Reply With Quote
  #8  
Old 01-12-2011, 03:22 PM
Tiki's Avatar
Tiki Tiki is offline
Sage Icon
 
Join Date: Feb 2005
Location: Southwest Florida, USA
Posts: 2,009
Quote:
Originally Posted by GKusnick View Post
Sets are however Iterable, so it may be more formally correct to call the set's iterator() method and use the returned Iterator's hasNext() and next() methods to access successive elements.
It's not immediately clear to me how this would be done in Studio code. I will have to think that one over a bit.
__________________
Server: Ryzen 2400G with integrated graphics, ASRock X470 Taichi Motherboard, HDMI output to Vizio 1080p LCD, Win10-64Bit (Professional), 16GB RAM
Capture Devices (7 tuners): Colossus (x1), HDHR Prime (x2)
,USBUIRT (multi-zone)
Source:
Comcast/Xfinity X1 Cable
Primary Client: Server Other Clients: (1) HD200, (1) HD300
Retired Equipment: MediaMVP, PVR150 (x2), PVR150MCE,
HDHR, HVR-2250, HD-PVR
Reply With Quote
  #9  
Old 01-12-2011, 03:34 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by GKusnick View Post
Java Sets don't have a defined element order and don't implement the get(i) method, so I'm not sure what GetElement() would do with them. Possibly something along the lines of copying the set into a temporary array and returning the ith element of the array.

Sets are however Iterable, so it may be more formally correct to call the set's iterator() method and use the returned Iterator's hasNext() and next() methods to access successive elements.
That's a good point Greg. I tend to take that for granted since I usually always iterate over the elements.

Quote:
Originally Posted by Tiki View Post
It's not immediately clear to me how this would be done in Studio code. I will have to think that one over a bit.
Does studio have a While loop syntax? If so, you get the iterator

Iterator = java_util_Set_iterator(EntrySet)

and then you can work on the objects until hasNext() is false

while (java_util_Iterator_hasNext(Iterator)) {
Item = java_util_Iterator_next(Iterator)
}
Reply With Quote
  #10  
Old 01-12-2011, 03:51 PM
Tiki's Avatar
Tiki Tiki is offline
Sage Icon
 
Join Date: Feb 2005
Location: Southwest Florida, USA
Posts: 2,009
Quote:
Originally Posted by stuckless View Post
Does studio have a While loop syntax? If so, you get the iterator

Iterator = java_util_Set_iterator(EntrySet)

and then you can work on the objects until hasNext() is false

while (java_util_Iterator_hasNext(Iterator)) {
Item = java_util_Iterator_next(Iterator)
}
No. The only conditional is "IF".

So, I think what I need to do in Studio is:

tempVids = new_java_util_HashMap()
entrySet = java_util_Map_entrySet(tempVids)
setIterator = java_util_Map_iterator(entrySet)

IF java_util_Iterator_hasNext(Iterator)
'This is the start of the loop
TRUE
curElement = java_util_Map_next(setIterator)
myValue = java_util_Map_Entry_getValue(curElement)
myKey = java_util_Map_Entry_getKey(curElement)
IF (some conditional code)
TRUE
java_util_Map_put(tempVids, myKey, MyValue)
IF java_util_Iterator_hasNext(Iterator) 'This is the end of the loop

---
Unfortunately, this doesn't work. Studio doesn't like the line "
setIterator = java_util_Map_iterator(entrySet)"
__________________
Server: Ryzen 2400G with integrated graphics, ASRock X470 Taichi Motherboard, HDMI output to Vizio 1080p LCD, Win10-64Bit (Professional), 16GB RAM
Capture Devices (7 tuners): Colossus (x1), HDHR Prime (x2)
,USBUIRT (multi-zone)
Source:
Comcast/Xfinity X1 Cable
Primary Client: Server Other Clients: (1) HD200, (1) HD300
Retired Equipment: MediaMVP, PVR150 (x2), PVR150MCE,
HDHR, HVR-2250, HD-PVR
Reply With Quote
  #11  
Old 01-12-2011, 03:56 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by Tiki View Post
Unfortunately, this doesn't work. Studio doesn't like the line "setIterator = java_util_Map_iterator(entrySet)"
You want java_util_Set_iterator(entrySet).
__________________
-- Greg
Reply With Quote
  #12  
Old 01-12-2011, 04:00 PM
Opus4's Avatar
Opus4 Opus4 is offline
Administrator
 
Join Date: Sep 2003
Location: NJ
Posts: 19,624
Quote:
Originally Posted by Tiki View Post
The Sage API contains a method called GetMediaFilesWithImportPrefix(). It returns a map if the last parameter passed to it (GroupFolders) is TRUE, otherwise it returns a vector.

I want to iterate through this map or vector and remove any media files that reside in a specific path. I have no problem dealing with the vector, but not sure how to iterate through a map and remove the unwanted items.
You could consider filtering your list of media files first, then sending that list as the first parameter of GetMediaFilesWithImportPrefix().

- Andy
__________________
SageTV Open Source v9 is available.
- Read the SageTV FAQ. Older PDF User's Guides mostly still apply: SageTV V7.0 & SageTV Studio v7.1.
- Hauppauge remote help: 1) Basics/Extending it 2) Replace it 3) Use it w/o needing focus
- HD Extenders: A) FAQs B) URC MX-700 remote setup
Note: This is a users' forum; see the Rules. For official tech support fill out a Support Request.
Reply With Quote
  #13  
Old 01-12-2011, 04:07 PM
Tiki's Avatar
Tiki Tiki is offline
Sage Icon
 
Join Date: Feb 2005
Location: Southwest Florida, USA
Posts: 2,009
Quote:
Originally Posted by Opus4 View Post
You could consider filtering your list of media files first, then sending that list as the first parameter of GetMediaFilesWithImportPrefix().

- Andy
That's actually a really good idea. I thought that 1st parameter had to be a media mask, but I see after re-reading the API doc, that it can alternatively be an array/collection of MediaFile objects.
__________________
Server: Ryzen 2400G with integrated graphics, ASRock X470 Taichi Motherboard, HDMI output to Vizio 1080p LCD, Win10-64Bit (Professional), 16GB RAM
Capture Devices (7 tuners): Colossus (x1), HDHR Prime (x2)
,USBUIRT (multi-zone)
Source:
Comcast/Xfinity X1 Cable
Primary Client: Server Other Clients: (1) HD200, (1) HD300
Retired Equipment: MediaMVP, PVR150 (x2), PVR150MCE,
HDHR, HVR-2250, HD-PVR
Reply With Quote
  #14  
Old 01-12-2011, 04:20 PM
stuckless's Avatar
stuckless stuckless is offline
SageTVaholic
 
Join Date: Oct 2007
Location: London, Ontario, Canada
Posts: 9,713
Quote:
Originally Posted by Tiki View Post
Unfortunately, this doesn't work. Studio doesn't like the line "[/COLOR][/COLOR]setIterator = java_util_Map_iterator(entrySet)"
Unfortunately, I think the studio syntax might be a bit odd, but I think it would be
Iterator = java_util_Set_iterator(java_util_Map_entrySet(Map))

In java..
Iterator = Map.entrySet().iterator()

But I don't think there is an easier way to do that in Studio.
Reply With Quote
  #15  
Old 01-12-2011, 04:33 PM
PLUCKYHD PLUCKYHD is offline
SageTVaholic
 
Join Date: Dec 2007
Posts: 6,257
Quote:
Originally Posted by stuckless View Post
Unfortunately, I think the studio syntax might be a bit odd, but I think it would be
Iterator = java_util_Set_iterator(java_util_Map_entrySet(Map))

In java..
Iterator = Map.entrySet().iterator()

But I don't think there is an easier way to do that in Studio.
actually I think it has to be in studio

Iterator =new_java_util_Set_iterator(java_util_Map_entrySet(Map))

I think you have to have the new but can't remember man I am glad I stopped doing that stuff in studio
Reply With Quote
  #16  
Old 01-12-2011, 04:41 PM
GKusnick's Avatar
GKusnick GKusnick is offline
SageTVaholic
 
Join Date: Dec 2005
Posts: 5,083
Quote:
Originally Posted by PLUCKYHD View Post
I think you have to have the new but can't remember
No, you don't need new because you're not instantiating the Iterator class; you're calling the iterator() method, which returns an instance of that class. (Any necessary instantiation presumably happens inside the method implementation.)
__________________
-- Greg
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
UK weather maps motobarsteward SageTV United Kingdom 3 01-19-2009 03:17 PM
Weather maps (extended maps) Dean_H SageMC Custom Interface 0 11-09-2008 10:15 AM
UK Weather Maps simonk1969 SageMC Custom Interface 1 04-15-2008 01:13 AM
How about Google Maps for Sage? fizzylime SageTV Customizations 4 04-30-2005 08:08 AM
Weather maps, anyone?? RenHoek SageTV Customizations 60 10-24-2004 12:11 PM


All times are GMT -6. The time now is 06:06 PM.


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