How do I safely and correctly override equals in a generic element class?

(I posted this in the collection forum, but it was suggested I should take it here instead.)
I've written an OrderedPair element class, (OrderedPair<K,V>), so I can have a set of ordered pairs.
To get the container to treat OrderedPairs as values instead of objects, I had to override OrderedPair<K,V>.equals(Object) (as hashCode too).
So I've written the equals(Object) below in the naive way and I'm now getting warnings about an unsafe cast at line (a) and an unsafe assignemtn at line (b).
I do understand why this is a problem, but I'm not sure what the best solution is.
How does one ask about instanceof for the otherObject, and how does one cast an Object to an OrderedPair<K,V> in a safe way?
    public boolean equals (Object otherObject) {
     if (otherObject == null || ! (otherObject instanceof OrderedPair<K,V>)) {    //line (a)
         return false;
     } else {
         OrderedPair<K,V> otherPair = (OrderedPair<K,V>) otherObject;      // line (b)
            return this.key.equals(otherPair.key)  && this.value.equals(otherPair.value);
    }or, more to the point, how does one write a version of equals(Object) for a generic class?
It seems that this overriding of equal will have to be done for many generic element types, so there must be some approach that is safe, yes?
It was pointed out to me that AbstractMap does something similar

<warning: thread hijack>
public class OrderedPair<A,B> {
final A a;
final B b;
A first() {
        return a;
B second() {
   return b;
another question about generic code is this:
is it possible that , most of the time, a generic code may looks like this
(please note that this is not a criticism of the above code which is perfectly ok to me):
public class OrderedPair<A,B> {
  public final A a;
  public final B b; // no accessor such as getA(), getB()
my point : unless you want specific behaviour linked to value consultation
the actual type of members a and b is not hidden: encapsulation seldom makes sense.
it is known to the user of the parametrized type, it is not subject to maintenance change
so it is public ..... (if it is final)
any remark?

Similar Messages

  • Oracle Trigger - How can I capture and correct on the fly  ORA-01847

    Oracle Trigger - How can I capture and correct on the fly ORA-01847 day of month must be between 1.
    I have a table that has a date column. Sometimes an invalid date is passed and I'd like to capture and initilize the incoming value to null and have it inserted without error. Currently I get ORA-01847 day of month must be between 1.
    Example:
    create table ep1
    col_1 number,
    col_2 date
    Now if a user does the following, I want no error to occure but rather for the date value to be set to null and inserted.
    insert into ep1 values('1', '41-JAN-13')
    The insert may come from any client and I can't change the calling code hence can't used a precedure to replace the insert. I'm guessing there is some way to catch system level exceptions on the DB level. This doesn't need to be nice, it just needs to work.
    Here is the question on experts exchange. I'm told there is no way, but there must be. After all the exception is on a DB system level and I would think one could extend or override these, or disable them.
    http://www.experts-exchange.com/Database/Oracle/PL_SQL/Q_23045306.html

    SQL> declare
      2     wrong_month      exception;
      3     pragma exception_init (wrong_month, -1843);
      4  begin
      5    begin
      6      insert into emp (empno, hiredate)
      7      values (2345,to_date('13/25/81','MM/DD/YY'));
      8    exception
      9      when wrong_month then
    10      dbms_output.put_line('I caught the bad month');
    11      insert into emp (empno, hiredate)
    12      values (2345,null);
    13    end;
    14  end;
    15  /
    I caught the bad month
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from emp
      2  where empno = 2345;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          2345Note the 1843 error vice 1847. It can be done outside of a trigger.

  • I can't update IPhoto, it says "the product distribution file could not be verified it must be damaged or signed in" I bought it on iTunes and have 8,000 photos already. how can I update and correct this??

    I can't update IPhoto, it says "the product distribution file could not be verified it must be damaged or signed in" I bought it on iTunes and have 8,000 photos already. how can I update and correct this??

    You might try resetting the App Store application and clear the cookies via this menu:
    as described in this website: Make use of the Mac App Store debug menu | MacFixIt - CNET Reviews
    OT

  • How can I copy and paste my edited Photo in photoshop elements 12?

    How can I copy and paste my edited photo from photoshop elements 12 into a word document?

    In full Editor:
    Go to Select menu>all
    Go to Edit menu>copy to put it on the clipboard
    Go to your destination document>Paste
    Hope that this works for you as well.

  • How do I identify and install latest RAW plug in for elements 10 for Sony A 7 mark 2

    How do I identify and install latest RAW plug in for elements 10 for Sony A 7 mark 2

    Elements 10 is too old for this new camera. It can't be updated to the ACR 8.5 version, you would need PSE12 or 13.
    Camera Raw plug-in | Supported cameras
    You can download the free Adobe Dngconverter which can batch convert whole folders of your Sony raw files to the DNG raw format that your PSE10 can handle.
    FAQ: Will Photoshop Elements work with my camera, or Why won't my raw files open?

  • How can I safely and painlessly downgrade catalyst drivers?

    The latest version of catalyst is 11.8 and is horrible for me. For example, the computer screen does not turn on after going to sleep (a problem I had with 11.4 as well), when running applications from Terminal I'm constantly getting X errors, and now the latest is that I can't make boxee compile at all, complaining about missing lGL (I've googled around and people suggest reinstalling catalyst or installing mesa).
    Disclaimer: I need catalyst drivers and not FOSS ones because of my hardware.
    So the question is how would I go about downgrading from 11.8 to 11.7 as painlessly as possible?

    Yes and I know how to generally downgrade packages, but catalyst is specific in that it's from AUR, it has many scripts attached to it, there is a kernel module, and my past experiences with trying to downgrade it resulted in a screwed up system (following the wiki)

  • How to quickly, safely and easily delete duplicate song files

    Can someone tell me how I can do this because I seem to have quite a lot of duplicated songs on iTune which is annoying!

    Go to file in iTunes and click "show duplicates". This should work if the songs have the same names.
    Regards,
    ComputerWhiz

  • How can I find and correct corrupt Catalog files on Elements 9?

    I was trying to create a simple slideshow with sound when first my computer warned of low memory (something that doesn't seem plausible), and then Photoshop Elements 9 and the associated organizer crashed. When I brought it back, several photos were "grayed out" and my organizer is completely frozen. The error suggests that there are corrupt files. I tried to follow the instructions on the website, but cannot find any sort of Catalog menu or means of changing anything in the catalog or organizer as indicated in the troubleshooting and restoration instructions. Any use of the organizer is frozen.
    What am I missing? Thanks to all for your ideas.

    If you start up organizer while holding down the shift key, that should take you to the catalog manager where you can repair and optimize your catalog.

  • How to get error and correct result in different file...

    Hi,
    sqlplus -s u/p@i >logfile /nolog <<EOF
    @ sql script
    exit
    EOF
    Is it possible to write sqplplus so as to get only connection related error in logfile and PL/SQL script related error in spool file.
    Regards
    Sri

    Below is a sample script I used recently; here "2>" puts the errors into file mentioned and I spool inside the sql script I call from sqlplus session.
    Also if you use this type of connection users can not see you database users password with unix ps command -
    #!/bin/ksh                                                                     
    export SAMPLE_USERNAME="usernm"                                               
    export SAMPLE_PASSWORD="passwd"                                               
    export SAMPLE_DATE=$1                                                     
    export SAMPLE_DIR="/xxx/yyy/log"                                                   
    if [[ -z $SAMPLE_DATE ]]
    then
       echo
       echo HATA : SAMPLE_DATE parametresi girilmis olmali!..
       echo
       exit -1
    fi
    cd ${SAMPLE_DIR}
    retc=0
    sqlplus -s > $SAMPLE_DATE.log 2> $SAMPLE_DATE.err <<EOF
    $SAMPLE_USERNAME/$SAMPLE_PASSWORD
    @/xxx/scripts/yyy.sql $SAMPLE_DATE
    exit ;
    EOFbest regards.

  • How do you safely and quickly move users from one mailstore to another?

    In our current NMS configuration we have our clients spread across 4 mailstores (mstore0-mstore3). The current stores are filling up and we need to move some clients from each existing store to a new one (mstore4). MoveUser will move the users but seems very slow given the number of clients and messages will have to move. Is there any better method and as important has anyone else done anything similar and would share experiences?

    Hi,
    MoveUser is the safe and better way for moving the user.
    Please mention from which version you are migrating users from different store.
    hope the following link will help you
    http://docs.iplanet.com/docs/manuals/messaging/ims52/mg/changes.htm#20138

  • How can I safely and securely get files from my mac.

    I want something like LogMeIn Pro but for free. ther is a free version it DOES support mac BUT not gettong files. I want to be able to securely get files from my mac from school or anywhere whitout paying!!
    I HAVE had a look on google, no help.

    Try versiontracker.com

  • How do I copy and paste from Word into Adobe Photoshop Elements 13

    using Windows 7 Professional SP1, Microsoft Office 365 (Office 2013).
    I can copy the text within a word document, without a problem.
    However, the paste options are greyed out and "Ctrl"+"V" does not work.
    Am I missing something, as I can't work out how to copy the text from word, to use as a basis for my photo shop document.

    mattresshero wrote:
    Hey, guys. I am a complete noob to Elements 13. I need to get something done relatively quickly and I need to learn how to copy and paste from a Word document. How do I do this?
    Copy the text in WORD to place it on the clipboard
    Open PSE in Expert tab
    Open your picture file
    Get the type tool out of the tool box, click an insertion point
    Go to Edit>paste
    You should see two layers in the layers palette: background layer, and layer with the text.

  • Proofread and correct OCR'd text in Acrobat 10 Pro

    How do you proofread and correct text produced by OCR from a scanned document, in Acrobat 10 Pro?
    I scan (many, large) paper documents, then use Recognise Text. After the OCR phase, if I save PDFs as text, I can see many scan errors.
    I would like to be able to correct those errors in the scanned text, so that names etc can be successfully searched. However I cannot find any way to view and correct the scanned text.
    I experimented with Tools / Content / Edit Document Text, but I cannot see how to display the scanned text to allow correction. It appears to operate on the PDF image. But if I try to change the document image to correct known errors (e.g. in spacing), and then save the PDF as text again, the string where I changed the image becomes gibberish.
    How is Edit Document Text supposed to work? Is there any way to achieve what I am looking for (fixing many errors in large OCR'd documents)?
    Regards,
    Sue.

    "This is a 76-page document, and the users will expect to see the image looking like the scanned original."
    That locks it down. The only way to satisfy this is Searchable Image (Exact).
    The scanned image serves as the an objective replacement for the source hardcopy.
    The OCR output exists to facilitate search/find.
    At the end of the day there is no practical means of editing OCR's Hidden Text layer with it in the PDF.
    That's not to say you cannot work at it and get results. But, the operative word is practical.
    In that context you may want to look over a reply I made here:
    http://forums.adobe.com/thread/950209?tstart=0  
    To increase accuracy of OCR recognition:
    Yes, there are dedicated OCR applications (desktop or server). Having used several of each as well as Acrobat's OCR I've learned that also significant is the scanner and the quality of the hardcopy source.
    Regarding the remainder of your post above.
    Ok, I cannot replicate what you describe with a PDF I've been using.
    It is a scanned image of a single page of textual content.
    After ClearScan I can export to Word (&, of course, have some cleanup required).
    I can use the TouchUp Text / Edit Document Text tool to select all the PDF page's content (the ClearScan output).
    Changed the font to TimesNewRoman, saved, and exported to Word.
    The content in Word needed cleanup.
    Next, I selected various words and typed in a replacement word.
    After a Save I Exported to Word. The changed words carried through.
    re: Q1 - What you describe is symptomatic of the Hidden text output of Searchable Image / Searchable Image (Exact) and not ClearScan. So, I'm perplexed.
    re: Q2 - An advantage of ClearScan is being able to edit a text string to correct it. So, sure, why not correct? With that said, it can be a tedious and labor intensive activity. As well, typos are possible during correction which begs the question "Who bells the cat?"  8^) 
    re: Q3 - If corrections to the ClearScan output meets your needs an export to Word may not be needed.
    However, sometimes ClearScan cannot recognize the image of a character and leaves it as a bitmapped image.
    So, to correct you'd have to get into a word processor.
    re: Q4 - Goes back to Q3.
    Here are some useful video tutorials:
    http://acrobatusers.com/tutorials/clearscan-vs-imagetext-ocr 
    A listing of others: http://acrobatusers.com/tutorials/filter/search&keywords=scanning%20ocr&tut_type=Video&cha nnel=tutorials/
    At Adobe TV:
    http://acrobatusers.com/tutorials/filter/search&keywords=scanning%20ocr&tut_type=Video&cha nnel=tutorials/
    Be well...

  • How do I safely retreive my harddrive contents before having MacBook Pro repaired?

    I have a MacBook Pro model A1260 with a broken logicboard. How do I safely and inexpensively retreive my harddrive contents before having it repaired? I am also considering purchasing a used one and swapping out the harddrive. Thank you.

    Thank you, I thought this as well but they told me they do need the hard drive because when they send it out they test it to be sure every part is working. Also the technician said that he was 'pretty sure' it was the logicboard based on his diagnostics however cannot be sure until it is repaired. The suggestion was to pay $100 to have my data transfered and it would not be done on site.

  • How can I edit and save a raw file in jpeq and open it in windows live photo gallery

    how can I edit and save a raw file in ps elements 10 and open it in windows live photo gallery?

    Change to 8 bit mode before clicking the Open Image button, then jpeg will become available as a choice.
    Click to view image

Maybe you are looking for

  • How to set ApplicationIntent=ReadOnly in Connection String for SharePoint 2013

    SharePoint 2013 and SQL Server 2012 allows us some additional options to create HA and DR sites through AlwaysOn Availablibity Groups and Listeners.  Problem that I'm having is that I have a DR site that is at a different location.  Microsoft recomme

  • MP4/H.264 video format license for selling videos

    Hello! I have searched on the forums and I did not find anything new about this topic. I create animated films and I want to export them as .mp4 with H.264 codec. Can I use these films with commercial purpose? (I want to sell the films to companies,

  • Material issue for subcontracting PO

    while issuing the material for subcontracting PO with TCode MB1B mov type 541 when i am giving more quantity then the subcontracting PO it is posted how it is possible. Please help... For an instance i am giving quantity 10 in Subcontracting PO and g

  • FlashPaper Menu in Word Missing

    I have recently installed Studio 8 which comes with Contribute 3 which come with FlashPaper2 (why they bundled Contribute and FlashPaper together, I can't figure). I like FlashPaper and have been experimenting with it in my work area. For some reason

  • How To Convert DVD Files To Nokia N8 Format?

    Which Converter Is To Be Used So That We Can Watch Movies In N8