API design style I've never seen before - would you use it?

I was Googling for examples of a "Bean Comparator" and came across this strange API design I've never seen before (is it just me?). I'm curious if you have seen it before and what you think about it?
[http://cojen.sourceforge.net/apidocs/org/cojen/util/BeanComparator.html]
The basic problem is to create a Comparator that can sort on multiple fields within a given class.
First, a more traditional(?) API design might be something like:
Constructor Summary:
     BeanComparator(Class theClass);
Method Summary:
     addSortField(String fieldName, boolean isAscending, boolean isSortNullHigh);
     addSortField(String fieldName); // convenience method with default ascending and sortNullHigh
So you could create a BeanComparator that sorts on multiple fields by using:
BeanComparator bc = new BeanComparator(SomeClass.class);
bc.addSortField("field1");
bc.addSortField("field2", false, true);
bc.addSortField("field3", true, false);Finally, without listing the API, the equivalent code for the "strange API design" would be:
Comparator c = BeanComparator.forClass(SomeClass.class)
     .orderBy("field1")
     .orderBy("field2")
     .reverse();
     .orderBy("field3")
     .nullLow();So in this case:
a) there is no explicit "add" method to add a new sort field. The "orderBy" is an implicit add.
b) the reverse() and nullLow() methods only apply to the current orderBy field.
c) the creation of the class is "sequential" in nature as each method needs to be invoked in the proper order
In some ways this seems to simplify the API because you don't need lots of convenience methods or your don't need to use the full method and then restate the default values.
Also you can add new sort options to the API without affecting any existing methods.
What do you think of this type of API design?
Have you ever used it before?
Would you consider using this design and in what situations would you consider it?

What part is bothering you exactly? Its not that it bothers me, its just that it is "different" and I was wondering if it is an acceptable design of a class and when you would use it, since I don't think I've seen any examples in the JDK.
Usually the order of method invocation is not important. You can do:
component.setFont()
component.setBackground()or
component.setBackground()
component.setFont()However
orderBy()
orderBy()
reverse()is not the same as
orderBy()
reverse()
orderBy()So the API implies a "building" approach where you need to know you are building the components of the class in a certain order.
Again, its not bad, its just different (to me) so I was wondering if it is common and when you would use it.
The fact that the methods return the object itself...No, I've seen that pattern before and find it handy.
Your example (addSortField) also depends on the order in which the methods are called.Yes, but this is normal for most APIs. For example adding items to a Vector, or components to a panel.
In this case the orderBy() method implies a change of state because the next set of methods may or may not modify the state of the field being ordered.
Again, I said I thought that this potentialy does simplify the API, but I have not seen it used before.
I don't see the design as much of a problem. Me either.

