Iteration through a list of map entries

hi,
I am facing a situation in which i have to write a rule to iterate through a list of map entries within a map and again iterate for a given attribute through a map of attributes within the selected map entry.
Can anyone throw light on any function or expression in the XPRESS language in the Identity Manager to accomplish this.
thanx in advance,
yashuwyah

HI,
I cant help you out with full code at this point. But do make use of the following to determine the equivalency between GenericObject and HashMap as shown below.
Basic Operations
� map.keySet() == genObj[*].name
� map.entrySet() == genObj[*]
� map.get(attribute) == genObj.attribute
� map.get(attribute1).get(attribute2).get(employeeNumber) ==
genObj. attribute1. attribute2.employeeNumber� if attribute1 indexes a list object in the preceding example ==
genObj. attribute1[attribute2].employeeNumber� Searches
� find the object with the attribute fullname = �John Smith� ==
genObj[fullname=John Smith]� get John Smith�s employeeNumber == genObj[fullname=John
Smith].employeeNumber� List Operations
� get the names of all permanent employees ==
genObj[employeeType=permanent].nameFor your requirements, I figure that you can iterate through the list in the beginning and assign the initial result to a <defvar>. Then use the reference of this to determine the required attributes next.
IC.

Similar Messages

  • Iterate through a list containing Map items using struts

    Hi friends,
    I have a small problem. I want to iterate through a list of items, using struts.
    The list actually contains map structres for example:
    list(0)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)
    list(1)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)
    list(2)
         map(..key..value..)
         map(..key..value..)
         map(..key..value..)can I use <logic:iterate/> for this? if yes how? Because I have used this tag for list containing bean objects not Map.
    Any suggestions are much appreciated.
    Thanks,
    Vishal

    Normally, each object exposed by the iterate tag is an element of the underlying collection you are iterating over. However, if you iterate over a Map, the exposed object is of type Map.Entry that has two properties:
    key - The key under which this item is stored in the underlying Map.
    value - The value that corresponds to this key.
    So, if you wish to iterate over the values of a Hashtable, you would implement code like the following:
    <logic:iterate id="element" name="myhashtable">
    Next element is <bean:write name="element" property="value"/>
    </logic:iterate>
    Best Regards
    Maruthi

  • DriverManager iterating through driver lists, will it create an overhead ?

    Folks, i read this on a website:
    "You need a database connection to manipulate the database. In order to create the connection to the database, the DriverManager class has to know which database driver you want to use.
    It does that by iterating over the array (internally a Vector) of drivers that have registered with it and calls the acceptsURL(url) method on each driver in the array, effectively asking the driver to tell it whether or not it can handle the JDBC URL. "
    So does it mean whenever we try to create a db connection, the driver manager would iterate through the entire list of drivers which have registered ??
    In case the number of drivers registered are substantial, won't this create an overhead ?

    So does it mean whenever we try to create a db
    connection, the driver manager would iterate through
    the entire list of drivers which have registered ??
    In case the number of drivers registered are
    substantial, won't this create an overhead ?The number of drivers is never substantial.
    Problems in your code are much more likely to cause more overhead than this feature ever will. Add this one to the "don't worry about it" list.
    %

  • Iterating through a list in BPM

    hI,
    I have a element which is unbounded and i want to loop over it.I could not find any function in BPM for the same.Can you pl tell me as how to iterate over a list.
    Thanks

    Hi Mansish,
    Please find a similar discussion Select entry out of a list
    I think you need to create an EBJ function, here is a link to a help document for EBJ functions http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/609c9982-39af-2b10-768b-e5bd8813c1f3
    Best regards,
    Radost

  • Iterating through a generic list of unknown type

    Hi,
    I am in the process of creating pdf reports for my project.I have to deal with a persistence api to get the data for the report.The data will be in the form of a list,like List<SomeObject>,all these lists returned by the persistence framework contains object of some type which implements a common interface.But through that interface I wont be able to get all the data for my reports.So I am looking for a generic way for iterating through the list,by providing some metadata for the data within the list. I am planning to use reflection to query through the list.Is there any feature of generic,through which I can easily iterate through this unknown type,preferrably a combination of reflection and generics,I want to reduce the LOC.Any suggestions??

    If the List returned by the framework isn't parameterized, Like
    public List<K> getList(Class<K> classType);
    then you have to cast it to the appropriate type. If you are not sure about the type of the Objects in the list, and you have a bunch of class types you could expect from the list, then you could use instanceof operator.
    If it could be Class A or B, then
    if (obj instanceof A){
    A castObject = (A) obj;
    else if(obj instanceof B){
    B castObject = (B)obj;
    }Even to do reflection to invoke methods, you need to know the method Names. Which tells me you have the knowledge of what could come out of the list. So cast them. Invoking methods using reflection is really slow.

  • Concurrent modification exception while iterating through list

    Hi,
    I have a list of objects. I use for each loop in java to iterate through that list of objects and display them.
    The problem is that while iterating other thread can add or remove some objects from that list, and I get ConcurrentModificationException.
    How can I handle this problem. How can I be sure that I am iteration through the updated list.
    Thank you

    Synchonize on the list before iterating through it, and make sure that other code also synchronizes on the list before adding to it or removing from it. Using a list implementation that simply synchronizes all the methods (e.g. Vector) will not do that, you have to do it yourself.

  • Problem in iterating through huge number of entries ... memory issue

    I am having large number of entries in lacs.
    I need to check each entry with previous ones , so I need to iterate through the each and every entry previous to current entry.
    Here I have put all the entries in arraylist and I am iterating though this arraylist and validating current entry.
    As I am using the arraylist for storing all the entries , the system is taking lot of memory because I am putting all in the memory.
    Is there anyway to resolve this memory issue?

    If you have a hundred thousand entries, to verify all the entries you would need to compare the later entries with the earlier ones such that:
    Entry 1 = 100,000 accesses
    Entry 2 = 99,999 accesses
    Entry 5 = 99,995 accesses
    Entry 10 = 99,990 accesses
    Entry 99,990 = 10 accesses
    Entry 99,995 = 5 accesses
    Entry 99,999 = 1 access (only to be compared with the 100,000th entry)
    It would then make sense to keep a certain (fixed) amount of entries in memory, those which get accessed the most, then write to file those which get accessed the least frequently. Have a method that can decide, based on the index of the entry, whether to get it from the ArrayList or to read it from the file. That will give you good performance.
    BufferedReader would be a good candidate to read the file, because it can skip more bytes at once should you need a line very late in the file. Also consider using RandomAccessFile and seek(entryNumber * ENTRY_SIZE) if your data can be represented with a fixed size in bytes.
    s
    Edited by Looce at 2009-03-25 20:33:11 GMT [Added BufferedReader advice]

  • Modify map while iterating through it

    hi all,
    i have some java code iam maintaining and am seeing in many places that
    HashMap object's iterator is used to iterate and in the loop, the same map is modified (adding an element). is this valid coding? i didnt get any issues so far.
    Thanks.
    eg code:
    for ( Iterator iterator = myHashMap.keySet().iterator(); iterator.hasNext(); )
    //bla bla bla
    myHashMap.put(key,value);
    iam wondering since the map got modified, how reliable is the iterator used in for loop?
    -Madhu

    You should not add during iteration. If you must, you should add
    into a temporary array. When you're done with the iteration,
    you can then add everything from the array into the map.
    Or, if you quit the iteration right after adding something, that's okay. (That is, if after you add something, you no longer
    touch the iterator, then that's okay)
    Furthermore:
    First of all, you should not use keySet() since it is very inefficient.
    You're supposed to use entrySet() instead.
    Second of all, if you use entrySet(), then you CAN delete+modify during iteration (just not "add")
    for(Iterator i=map.entrySet(); i.hasNext(); ) {
       Map.Entry e = (Map.Entry)(i.next());
       Object key = e.getKey();
       Object value = e.getValue();
       // You can now remove this entry like this:
       i.remove();
       // Or you can alter the value of this entry, like this:
       e.setValue(someNewValue);
    }

  • Reuse of Map.Entry

    Hi,
    I'm writing some Map implementations and warppers and i have specific question.
    Is Map.Entry reusable after calling next iterator.next().
    Questionable code. Is this valid.
    Map.Entry first = null;
    for( Iterator i = myMap.entrySet().iterator()) {
      Map.Entry entry1 = (Map.Entry)i.next();
      if( first == null) first = entry1;
      // do something with entry
    // do something with first entry <<<<Does do something with "first" is valid operation,
    or entrySet can return the same object for each entry but with
    some different internal data.
    This is performance question, since in my Map implementation there is
    nothing similar to Map.Entry, so I must create new instance
    of wrapper for each iteration.
    I'd like to return always one instance (shared amont Iterator returned by Map.entrySet().iterator()) pointing to different "real" data.
    Thanks.

    This and many more examples, esp. with wrappers or
    or so called "views" shows weaknes of java.util contracts.I think it should be written in documentation of Map interface.It can be found in the javadocs for the Map.Entry interface:
    A map entry (key-value pair). The Map.entrySet method returns a collection-view
    of the map, whose elements are of this class. The only way to obtain a reference
    to a map entry is from the iterator of this collection-view. These Map.Entry objects
    are valid only for the duration of the iteration; more formally, the behavior of a
    map entry is undefined if the backing map has been modified after the entry was
    returned by the iterator, except through the iterator's own remove operation, or
    through the setValue operation on a map entry returned by the iterator.
    kind regards,
    Jos

  • Iterating through HashMap

    I found a tutorial and am wrote this into my code:
    for (Iterator i=m.entrySet().iterator(); i.hasNext(); ) {
    Map.Entry e = (Map.Entry) i.next();
    System.out.println(e.getKey() + ": " + e.getValue());
    Now I get the exception:
    Exception in thread "main" java.lang.ClassCastException
    on the line
    Map.Entry e = (Map.Entry) i.next();
    Is there another way to iterate through the Hashmap so I can print the keys and values?

    Results are
    java.util.Collections$UnmodifiableMap
    java.lang.Integer
    I used keySet and my Keys are Integers
    Maybe I should have used entrySet
    When I use entrySet I get:
    java.util.Collections$UnmodifiableMap
    java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
    java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
    java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
    java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
    java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
    java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
    java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
    java.util.Collections$UnmodifiableMap$UnmodifiableEntrySet$UnmodifiableEntry
    Exception in thread "main" java.util.NoSuchElementException
    at java.util.HashMap$HashIterator.nextEntry(HashMap.java:765)
    at java.util.HashMap$EntryIterator.next(HashMap.java:804)
    at java.util.Collections$3.next(Collections.java:1324)

  • Iterating through a HashMap

    Hi!
    I am trying to iterate through a HashMap that stores the 2 length words as keys and their number of occurrence in the given text. What I want to do is to count the total number of 2letter words which starts with the same letter. Unfortunately I could not find the code that will compare the 2 adjacent keys. I can take the next entry with Map.Entry meNext = (Map.Entry)iter.next(); but I cannot take the current entry with Map.Entry me = (Map.Entry)iter;. Or the next next entry.
    I hope I am clear. I would be really glad for your advices. Below is my code, which gives error:
    java.lang.ClassCastException: java.util.HashMap$EntryIterator cannot be cast to java.util.Map$Entry
    Iterator iter=symbols.entrySet().iterator();
              while (iter.hasNext()) {
                   Map.Entry me = (Map.Entry)iter;
                   Map.Entry meNext = (Map.Entry)iter.next();
                   String valueToString = (me.getValue()).toString();
                   String valueToStringNext = (meNext.getValue()).toString();
                   String keyToString = (me.getKey()).toString();
                   String keyToStringNext = (meNext.getKey()).toString();
                   int numberOfElements = (int)Integer.valueOf(valueToString).intValue();
                   while (keyToString.substring(0,1).equals(keyToStringNext.substring(0, 1))) {
                              numberOfElements += (int)Integer.valueOf(valueToStringNext).intValue();
              }

    thanks a lot for your answer yawmark, but I think I really need to take and compare the 2 adjacent key entries of the hashmap. because later on if the userchoice=2gram, I want to calculate the probability of the 2nd char given the first char. i.e. Prob(b when given a)=numberof(ab) / numberof(words starting with a), otherwise it calculates the probability of the word. i.e. Prob(ab) = numberof(ab) / numberof(all words in the document)
    so length in the code = number of all words in the doc.
    I have my hashmap in sorted, so all the words starting with the same letter will be next to each other. So it can count until it sees another starting letter in the next word.
    The output should be the contents of the probability hashmap, which contains <entries of symbols hashmap which are <words,occurances>, probability of the words>
    for ex. (in this ex it just calculates the probability = occurance/numberof all words.
    &#12362;&#12452;=2=0.5
    &#12452;&#12403;=1=0.25
    &#12403;&#12362;=1=0.25
    for the document: &#12362;&#12452;&#12403;&#12362;&#12452;
              Iterator iter=symbols.entrySet().iterator();
              while (iter.hasNext()) {
                   Map.Entry me = (Map.Entry)iter;
                   Map.Entry me = (Map.Entry)iter.next();
                   String valueToString = (me.getValue()).toString();
                   String valueToStringNext = (meNext.getValue()).toString();
                   String keyToString = (me.getKey()).toString();
                   String keyToStringNext = (meNext.getKey()).toString();
                   int numberOfElements = (int)Integer.valueOf(valueToString).intValue();
                   while (keyToString.substring(0,1).equals(keyToStringNext.substring(0,1))) {
                              numberOfElements += (int)Integer.valueOf(valueToStringNext).intValue();
                   if(userChoice.equals("2gram")) {
                        probability.put(me, ((double)Double.valueOf(valueToString).doubleValue()) / numberOfElements);
                   else
                   probability.put(me, ((double)Double.valueOf(valueToString).doubleValue()) / length);
              }Edited by: koksalasli on Dec 21, 2009 3:06 PM

  • Any performance overhead if we get iterator over values stored in map

    Hi Everybody,
    Is there any performance overhead if we get iterator over values stored in map. like this
    Iterator itr = rolesMap.values().iterator();
    if yes please explain...thanks in advance.

    ejp wrote:
    That's rather out of date. It is how Hashtable works, but as regards HashMap it isn't. The keySet() iterator and the values() iterator are both written in terms of the entrySet() iterator. There is no skipping over unused slots.Out of date? In that case there's been a recent advance in hashed data structures I've missed.
    Or the HashMap implementation has been recently changed to internally link entries to improve iteration performance. I doubt that because such a list would degrade the performance of the HashMap in other ways and that's unacceptable (and unnecessary because of LinkedHashMap).
    Besides, what I said is in the Java 6 API documentation to LinkedHashMap. It may be out of date but I doubt it.
    So here we are with a fact of nature: Any iteration of a hash based data structure will be proportional to capacity rather than the number of entries, unless a supportive list style data structure is introduced to overcome this.

  • Iterating through entrys of HashMap

    I have a HashMap that is already populated. I'm iterating through the entrySet and want to get the keys and values and use them to create another object. I've searched the forum and googled but can't quite seem to find what I need. Here's the code I have so far.
    Iterator iterator = map.entrySet().iterator();
    while (iterator.hasNext()) {
    if (iterator.next() != null) {
         reasonsList.add(new DropDownData(key, value)); // here's where I'm not sure what to do
    }The DropDownData object accepts twos strings, one for the key and one for the displayed value. These strings should be the key and value from my current HashMap entry. But I can't seem to figure out how to do it.
    thanks for any help/suggestions

    iterating over the not-null entries or iteratingover
    gotten entries that are not null is equivalent,maps
    return "null" for unexisting keys...
    I do not understand what you are saying here.
    It is not required that Map implementations return "null" for non-existent keys.
    It just happens to be the way the implementations in the JDK are implemented.
    The documentation specifically says that Map.get(key) could be allowed to throw a NullPointerException.
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Map.html#get(java.lang.Object )
    >
    I would add that map's structure suggests it's the
    way to go (I mean, mine of course ;))
    That's a matter of interpretation.
    what's the point in iterating over the values when
    you need the key ?When you need the keys and the values (as in the case of the OP), then there is plenty of point in it.
    >
    the only way (the API should define) to iterate over
    a map is through the key (hence the "map" name),
    entrySet is (as far as a I reckon) a twisted bypass...It's in the API. It works well. It's useful. So there's no reason not to use it when it is applicable.

  • ClassCastException for Map.Entry

    Hi
    I am storing id, name from the resultset in a Map. On the Jsp page i am trying to get these values and store it in a drop down list. But during that process i get a CLASSCAST EXCEPTION
    I did tried looking in the forum but nothing seems to work or maybe i am missing something
    heres the code if this would help
    <%
    Map fileTypes = new LinkedHashMap();
    fileTypes = getResultsetData(connection);
    %>
    [HTML CODE]
    <% Iterator keyIter = fileTypesMap.keySet().iterator();
    while (keyIter.hasNext())
    Map.Entry currentEntry = (Map.Entry)(keyIter.next()); // CLASSCAST EXCPETION
    %>
    <option value="<%=currentEntry.getKey()%>"><%=currentEntry.getValue%></option>
    <% } %>
    [/HTML CODE]Any help is appreciated .........please
    Thanking you

    Iterator keyIter = fileTypesMap.keySet().iterator();should be
    Iterator keyIter = fileTypes.entrySet().iterator();

  • What is the diffrence between  map and map.entry in core java

    what is the diffrence between map and map.entry in core java . where it will be use ful. any one give one example plz.

    A Map contains Map.Entry's
    e.g.
            Map map = new LinkedHashMap(8);
            map.put(new Integer(1), "one");
            map.put(new Integer(2), "two");
            final Iterator iterator = map.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry entry = (Map.Entry) iterator.next();
                System.out.println("key=" + entry.getKey() + ", value=" + entry.getValue());
            }

Maybe you are looking for

  • 60i footage into 24p sequence

    Hi, I have 60i footage that I want to import into a 24p sequence. The scene was filmed in 60i specifically because I want to slow it down 50% in my premiere sequence and the 24p does not allow for good slow motion. My concerns are how to do it, and h

  • How can i watch all movies in english with a spanish account?

    I want to see the films in english in my spanish account because i live in spain. but i can only see little movies in english. i what to know if there is any option so that i can see all movies in english.

  • Song files missing in 7.0 and blank ipod

    I updayed my itunes to 7.0, and after it 'updated' my ipod i can no longer access mot of the songs in my library, which have an '!' next to them and the computer says it cannot find the file for the song, and my ipod no longer has any music on it wha

  • Yahoo sign in

    I am using safari via my windows computer, and I use yahoo emailing and on yahoo they have this thing where I can instant message people via the email itself through the internet web browser window, well...safari doesnt allow it because its not compa

  • Thinking of getting a playbook!

    Hi I am thinking of getting a playbook but have a few basic questions: Can you link or bridge more than 1 bb phone to it? Can you watch 'sky go' and download sky go movies/programmes on to it? Can you use skype on it? And what is the battery life tim