Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Nice ignatz! I was merely shooting for a minimalist example in my OP, but this is a great demo of a more realistic application of the idea. I like the encapsulation of the core routine and the use of static Comparators to facilitate ease of use. And of course since public sort method can take any Comparator, using it in custom applications would be a breeze. The one part that concerns me is that the map that does the initial setup isn't always going to be the same (string => length), so there needs to be some way of conveying dynamic behavior for that aspect through the public sort method. Writing a general wrapper in Perl for the ST you'd probably pass a subroutine reference; in Java you'd probably have to pass an object or break the rules and pass a java.lang.reflect.Method. Hmmm, actually, that latter option probably would work:

sort(Comparator c, Method prepare) .... .... // The second map would then look something like this map(new Block() { protected Object process(Object elem) { ArrayList temp = new ArrayList(); temp.add(elem); try { temp.add(prepare.invoke(elem, null)); // or possibly with ar +gs; } catch (Exception e) { // for real we'd catch finer grained exceptions and // do something smart } }, in);

This does work, I just passed in the result of String.class.getMethod("length", null) and it ran as expected :^) Of course one limitation is the assumption that the transformation to be run on the element exists as an instance method. Probably this measure could be omitted for the first map as in basically all cases you just want to pull out the first element.


"The dead do not recognize context" -- Kai, Lexx

In reply to Re: Re: Re: (OT) The Schwartzian Transform in Java by djantzen
in thread (OT) The Schwartzian Transform in Java by djantzen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-19 21:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found