Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7905423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:28:15+00:00 2026-06-03T10:28:15+00:00

I deal a lot with the pre-generics like Maps with Strings as the keys.

  • 0

I deal a lot with the pre-generics like Maps with Strings as the keys. They are mapping the keys to one of the following types of values:

  • Another Map
  • A List
  • Primitives wrappers

You can access the collection content using either XPath or queries like that:

myMap/FIRST_LIST[2]/SECOND_LIST[1]/MY_MAP/MY_PRIMITIVE

What I am looking for is a library that would allow me to apply a visitor function to the multiple elements of a collection. The basic functionality could look like that

MyMapBrowser browser = new MyMapBrowser(myMap);
browser.applyVisitor("FIRST_LIST[*]/SECOND_LIST[*]/MY_MAP/MY_PRIMITIVE", 
  new AbstractVisitor<String>() {
    visit(String s) {
         // do something with the strings
    }
});

It would be also wonderful to have a possibility to first register multiple visitors for various levels of collection and then start the visiting iteration. It could look like this:

browser.registerVisitor(SECOND_LIST, new AbstractVisitor<MyList> { ... )
browser.doVisiting("FIRST_LIST[*]/SECOND_LIST[*]/MY_MAP/MY_PRIMITIVE");

In fact I’ve already started implementing a browser like that but I can’t get rid of an impression that I’m reinventing the wheel.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:28:17+00:00Added an answer on June 3, 2026 at 10:28 am

    Have you looked into JXPath? It lets you use XPath expressions to query and manipulate Java object graphs. The JXPathContext class lets you iterate over the values of selected nodes if you just want to extract the string values, or you can use the selectNodes method to get JDOM wrappers.

    For instance, I think your example query would look something like:

    // untested
    JXPathContext context = JXPathContext.newContext(myMap);
    Iterator iter = context.iterate("FIRST_LIST/SECOND_LIST/MY_MAP/MY_PRIMITIVE");
    while (iter.hasNext()) {
        String str = (String) iter.next();
        // do something with strings
    }
    

    Unfortunately I haven’t actually worked with JXPath (though I’ve also tried implementing an XPath-like traverser before too), but apparently you can also configure it to automatically create objects for a particular path. I didn’t see any visitor functionality, but the iterate, getValue, and setValue should be able to accomplish the same thing. You could also rig up a simple wrapper class to run the query, iterate through the nodes, and pass the values to your own visitor interface. Something like:

    public class JXPathVisitBrowser {
        private JXPathContext context;
        public JXPathVisitBrowser(Object object) {
            context = JXPathContext.newContext(object);
        }
        public <T> void applyVisitor(String query, AbstractVisitor<T> visitor) {
            Iterator iter = context.iterate(query);
            while (iter.hasNext())
                visitor.visit((T) iter.next());
        }
    }
    

    There’s a pretty detailed JXPath user guide too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My question is a lot like this one . However I'm on MySQL and
There are a lot of similar questions, but they all deal with server-side slowness
I am an ETL developer and I deal with a lot of data that
Is there any pattern how to deal with a lot of object instantiations (40k
I'm using jQuery to perform ajax callback and deal with lot of objects (over
I Have a problem... Here's the deal. I have a lot of elements and
I deal with a lot of print jobs and I'm trying to figure out
I usually have to deal with a lot of people sending me Windows files
It introduced a lot of non-closed tags like below: <div> <table>...</table> The </div> is
I need to deal with a lot of big numbers much larger than a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.