The behavior of comparator

Hi
How do the following codes produce different results? (Both are part of a Comparator implementation)
public final int compare ( Object a, Object b )
            return( (Comparable)a ).compareTo( b );
public final int compare ( Object a, Object b )
      // reverse the usual roles of a and b
      return( (Comparable)b ).compareTo( a );
   }Actually how do the caller of the comparator method utilize the return value?
I mean say the list is {5,4,....}
so a = 5, b = 4
In the first case, a<b so the return value is negative. and for the second case b>a so the return value is positive.
If the caller wants to put negative values first and positive values next, then in both cases a should come before b. No where in the comparator I have mentioned that In the first case I want to put negative values first and in the second case positive values first.
So please somebody clarify the things.

amishera2006 wrote:
Actually how do the caller of the comparator method utilize the return value? When you're using Comparable, try to think of compareTo as determining whether something is absolutely greater or less than something else, NOT whether it is before or after something else. Typically, when you use Comparable, it's because two things can be compared in such a way. For instance, it's natural to say that a date in the year 1900 happened before a date in the year 2000. Dates have a natural ordering. It wouldn't be natural to say that two cars have an intrinsic, deferential and natural ordering, so implementing Comparable for a class "Car" wouldn't make much sense.
When you see this, you also see that compareTo should return the same thing, no matter if you are trying to sort forward or in reverse. According to the Javadoc, compareTo() "Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object" -- not depending on how you choose to sort your objects.
To sort backwards you'd just create a Comparator like in your second example.