Similar Messages

  • HT201401 My iphone 4s turned off properly but when I went to put it back the apple icon came on and then an image I have never seen before of a ubs pointiing towards the word itunes in a circle.  And the phone no longer goes beyond this message.  meltdown

    My phone started acting up and I noticed my text messages were not being sent.  So I turned my iphone off.  My iphone 4s turned off properly but when I went to put it back the apple icon came on and then an image I have never seen before of a UBS pointiing towards the word itunes in a circle.  And the phone no longer goes beyond this message.  I try to turn it off and on again and same message over and over.  If I hit the any button on the phone nothing happens. Does anyone know what this means or seen this itunes messaging ?  meltdown? Please help.

    Hello Raja,
    Thank you so much for your response.  I had these photos backed up on iCloud but, had I not, its good to have an alternate solution as the one you suggested.  Actually, I went to the Apple store today and yes, you are absolutely correct Restoring in iTunes will result in permanent loss of photos unless backed up somewhere such as iCloud or other solution.  Well, what they did was restore the phone in itunes ( I did not have iTunes downloaded to my computer which is why it did not work when I went to do it myself, I needed to go to the iTunes site and go to the download iTunes button because my windows based HP laptop does not come with itunes already downloaded).  This retoration process took a while and I was forced to upgrade to the latest 7.1 iOS software which I was not too happy about -sometimes you like the way things work now :-)  Anyhow, they said this restoration request happens as a result of a software update (which I was NOT in progress of an update or doing an update) or sometimes when you remove the power cable too quickly from the iphone (which I do not recall doing this either but...). Since I had backed up on iCloud all of the photos were downloaded back on my iphone 4s.  Best of all was that my phone was back up and runnning and there was NO CHARGE at the apple store for this service of restoring my phone.  Well, I just wanted to share the results and I appreciate all the responses and support I received.  Thank you kindly.

  • Netctl connects to access points I've never seen before

    On my laptop using netcl and auto switching profiles as described in https://wiki.archlinux.org/index.php/Netctl.
    Recently, and more than once, I'm connected at a public cafe and I'm suddenly no longer able to reach the internet.
    When I investigate, I find that I'm no longer connected to the cafe's wifi, but I am connected to some other essid that I've never seen before.  This is disconcerting for possible security reasons but also annoying to get disconnected in the middle of whatever I'm doing.
    The essids that my box connects to I've never seen before.  (I'm assuming the come from nearby computers.)  There is no corresponding profile in /etc/netctl.
    To work around the problem, I run
    sudo systemctl stop [email protected]; sudo wifi-menu
    then reconnect to the access point I was originally connected to.
      I really don't want netctl-auto to change a connection that is working.  How can I prevent this from ever happening?

    That file has a long list of every wireless router I've connected to!  I didn't know that was there.  It duplicates a lot of information thats in /etc/netctl/...   It has passwords, too.  I'm not going to post it here.
    But I don't see the mysterious routers in that file.  The ones I find myself connected to, that I never connected to myself.
    ... Looking over that file again, I see a strange entry:
    network={
    key_mgmt=NONE
    ssid=""
    id_str="wlp3s0-none"
    I'm going to delete that.  I believe it comes from a time I connected to an essid without a name.  But I'm not sure if that's the culprit.
    Last edited by Dave Cohen (2014-02-14 17:03:32)

  • I cant update my mac twitter app because it says i bought it with an apple id that i have never seen before. How do i update it?

    I cant update my mac twitter app because it says i bought it with an apple id that i have never seen before. How do i update it?

    Hi,
    Your best bet at this point then is to contact iTunes Support and get them to straighten this out for you:
    https://expresslane.apple.com/Issues.action
    Select the options that best apply to your issue. You will have a chance to provide a written description before you submit. iTunes Support will get back to you via email, usually within 24 hours. Be sure to check your Junk/Spam email folder if you don't hear back by then.
    They should be able to sort it out for you...
    Good luck!
    Cheers,
    GB

  • I have os x 10.5.8 and noticed a menu extra that I have never seen before. Is there a way to identify it? I tried to delete it i.e. comm drag, didn't work.

    I have os x 10.5.8 and noticed a menu extra that I have never seen before. Is there a way to identify it? I tried to delete it i.e. comm + drag, didn't work.

    If you can't CMD+ drag it off, try this...
    You've probably got a couple of corrupt preference files.
    Safe Boot from the HD, (holding Shift key down at bootup), run Disk Utility in Applications>Utilities, then highlight your drive, click on Repair Permissions...
    /Users/YourUserName/Library/Preferences/com.apple.systempreferences.plist
    /Users/<yourname>/Library/Preferences/ com.apple.systemuiserver.plist
    /Users/<yourname>/Library/Preferences/ByHost/com.apple.systemuiserver.xxx.plist
    where 'xxx' is a 12 digit (hexadecimal) numeric string.
    This will reset your Menu Bar to the default, you'll need to go through System Preferences to reset the ones you need. (If they are already checked, uncheck them first and then recheck them).
    reboot

  • HT5577 why i have some security question that i never seen before?

    I tried to change my password on apple id and i got some security questions that i never seen before..what can i do in this case?please help me

    Welcome to the Apple Community Helen.
    If you don't know your password, don't know your security questions and don't have a rescue address or don't receive a reset email, you should contact AppleCare who will initially try to assist you with a reset email or if unsuccessful will pass you to the security team to reset your security questions for you.
    If you are in a region that doesn't have international telephone support try contacting Apple through iTunes Store Support.

  • Never seen before interface while cleaning screen in lock mode

    Never seen before interface while cleaning screen in lock mode came up looking like player with some weird buttons.

    Go into iPod and play a song. While it's playing, click the standby button to lock/standby your phone and again to wake it (locked), then press the menu button twice. (This should also work if you play a song, press menu once to return to the main menu, then click menu twice. If not, there's a setting to turn it on.)

  • There is a dialog box on my screen that I've never seen before. I can't get it to disappear. Any ideas?

    My Macbook has a dialog box on the screen that indicates everything I do. Right now it says "Standard toolbar". When I try to get rid of it nothing happens. I've never seen this before and don't know ho to get rid of it.

    This seems to be more common than I thought. Premanent solution is to trade the cat in on a dog.
    https://discussions.apple.com/search.jspa?peopleEnabled=true&userID=&containerTy pe=&container=&spotlight=false&q=cat+on+keyboard

  • Please help ID a screen I've never seen before

    OK, I'm working along this morning on effects in my Viewer. At some point I looked over at my Canvas and there is a frame from my project with the clip name overlayed at the top and the timecode overlayed on the bottom. Now, this is not the standard Time Code Overlay screen we see in under the Show Overlays pull down. This has the clip name at the top of the frame and the timecode was a single line in a bigger than usual type face. This was not the clip I was working on in the Viewer and the moment I clicked out of Viewer the screen disappeared, replaced by the frame on which my playhead rested. I've never seen the screen before. Have you?
    Peter

    petemay wrote:
    Interesting. That would explain why, though I'm doing a video on tax evasion, everyone looked extraordinarily happy. Next time I'm going to try leaning into the screen rather than clicking away.
    Pete
    What's interesting, Pete, is that you've got the courage and humor to roll with us. Most others would get really upset and start screaming for the mods (whoever they are) to have the jovial persecuted to the full extent of the TOS.
    Can't say that I've ever seen this oddball screen of yours. Hope you see it again someday.
    bogiesan

  • Safari did something I've never seen before

    This is regarding my bookmarks.
    I went to click on a bookmark and my bookmark got deleted and there was this little dust cloud animation when I clicked.
    Nothing bad happened. I just had to go make another bookmark but I have never seen this happen before and I don't know how it happened or what I did.
    Does anyone know what this is?
    Message was edited by: thebonapartey
    Message was edited by: thebonapartey

    I clicked directly on the bookmark but I realized that if you drag a bookmark off the bookmarks bar it gets deleted and there is a dust cloud animation. I must of dragged it off and didn't know it. I seriously realized this about 1 minute after I posted my question. No big deal.
    Message was edited by: thebonapartey

  • G4 Blackout-Something I've never seen before; could be end of the machine

    I have a Powerbook G4 that I use to run ProTools. Not the best machine for the job but it's served the gig well over the last year. The one thing was that it had always run kinda slow even on mundane tasks.
    Since last weekend I've been trying to get it to run a little more smoothly.
    I cleared out the hard drive, ran Disk Utility, Disk Warrior, checked Console Logs, etc etc etc.
    After some research, I did an erase and install. I finished it up this morning. The thing ran like a dream. Restarts in well under a minute, fast operation, fast shutdown: just like a Mac should be.
    Then I was back in ProTools, and the thing did something I have never seen a Mac do, ever.
    I got a warning screen that ProTools was running out of CPU and that I should increase the Playback Engine settings, and then, before I could click out of the Alert message, the screen went black. The Hard Drives went down, and now the little rectangular white/blue light at the bottom of the monitor is calmly dim-flashing. Like HAL. I can't manually restart the thing. I can't shut it off. It won't respond to anything.
    It doesn't look good.
    Has anyone seen this before? Is there any way to bring the thing back?

    Hi there.
    I'm not familiar with ProTools per se, but in general if a mac laptop is frozen like that, I pretty well always start with:
    1) Take the external battery out. 2) Pull the plug out from the back of the laptop. (this will force it to shut down) 3) Press the power button for a few seconds (to completely discharge any power). 4) Let it sit there and think about what it's done for around thirty minutes (or sometimes longer). 5) Plug the ac adaptor back in; Press power; Then the "zap the pram" thing (apple key + option key + p + r) as it starts up (make it do the startup "bong" for 3 - 5 times; Then let it complete it's normal startup.
    Then see where you're at...
    In general, I find that OS X is happiest when it has at least 5gbs free of hard drive space to play with - Protools may require it to have even more free so it can do it's thing. Are you sure you didn't accidentally remove a file Protools needs during your own "cleanup"? Also, after I run Diskwarrior on an os x drive, I always then run Disk Utility to repair permissions afterward - Diskwarrior is a great fixing tool, but some of it's ideas on what the operating system really needs aren't quite what the mac os x directory doc has ordered.

  • Macbook pro i7 experienced a hard freeze while I was using Traktor with it. Never seen before dialog box says to shut down using on/off button.

    My Macbook Pro i7 dual core had a hard freeze halfway through my DJ set. At that moment, I had 'mixedinkey' opened on another page but it was not processing any files. The Traktor interface just froze for about 1-2 minutes with the usual rainbow ball spinning and I could not manouvre to another page. Suddenly, the music stop and an error dialog box which I have seen before appeared and say to shut down my Macbook using the on/off button. I did what was said, off the Macbook and on it again and it behaved normal after that. I also did a 'repair disk' with disk utility after that. Now, I am kind of worried it will happen again in the midst of my DJ sets because it is going to be embarassing. Does anybody out there know what actually happened? Is it my hard disk or is it a one time off thingy...any thoughts will be a great help.

    My Macbook Pro i7 dual core had a hard freeze halfway through my DJ set. At that moment, I had 'mixedinkey' opened on another page but it was not processing any files. The Traktor interface just froze for about 1-2 minutes with the usual rainbow ball spinning and I could not manouvre to another page. Suddenly, the music stop and an error dialog box which I have seen before appeared and say to shut down my Macbook using the on/off button. I did what was said, off the Macbook and on it again and it behaved normal after that. I also did a 'repair disk' with disk utility after that. Now, I am kind of worried it will happen again in the midst of my DJ sets because it is going to be embarassing. Does anybody out there know what actually happened? Is it my hard disk or is it a one time off thingy...any thoughts will be a great help.

  • Driver I Have Never Seen Before

    I just re-installed win 7 pro. But for some unknown reason I have a drive "F" that I never had before. It tells me that it has "Data" on it. But when I open the drive it's empty. I'm running RAID for my "C" drive, and my "D"
    drive is data. I have no idea what this "F" drive is. How do I delete it, or remove it??? Suggestions??
    Thank You.

    Open Computer Management by clicking the Start button ,
    clicking Control Panel, clicking System
    and Security, clicking Administrative Tools, and then double-clicking Computer
    Management.  If you're
    prompted for an administrator password or confirmation, type the password or provide confirmation.
    In the left pane, under Storage, click Disk
    Management.
    Arnav Sharma | http://arnavsharma.net/ Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading
    the thread.

  • Ridiculous amount of problems, and something I've never seen before.

    I had gotten a 4th gen 20gb iPod for a Christmas gift in 2004. It had a few problems here and there, but worked well for the most part for the better part of a year.
    Right around the time the one-year warranty was going to expire, it started really acting up. I sent it in, and got a replacement. Well, its been right around four months since I got the 'new' one, and I've had so much trouble with it, I've nearly thrown it out.
    I've been reading up on these forums for a couple days, and trying everything I could with no success.
    The main reason I'm starting this topic is in hopes for an answer on my iPod's capacity.
    So we're all aware that the 20gb's are really only 18.5 gb's. That's no secret. What really blew my mind was, just a week or so ago, I was having a ton of trouble with my iPod, and when I finally got it to respond, and it connected with iTunes, the maximum capacity was showing 16.4 gb. It was completely empty of anything I would have put on it, so I was extremely confused, and fairly upset.
    Well, not even ten minutes ago I went through the same sanity-reducing behavior, and when things finally connected, iTunes was showing that the iPod's maximum capacity is now at 15.98 gb!!!
    I don't know what to do, I've tried literally everything I've seen suggested in these forums that I can do aside from sending it in for repair.
    If the "true video" iPod doesn't come out in the next couple months I think I might switch to an iRiver. I don't really want to do that, because I have faith in Apple, but the problems I've had are ridiculous.
    Sorry for ranting, and thanks for reading.

    Sorry to butt in... Two thoughts for you.
    1) Are you resetting the iPod while it is still attached to the comp? If so try resetting it when it is not attached and leave it to "settle" for a minute (or so) before you attempt to reconnect. Make sure that the iPod is fully charged (or very nearly fully charged) before connecting since sometimes the current drain to start the iPod's internal HDD and keep it spinning to synch with iTunes is more than the USB port can support.
    2) I've seen the iPod "lie" about how much space is available - it's happened to me! It's not ideal, but my advice is to accept the iPod lies about how much space is available and ignore it unless you experience other symptoms which suggest that it really is inexplicably short of space (e.g. iTunes indicates that it is full, Windows thinks that it is full and you know that it should not be). You can also try running chkdsk on the drive letter windows has allocated to the iPod - it should detect any problems in the filesystem on the iPod which could lead to it getting confused about how much space is available. These "lies" about availble space can come and go (in my experience) - with no apparent reason or at least any that I've so far identified.
    Hope that helps.

  • Changing colors brings up a new dialog I've never seen before...

    Hi,
    I think I broke my Photoshop CS4.
    For some reason, when I try to change colors anywhere (it could be the color of text, or the main foreground color) a dialog with swatches appears instead of the eyedropper tool I'm used to using in this scenario. I can't click on anything else in the screen except the options in this annoying swatches dialog.
    It looks like this :
    This is extremely annoying and frustrating, as this dialog won't tell me what the hexadecimal color values are (even when I click "Define Custom Colors").
    As of right now, the project I was working on is stalled until I figure out how to make this thing go away and let me use the eyedropper tool to change the color of something.
    This problem is new. I had my CS4 running since it came out and it never did this before.
    Thanks for any help you can provide!

    Edit>Preferences>General Change the color picker from Windows to Adobe.