Similar Messages

  • How do i configure a FOR loop to have the behavior of the step Loop Type: Pass/Fail count?

    Hello,
    I'm using the Pass/Fail count set to one Pass to capture an event generated by my DUT.  I originally used a numerical compare step with the Looping type of Pass/Fail count to accomplish this.  Unfortunately the implementation changed and now I need to execute a few steps that can not be combined within one code module as before. Nor can these steps be put into a subroutine.  One of the steps executes a .NET asembly and I haven't figured out how to pass the reference to the subroutine.  When the subroutine is intered the reference is lost and the methode does not execute correctly.
    I have an evaluation function the exits the loop when the expected conditions are met. Everything works except for the Overall Pass/Fail result of the For loop.  If the loop exits due to the first numerical compare test passing, I want the loop overall execution to report as "Passed".  If the loop reaches it's predetermined number of iterations, the overall result needs to report as "Failed".  It would also be nice to have the radio button functionality of "Record Result of Each iteration".  Some conditions require a wait over a minute for the event to occur and I don't want to generate needless data for the report.
    Currently I get the pass/fail status for each For loop iteration, but only "Done" for each loop iteration.  I don't want the initial few failures to cause the test to fail.
    Does anyone know how to do this? Suggestions?
    Thanks,

    I have 2 steps in the loop that can not be combined into one step. This forces me to implement the behavior in some form of loop.  A While Loop could be an option.  I would need to pass the Step.Result.Status from the Multiple Numerical compaire step to the condition of the While Loop.  I tried to use the Step.TS.ID without success.  Some form of reference to the numerical compare step would be needed. I'm using a For Loop as I do want to limit the number of iterations of the loop.  In the case where the loop iterations are reached, the event I am trying to detect did not occur at the correct time and a failure needs to be reported.
    I came up with something based on my comments in the second post:
    1) To start with I configured a Locals.ForLoop_5 variable.  This is used to set the limit on the loop iterations and for comparison after the loop has finished executing. More on that later.
    2) The first step inside the loop invokes a method within a .NET assembly that has been packed in a DLL This method gets the required data from the DUT and stores it to a text file.
    3) The next step is the Multiple Numeric Limit step.  This step invokes a VI that extracts the data from the text file.  This step has been customized in several ways.
      i)  In Run Options, the Results Recording Option was disabled.  This prevents recording of "Failed" while the loop executes when waiting for the event to happen.
      ii) In Run Options, the Step Failure Causes Sequence Failure is unchecked.  Same reasoning as i)  These steps are not true failures.
      iii) A Post Action is configured to go to the nexxt step after the For Loop End step On Condition True with the logic of Step.Result.Status == "Passed".  This causes the loop to exit when the first "Passed" is encountered which corrolates with the event I'm trying to detect. On Conditon Fail remains set to default.
    4)  The step after the For Loop End is an expression step with everythin set to default except for the Status Expression logic set to: Locals.Loopindex < Locals.ForLoop_5 ? (Step.Result.Status = "Passed") : (Step.Result.Status = "Failed"). This step performs the overall Pass/Fail reporting for the For Loop.  If the number of loop iterations is less than the maximum it could have only gotten there by the previous logic triggered by the numerical compare passing, therefore "Passed".  If the loop index has reached the limit, then the event was not detected, therefore Failed.
    I have tested this work around with success, it just a pain to now have to implement this on my 40 some odd For Loops.
    If there is a better way, I'd still like to hear it.

  • Create Archive, how to change the behavior of the default file naming?

    From an earlier post on archiving via the contextual menu in the Mac OS X Finder:
    "If you archive a single item, the archived file has the name of the original item with a ".zip" extension. If you archive multiple items at once, the archived file is called Archive.zip."
    Is there a way to change the behavior of this?
    I ask because I want to archive a single file, say "photo.psd" and when I do I get an archive called "photo.psd.zip" - is there a way to create an archive from the contextual menu and have the original file extension be appended? - in this case I would want "photo.zip" to be the end result.
    Also, is there a way to change the behavior of archiving multiple files? To, say, create a differently named file afterwards instead of the default "Archive.zip" - perhaps something a little more descriptive but standard, like "YourFilesCompressed.zip" - something that would stay the same across each archive creation.
    Thanks, I've been manually renaming after all create-archive's. And I do realize other applications could probably do this, but I'm thinking there must be a way to do this in the finder, no? A terminal command? Any ideas would be appreciated.

    Try looking at the documentation for the ditto and zip Terminal commands.
    (14504)

  • Line breaks in the "Behavioral Indicator" field that appears in Appraisals.

    Hi,
    While defining Competencies. We can specify the "Behavioral Indicator". This appears on the appraisal screen (since the competency template is attached to it.).
    E.g. for our competence called "Attendance/ Punctuality" , the following behavioural indicator has been defined.
    1: Often late and / or absent with plausible excuses.
    2: Usually punctual, but needs to improve on timekeeping.
    When this appear on the appraisal page. (OAF page), it appears in a paragraph as
    1: Often late and / or absent with plausible excuses. chr(10) 2: Usually punctual, but needs to improve on timekeeping.
    How can I make it appear as seperate lines in the OAF page.
    i.e. 1: Often late and / or absent with plausible excuses.
    2. Usually punctual
    I tried the option of introducing chr(10) as well as /<br> in between those lines but both of them did not work.
    I also tried applying the patch as per the metalink note Doc ID 465600.1 but still the problem exists.
    Can anybody suggest some way as to how to resolve this issue.
    regards
    Edited by: Maya on Nov 26, 2012 4:08 AM

    No, there is no yellow star on any of the entries. Each entry has the site's (or company's) logo, as well as the name of the site and URL. There is nothing more in each entry.

  • What is the behavior of items in an Exchange Online Inactive mailbox that were under a Litigation Hold for a set period of time.

    I am specifically asking what happens to the items in an Inactive Mailbox that was placed on Litigation Hold prior to Deletion when the Litigation Hold has say a '6 mo.' Retention Period assigned.
    Do any of those items 'expire' out of the mailbox?  Do only the items in the 'Admin' folders of the Deleted Items get removed, or none?
    I am not asking about recoverability of that mailbox, more of what the behavior is specifically when the Litigation Hold is set to expire after a certain amount of time.

    There is no expiration, check the blog post here:
    http://blogs.technet.com/b/exchange/archive/2013/03/21/preserve-mailbox-data-for-ediscovery-using-inactive-mailboxes-in-exchange-online.aspx
    All content in an inactive mailbox is on hold until you remove the hold from the mailbox.

  • The answer helped me.But still, what are the settings that I have to change for the behavior of the mouse pointer towards finder? Also the mouse pointer sometimes  doesn't accept my command and start clicking itself.what is the problem and how to fix it?

    The answer helped me.But still, what are the settings that I have to change for the behavior of the mouse pointer towards finder? Also the mouse pointer sometimes  doesn't accept my command and start clicking itself.what is the problem and how to fix it?

    If the mouse clicks something on its own then it looks like you have a hardware problem with the trackpad or possibly the battery that is right underneath the trackpad.
    I have read that the battery can swell and that would put pressure on the trackpad.

  • KB2993651 and KB2982791 alter the behavior of SaveDC and RestoreDC

    I posted this problem on answers.microsoft.com/en-us/windows/forum/windows_7-hardware
    They directed me to this place to post this problem.
    After applying KB2993651 or KB2982791 the behavior SaveDC and RestoreDC has changed.
    Before these updates they had the  following behavior with respect to a path that was selected into a DC.
    - Select a path into DC.
    - SaveDC
    - Paint the path
    - Restore DC.
        Now the path is present in the DC and can be painted again, or the number of point fo the path can be retrieved.
    After these updates they had the following behavior with respect
    to a path that was selected into a DC.
    - Select a path into DC.
    - SaveDC
    - Paint the path
    - Restore DC.
        Now the path isn't present in the DC and can't be painted again.
        also retrieving the numbers of points of the path fails.
    With update KB2982791 we got a BSOD after calling
    pDC->GetPath(NULL,NULL,0);
    We didn't test this with update KB2993651 .
    Due to this changes our customers who applied these update have problems with printing.
    We use the SaveDC and RestoreDC to repeatedly  to use the same path without to the need of creating it with ::BeginPath ::Endpath everytime.
    This code was in use for more than 15 years, and now it is broken.
    This problem should be solved by microsoft, because the old behavior is the correct one.
    SaveDC and ResoreDC should also restores in the DC selected object (such as path).

    Hi, Genmini,
    According to the KB below, Microsoft already confirmed the issue after these two updates installed.
    http://support.microsoft.com/kb/2993651
    http://support.microsoft.com/kb/2982791
    You can try to uninstall these two updates firstly for test. Also you can try to use system restore to revert your system to a former normal time point if possible.
    In addition, please also check Windows updates, these problem should be fixed soon.
    Roger Lu
    TechNet Community Support

  • How to change the behavior of Named Criteria

    Dear,
    we created Named Criteria with bind viriable, then I drag as Query Panel to the page, then I drag the same VO to the page as ADF Form. in the same form I create three bottons ( Delete,Insert,Update)
    the question is when I create record in the form using Insert botton then I want to cancel this action and I want to click on search botton the from give that some fields in ADF from are requird so how to avoid that. or how can I change the behavior of search button .
    thanks,

    Thanks,
    but can you please tell me how to add the rollback in the action of search button.
    as I see I cann't find the code behinde for search button.

  • Adjusting the behavior of sales unit of measure on sales order

    Hello Everyone,
    I have a question regarding adjusting the behavior of sales unit of measure (UOM) on sales order (SO).
    We maintain 3 UOM on material master u2013 A, B, C; where A is base UOM and C is sales UOM.
    If we change the material on existing sales order in VA02, system also always changes the UOM on SO to C as well because C is sales UOM on material master. Sometimes SO quantities are in A or B UOM and we do not want system to change them to C when material is updated.
    We know it is a standard SAP behavior and the question is if it can be adjusted somehow (in configuration or some other way), so system is not changing the UOM on existing SO to sales UOM when material is updated.
    PS if we leave sales unit of measure field in material master blank, when material on SO is changed system is still changing the UOM, now to the base UOM A
    Thank you!
    Alex

    ANSWER: According to SAP there is no way to change the behavior without taking the risk of breaking a lot of stuff.

  • Changing the behavior of LOV's ...???

    Hi,
    Is it possible to change the behavior / appearance of LOV objects in Forms 6i and /or Forms10g..., or are they considered as 'black box'..????
    For example , is it possible to add two text fields in the upper side of the lov window titled as "Find" (the combination of the content of the first text field and/or the content of the second one...) , or to do the order of the displayed records dynamically as they appeared according to the first / second e.t.c. field ... or to order them in ascending or descending ....
    Thanks....
    Sim

    Hello,
    <p>This solution could show you one search direction.</p>
    Francois

  • How can a graphic be replaced in a Motion template and retain the behaviors of the graphic?

    I'd like to replace a graphic with another graphic in a template while retaining all the behaviors.  Possible?

    Yes, it's easy. You just drag. But you must pay attention to the cursor, it will turn into different things depending on where you try to drop your replacement.
    Check the online help system, just search for REPLACE and then look for REPLACE LAYER CONTENTS.
    bogiesan
    Message was edited by: David Bogie Chq-1

  • Whats the difference between comparable and comparator?

    whats the difference between comparable and comparator?
    when must i use comparable, and when must i use comparator?

    whats the difference between comparable and
    comparator?Comparable is from the java.lang package, Comparator from java.util.
    when must i use comparable, and when must i use
    comparator?Here's a tutorial on both:
    http://java.sun.com/docs/books/tutorial/collections/interfaces/order.html

  • How does the print gamut compare with mobile devices?

    I need to design a document for 4 color process printing, using only colors that will reproduce correctly on other platforms, such as computer monitors, smart phones, and tablets.
    I know how the print gamut compares with the RGB gamut of monitors.
    But are the gamuts of phones and tablets the same as monitors?

    There's very little hard evidence, based on a Google search. This Anandtech page, which compares the gamut, contrast, etc. of the iPad with Android tablets is the only one I could find.
    http://www.anandtech.com/show/5689/the-new-ipad-retina-display-analysis/3

  • Good day. Is there into Pages the possibility to compare two documents? In order to reveal changes.

    Good day. Is there into Pages the possibility to compare two documents? In order to reveal changes.

    Hi iMayner,
    I don't know of a way to easily compare two documents in Pages. Maybe there is an app to do this, but I don't know of one.
    What you can do in Pages is to open both documents, resize the windows and drag them side-by-side on the screen. Pages 5 has a limit on how narrow you can make the windows, so this may be a bit of a pain.
    The first step would be to show the Word Count in both documents. (Pages 5.5.1 Menu > View > Show Word Count, or click on the View button in the ToolBar and Show Word Count). If the Word Counts are the same, you have **some** confidence that the documents are identical, but no guarantee.
    An example of two short documents with different word counts:
    Document A (33 words)
    The quick brown fox jumps over the lazy dog.
    Don't count your chickens until they hatch.
    Don't cross your bridges until you come to them.
    An apple a day keeps the doctor away.
    Document B (34 words)
    The quick brown fox jumps over the lazy dog.
    Don't count your chickens until they have hatched.
    Don't cross your bridges until you come to them.
    An apple a day keeps the doctor away.
    To home in on that difference, copy and paste each document into a column in a spreadsheet such as Numbers or Excel, so that each paragraph becomes a cell in a column. Turn on Wrap text in cell.
    The different heights of each cell (paragraph) become apparent.
    Happy Christmas!
    Regards,
    Ian.

  • HT201302 I am trying to import photos taken on my iPod Touch to my computer. I read the support article and when I connect my iPod the auto play dialogue box does not appear so I followed the steps to enable the behavior but my iPod is not listed. What ca

    Am trying to import photos taken with my iPod touch to my windows 7 computer. When I plug in my iPod the Auto play dialogue box doesn't come up. I read the related article and tried to enable the behavior but when I go to the autoplay section and to devices the iPod does not appear in the devices menue . What can I do next? Thanks

    So you tried here:
    iOS: Importing personal photos and videos from iOS devices to your computer
    Have you looked here:
    iOS: Unable to import photos or device not recognized as a camera

Maybe you are looking for

  • Issue in updating the Template definition using XDOLOADER command

    Hi All, My requirement is to update the territory value as 00 from 'US' in the template screen.So I am using the XDOLOADER command to update the exising template defintion and the issue here is instead of replacing the old template territory value,it

  • Computers will not speak to each other

    Has anyone found this? I have two computers both running Adobe CS5.5 when I save files on to my external hard drive and try to edit in the other computer the files are not visible. If I open the files on the external hard drive they are only availabl

  • Built in speech software and iCal compatibility; Some questions

    This may be entirely an old concept that most people are tired of hearing, or perhaps it's something that has never come up, but it's been on my mind none the less. Recently I've wondered if I can use iCal in sync with the built in 'speech' that the

  • How to install aperture 2 (CD Version) on new Macbook Pro Retina

    Hello, Just purchased a new MacBook Pro Retina. I wanted to install aperture but all I have is the V.2 CD. How do I go about this? Thanks!

  • DSEE Server certificate required on client side?

    I have DSEE 6.3 working in my environment but I am not sure it's configured as it should be.... I am using tls:simple and everything works, the certificate store is setup with the CA and LDAP server certificates on both the LDAP servers and clients.