Maybe you are looking for

  • Unable to create content properly in UCM 11G using validateStandard filter

    Hi All,     We have used validateStandard filter to assign content id with 16 digits in UCM 10G and it worked well, we deployed this component in UCM 11G but it is not working properly. When we click on Check In button content is getting created and

  • Looking to transfer photos from several iphoto 6 sources to new iphoto

    Hey all, So I just got a new macbook pro. i want to transfer all my previous photos to my new iphoto. heres the thing i have prob 3-4000 pics that are saved in 4 seperate places (all by simply copying/ backing up the Iphoto Library folder) I have: 1

  • How can I get help with this?

    Hi There I am posting this here as my fiancé is pulling her hair out over Verizon's customer service (or lack of it). I'm from the UK, my fiancé came to visit me from Florida. Originally for 3 weeks then decided to stay for 6 months. I advised her to

  • Oracle 10g crashes Windows 2003 server (bluescreen)

    Hello, i have a problem that Oracle 10G crashes my Windows 2003 Server. All components are up-to-date and it is a certified system setup. The database worked well for months, but three days ago when our staff went to a workshop, I shut down the machi

  • I don't see an itunes store menu on new version of itunes

    So itunes won't let me rent a movie because it says I haven't authorized my computer. It says to do so I have to go to the store menu, and hit "authorize" but I don't see the store menu anywhere on this new version of itunes.  Please Help.