How would you implement equals ()

For complex classes with many data members, my dilema is:
1. equals should return true only if all fields of the two objects are
equals.
2. equals should return true if the key(s) of the two objets are equal.
For instance, we have the Class Person, that contains dozens of
data: ID, name, age, job, salary, children, more 1000 items.
Person is like a record in a DB table. There can not be two persons
with the same ID.
In this case, how would you implement equals, and why?
thanks

What I'm trying to say is: what is equality foryou?
Two objects are equal if all there contents areequals
or is it enough
to compare their keys?
In the latter case, there can happen, by somereason,
that we can end
up with two objects with the same keys, but all the
rest of
the contents different.i think you meant to say that:
In the latter case, there can happen, by somereason,
that we can end
up with two objects with different keys, but
all the rest of the contents the same.and the answer is, and listen carefully, it totally
depends on the application you are writing. there
is no hard definition of equality where custom classes
are concerned... that is the answer.If this question arises, you should revisit your design.
If two entities have equal keys, they should be considered to be equal. Otherwise the attributes you call keys are in the fact normal attributes and no keys.

Similar Messages

  • How would you implement a "real" on key released event?

    Hello there.
    I'm looking into key bindings and I'm trying to implement a "keep doing as long as space is pressed" feature. Figuratively speaking the optimal solution would be:
    space key is pressed -> call something.start()
    space key is released -> call something.stop()
    The thing is, the space key can be held down for several seconds and that does not generate one clear pressed and one clear released event. Instead you get a whole series of pressed and released events during the whole time the key is being pressed down. Actually it's logical. Click on some input field on your screen and keep a key pressed, you will see what I mean. :)
    So if I try to use:
    getInputMap().put(KeyStroke.getKeyStroke("pressed SPACE"), "start");...and...
    getInputMap().put(KeyStroke.getKeyStroke("released SPACE"), "stop");I don't get what I want. Start and stop are being called like crazy.
    So now, what would be the best way to react only to the first pressed and the last released event? Discarding events that follow each other too fast doesn't seem like an elegant solution.
    Thanks
    Cap

    Instead of timers I chose the following IMHO simpler and more reliable solution:
    public class Button
         private boolean on;
         public Button()
              on = false;
              // React to the SPACE key.
              getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("pressed SPACE"), "do");
              getActionMap().put("do", this);
         /* The problem we have to deal with is that a key being held down for several seconds
          * actually fires a whole havoc of pressed and released events. On Windows it fires
          * only a havoc of pressed events and then one released event when the button is
          * finally released. To make the button work right at least on Windows we keep track
          * of the state of the button (on = pressed, off = released). As soon as the button
          * is pressed, it doesn't react to pressed events anymore, this way the pressed havoc
          * can be ignored. It still reacts to released events though, so when the key is
          * finally released, the button goes into the off state again. On Linux this will never
          * work, because not only the pressed havoc, but also the released havoc is fired. */
         public void actionPerformed(ActionEvent arg0)
              if (on)
                   // The button is on, let's turn it off.
                   getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("pressed SPACE"), "do");
                   getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released SPACE"), "none");
                   on = false;
                   // TRIGGER SOME ACTION HERE
                   dont();
              else
                   // The button is off, let's turn it on.
                   getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("pressed SPACE"), "none");
                   getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("released SPACE"), "do");
                   on = true;
                   // TRIGGER SOME ACTION HERE
                   do();
    }Things would be much easier, if it was possible to differentiate, if the Action was triggerd by a "pressed" or a "released" event. I don't see a way to get this information from the ActionEvent object. If someone knows a way, please do tell.
    Cap

  • How would you implement a page like this?

    Hello
    When you look at www.autoweek.nl you see a little down 6 tab pages (Alle Rubrieken - Autonieuws etc.)
    My question is about the way you could implement the contents of one tab page.
    Would the content be several html regions (one for every message), or would it be a report? Or even something else?
    I'm struggling with the number of items. When I choose a html region for every news item I have a fixed number of HTML regions, which is not flexible.
    A report gives me this flexibility but is not that easy to layout?
    See also: http://www.autoweek.nl/nieuwsindex.php
    Any suggestions appreciated!
    Regards Erik
    Edited by: Erik Trip - Darwin IT on Nov 5, 2010 9:04 AM

    I would say a region per Tab and inside the Tab it is a report.
    brgds,
    Peter
    Blog: http://www.oracle-and-apex.com
    ApexLib: http://apexlib.oracleapex.info
    BuilderPlugin: http://builderplugin.oracleapex.info
    Work: http://www.click-click.at

  • How would you implement a domain in my situation?

    Are the users shared between site 3 and sites 1 and 2? You could do a totally separate domain at Site 3 if not.

    So I have three sites that I manage. I won't get into details as to why some things are the way they are, so I will just let you know what I have to work with.Site 1 and Site 2 are connected by VPN. Site 3 is not connected to these sites by VPN and can't be. I have full control of the Site 3's network firewall, switches, everything. Site 1 and 2 I have full access to everything, but not the firewalls or network switchs (its a contact thing).I have not chosen a domain service yet. I have thought about Windows Active Directory on an in-house system, lack of VPN worries me. I have thought of off site domain services like Univention as well, but I have never met anyone that has used it personally. Are there off site/hosted domain services that work as good as hosting in-house. The stability would be nice, but I have always done everything...
    This topic first appeared in the Spiceworks Community

  • How would you implement browser-based video conferencing?

    A client wants to build a website wherein multiple users (say 10 at a time) would be able to log in and converse with each other with sound and video in a virtual meeting room, with one user in particular broadcasting at a respectably high resolution, say 640x480. First of all, is this even possible to put together? If so, then what's the best way?
    I'm quite baffled as to how to approach this

    Diospyros wrote:
    A client wants to build a website wherein multiple users (say 10 at a time) would be able to log in and converse with each other with sound and video in a virtual meeting room, with one user in particular broadcasting at a respectably high resolution, say 640x480. First of all, is this even possible to put together? If so, then what's the best way?
    I'm quite baffled as to how to approach this
    It could be done with Flash but playback performance could be a issue with that many streams.

  • How would you change an integer variable per second

    Im new to action script, and I'm working on a game were your health variable will add 1 hp automatically every second if the health variable is not equal to 100. How would you do that?

    If you are using AS3, you can use the Timer class.  You can specify it to activate every second and use an event listener.event handler function to add to the value if it is less than 100.
    var healthTimer:Timer = new Timer(1000);
    function addHealth(evt.TimerEvent):void {
         if(health < 100) health += 1;
    healthTimer.addEventListener(TimerEvent.TIMER, addHealth);
    healthTimer.start();
    If you are using AS2, look into setInterval().

  • Would you implement GRC for just 2500 users

    Hi
    I've tried searching but my brain hurts so I'll probably get a roasting for asking a stupid and basic question
    If you have a 4.6C system with around 2.5k users in it how would you establish the cost effectiveness of buying and implementing RAR 5.3 (AC10) initially?
    Okay, I've hidden under the desk ready for abuse!
    Cheers
    David

    David Berry wrote:
    You would start with 10 singles to sort out and, by the time you had analysed who had what in which user group there would be 30 shiny new singles bobbing up and down and eager to go to PRD.
    Exactly that is why I don't like them and why they also popup all over the place when you remediate a single role used by several composites and you don't know what the dependencies are.
    You should only split roles because of Org-Levels.
    The music (as far as authority-checks are concerned) are in the singles (with generated profiles).
    Luckily (or not when remote enabled and the user can influence input parameters) newer concepts allow you substitute the org-level with programatic validations (for example "Business Partner" assignment of the "Person" mapped to the sy-uname).
    I have 3 million users in a system with only 3 roles. How is that for a ratio?
    GRC has a great value for backend config, support, development, etc such as other ABAP based authorization object concepts and you can map services and other applications to "actions" as if they were transactions, and you can do this logical system independently.
    It is still tempting, but not really a hard requirement to be able to control the access and combinations in a limnited number of systems. It is certainly independent of the number of users!
    A good build is always better - which is what GRC RAR will ultimately tell you anyway...
    Cheers,
    Julius
    ps: The "blue boxes" are like this:
    {quote} David said that composite roles are a dog's breakfast {quote}
    Result =
    David said that composite roles are a dog's breakfast

  • In Security, clicking on the "Saved Password" button displays your current saved password for each site. It does not allow you to change a password. How would you do that?

    In Security, clicking on the "Saved Password" button displays your current saved password for each site. It only allows you to view and delete site passwords. It does not allow you to change a password. How would you do that?

    If you enter a new password Firefox should offer to change the password.
    *You may not need to delete the old password. Try "Refreshing" the page, entering the site again, you may need to let Firefox fill in the old password, then enter the new password, and Firefox should ask to save the new password. See:
    **http://kb.mozillazine.org/Deleting_autocomplete_entries
    *If you delete the old password, you may need to "Refresh" the site after deleting the old password.
    If you want to delete the password that has been saved do the following:
    #In the Tools menu select Options to open the options window
    #Go to the Security panel
    #Click the "Saved Passwords" button to open the passwords manager
    #Select the site in the list, then click Remove
    <br />
    <br />
    '''You need to update the following.''' The Plugin version(s) shown below was/were submitted with your question and is/are out of date. You should update to avoid known security issues with the version(s) you have installed. Click on "More system info..." to the right of your question to see what was included with your question.
    *Adobe PDF Plug-In For Firefox and Netscape 8.3.0 (''Note: this is a very old version and installing the current version may not delete it or overwrite it. To avoid possible problems with having 2 versions installed on your system, you may want to remove the old version in Windows Control Panel > Add or Remove Programs before installing the new version'').
    *Shockwave Flash 10.3 r181 (''this may be current but a new version was released on 2011-06-14 with a ".26" after the "181". You can use the Plugin Check below and/or look in Add-ons > Plugins for the version of Shockwave Flash that you have installed. The newest version will be shown in Add-ons > Plugins as "Shockwave Flash 10.3.181.26"'').
    *Next Generation Java Plug-in 1.6.0_24 for Mozilla browsers
    #'''''Check your plugin versions''''' on either of the following links':
    #*http://www.mozilla.com/en-US/plugincheck/
    #*https://www-trunk.stage.mozilla.com/en-US/plugincheck/
    #*'''Note: plugin check page does not have information on all plugin versions'''
    #*There are plugin specific testing links available from this page:
    #**http://kb.mozillazine.org/Testing_plugins
    #'''Update Adobe Reader (PDF plugin):'''
    #*From within your existing Adobe Reader ('''<u>if you have it already installed</u>'''):
    #**Open the Adobe Reader program from your Programs list
    #**Click Help > Check for Updates
    #**Follow the prompts for updating
    #**If this method works for you, skip the "Download complete installer" section below and proceed to "After the installation" below
    #*Download complete installer ('''if you do <u>NOT</u> have Adobe Reader installed'''):
    #**SAVE the installer to your hard drive (save to your Desktop so that you can find it after the download). Exit/Close Firefox. Run the installer you just downloaded.
    #**Use either of the links below:
    #***https://support.mozilla.com/en-US/kb/Using+the+Adobe+Reader+plugin+with+Firefox ''(click on "Installing and updating Adobe Reader")''
    #***''<u>Also see Download link</u>''': http://get.adobe.com/reader/otherversions/
    #*After the installation, start Firefox and check your version again.
    #'''Update the [[Managing the Flash plugin|Flash]] plugin''' to the latest version.
    #*Download and SAVE to your Desktop so you can find the installer later
    #*If you do not have the current version, click on the "Player Download Center" link on the "'''Download and information'''" or "'''Download Manual installers'''" below
    #*After download is complete, exit Firefox
    #*Click on the installer you just downloaded and install
    #**Windows 7 and Vista: may need to right-click the installer and choose "Run as Administrator"
    #*Start Firefox and check your version again or test the installation by going back to the download link below
    #*'''Download and information''': http://www.adobe.com/software/flash/about/
    #**Use Firefox to go to the above site to update the Firefox plugin (will also install plugin for most other browsers; except IE)
    #**Use IE to go to the above site to update the IE ActiveX
    #*'''Download Manual installers'''.
    #**http://kb2.adobe.com/cps/191/tn_19166.html#main_ManualInstaller
    #**Note separate links for:
    #***Plugin for Firefox and most other browsers
    #***ActiveX for IE
    #'''Update the [[Java]] plugin''' to the latest version.
    #*Download site: http://www.oracle.com/technetwork/java/javase/downloads/index.html (Java Platform: Download JRE)
    #**'''''Be sure to <u>un-check the Yahoo Toolbar</u> option during the install if you do not want it installed.
    #*Also see "Manual Update" in this article to update from the Java Control Panel in Windows Control Panel: http://support.mozilla.com/en-US/kb/Using+the+Java+plugin+with+Firefox#Updates
    #* Removing old versions (if needed): http://www.java.com/en/download/faq/remove_olderversions.xml
    #* Remove multiple Java Console extensions (if needed): http://kb.mozillazine.org/Firefox_:_FAQs_:_Install_Java#Multiple_Java_Console_extensions
    #*Java Test: http://www.java.com/en/download/help/testvm.xml

  • How would YOU retype these old XM08 types for use in an ABAP OO method?

    The XM08 function group has the following type declarations:
    TYPES: BEGIN OF mmcr_drseg_co.
            INCLUDE STRUCTURE cobl_mrm_d.
    TYPES: cr LIKE drseg_cr    OCCURS 0,
           unpl_refwr TYPE refwr,
           END OF mmcr_drseg_co.
    TYPES: mmcr_tdrseg TYPE mmcr_drseg OCCURS 0,
    TYPES: BEGIN OF mmcr_drseg.
            INCLUDE STRUCTURE drseg.
    TYPES: cr LIKE drseg_cr OCCURS 0,
           co TYPE mmcr_drseg_co OCCURS 0,
           sm LIKE drseg_sm OCCURS 0,
           charact TYPE rbcharact_instance OCCURS 3,
                                           "instances of characteristics
           uebgmat  TYPE matnr,
           uebrblgp TYPE rblgp,
           selkz_db TYPE selkz,
           rblgp_old TYPE rblgp,           "rblgp before aggregation
           END OF mmcr_drseg.
    How would YOU redeclare these types so that they work in an ABAP Objects class?  
    Some of the "fixes" are easy, like replacing "LIKE" with "TYPE:".
    But what about the "INCLUDE STRUCTURE" and the "occurs 0" specifications?
    The reason I'm asking this is that I have to call a method from ZXM08U16 and I'd like to be able to pass this method exactly what XXM08U16 gets from SAP, i.e. the table E_TDRSEG of type  MMCR_TDRSEG

    David,
    I wonder it can be directly in ABAP (I would like to hear opinions from others as well!), I needed to use Data Dictionary as well:
    TYPES: BEGIN OF mmcr_drseg_co.
            INCLUDE STRUCTURE cobl_mrm_d.
    TYPES: cr TYPE z_tt_drseg_cr,
           unpl_refwr TYPE refwr,
           END OF mmcr_drseg_co.
    z_tt_drseg_cr is a table type created in SE11, based on structure drseg_cr.
    the way to create internal table and work area, based on the above:
    DATA : gt_... TYPE TABLE OF mmcr_drseg_co.
    DATA : gw_... TYPE mmcr_drseg_co.
    hope this helps some
    ec
    UPDATE : Rich is right, it is possible to do it only in ABAP with the DEFAULT KEY addition.

  • Disable the pop-up message box "How would you like to open this file" to open pdf file??

    Hi,
    is there any way i can stop the pop-up box displaying to open pdf file in sharepoint document library? Right now whenever i am trying to open pdf file, asking "how would you like to open"  Read only or edit mode. currently MIME Type is setup
    but still pop-up message box.
    Thanks in advanced!

    Hi ,
    As far as I know, This is a default feature. and is not recommended to delete or deactivate this pop up. 
    This is a feature of office and there is a dll called owssupp.dll which is responsible for getting the popup to open.
    You can go to IE tools> addon settings and deactivate the above dll (sharepoint open document class). But if you do so, then the other office office files which are word/excel/pptx etc.. would aslo gets affected and they also wont get the popup.
    Hope this helps.
    Best Regards, Ashok Yadala

  • How would you write a "wildcard" in a filefilter?

    How would you go about to have a wildcard instead of the "*" in the following filefilter;
              File[] files = new File("./resultat/resultat_" + "*" + "_" + index[0]).listFiles (new FileFilter () {
                    public boolean accept (File file) {
                        return ! file.isDirectory ();
              });All help appriciated
    - Karl XII

    Shouldn't "a*" accept all files that begins with "a" and ends with whatever?No. "*" in regexp is a not a wildcard match. Instead it matches one or more instances of the preceeding
    value.
    Therefore "a*" will match "a", "aa", "aaa", "aaaa" etc but will not match anything which does not end in
    an "a".
    The following might help you out. (not the most elegent expression but it will do
    import java.util.regex.*;
    public class RegExp{
      public static void main(String[] args) {
      Pattern p = Pattern.compile("a*b");     
      Matcher m = p.matcher("aaaab");     
      System.out.println(m.matches());                    
      // interesting bit here
      // match one or more occurances of any characters in the ASCII charset  (the \\p{ASCII}* bit   
      p = Pattern.compile("hello_\\p{ASCII}*_b");     
      m = p.matcher("hello_wibble_b");     
      System.out.println(m.matches());
    }

  • How would you pass more than 255 args?

    I have an SFTP program that currently is only passed a single file. I am modifying it so that it will loop though an array of files to simulate an mput command. Originally I was just going to call the program with each file to be transferred as an argument but noticed the 255 argument limit. I am looking at potentially having 1500 - 2000 files to transfer at one time. I am just looking for advice on how this should be designed. One idea that was forwarded to me was to just create a listing of the files on the server and use that list file as my argument. Would this be the best approach for this issue?

    sdhalepaska wrote:
    georgemc wrote:
    sdhalepaska wrote:
    georgemc wrote:
    sdhalepaska wrote:
    georgemc wrote:
    I see no reason why you need an argument for every file.I would not necessarily need one for every file. Prior to our needing to use this for multiple files, it was easy enough to pass in one file as an argument. That is my question, how would you try to pass in a long list of files?Let's establish what you are concerned about. The 255 argument limit is on method signatures. From what you're saying here, you're talking about arguments being passed into your application from, say, the shell. Am I right?Correct, please see my clarified post. From what I have tested, the 255 argument limit appears to exist even for arguments passed to main.Ah, but arguments passed to main from the command line are passed into main as a single array of Strings, no matter how many of them there are. I have no idea what the limit on those is, but an array can hold millions of elements. I expect your shell will moan about that many, though.
    As I see it, you have a few choices. Unless these files are all in different, arbitrary directories, you can specify a list of directories for your app to search. Or you can pass them all in one at a time, and see how you go. Or you can list them in a text file, pass that to your app and have it work them out. Or write a script that invokes your app multiple times. What you don't need, is a method that takes each file as an argument.Thank you for walking me through this. Would you mind telling me which way you would lean if you were designing this? The files will all be in a single directory on the server and I would not like to invoke the app multiple times as it creates a connection during each invocation. They're all in the single directory. Ok, are all the files in that directory to be transferred? If so, I'd just pass the directory name to the app, and have it iterate over all the files. If it's only to be certain ones, how do you know which ones? Is there some regex or filtering you can do on the command line?
    If you are interested, the 255 argument limit for main that I tested was from this article:
    [http://www.javaspecialists.eu/archive/Issue059.html|http://www.javaspecialists.eu/archive/Issue059.html]
    It does die at 255 using Java 1.5.Like I said, arguments to a method are thus limited. But the args passed to an app are passed to main as one argument - an array. In short, that article is not relevant to your problem.

  • How would you go about saving an online image locally?

    Say if you knew the url such as http://www.yahoo.com/img.jpg
    How would you save this locally?

    Read the answer in your previous posting:
    http://forum.java.sun.com/thread.jspa?threadID=772451
    Use the file as an InputStream to read the data and then use an OutputStream to write the file.
    The logic is the same as reading and writing a file from disk once you have the InputStream.

  • How would you split a 10 GB root partition? Would you?

    The system seems to be booting a little slow lately (been using Arch for more than a year now) and I was thinking of splitting the root partition to improve performance.
    Right now the entire OS is on a single partition. I don't have a /home partition but I can see it's usefulness:
    - files on /home are, in general, more frequently written (browser cache especially), which means less fragmentation for the root partition
    - having a noexec flag for /home so no potentially dangerous software will run from there (and why would you need to run software from /home?)
    - my /var folder takes up 102 MB, 9.706 files in 4.846 folders. Is there a filesystem that will deal well with many small files ? ReiserFS maybe ?
    So how would you split (gigabyte-wise) a 10 GB partition into /, /home and /var ? And would you ? I've been told from the IRC channel that it makes zero sense. At least not for desktop use.
    PS: I'm also switching from i686 to x86_64, so please take that into account as well. For instance I noticed that 64 bit software usually takes up more space than 32 bit.
    Last edited by DSpider (2011-05-29 11:32:04)

    Here is what's happening on my Arch box:
    . 2,1TiB [##########] /mnt
    . 61,0GiB [ ] /home
    5,2GiB [ ] /usr
    . 2,9GiB [ ] /var
    126,0MiB [ ] /opt
    83,1MiB [ ] /lib
    . 14,1MiB [ ] /boot
    10,0MiB [ ] /sbin
    . 7,3MiB [ ] /etc
    5,3MiB [ ] /bin
    . 3,0MiB [ ] /tmp
    192,0kiB [ ] /run
    20,0kiB [ ] /srv
    ! 16,0kiB [ ] /lost+found
    4,0kiB [ ] /dev
    4,0kiB [ ] /lib64
    ! 4,0kiB [ ] /root
    . 0,0 B [ ] /proc
    0,0 B [ ] /sys
    < 0,0 B [ ] /media
    Generated with ncdu.
    I have big stuff installed like a full texlive and libreoffice and I never clean my package cache. This is /var:
    . 2,6GiB [##########] /cache
    . 153,2MiB [ ] /lib
    57,1MiB [ ] /abs
    . 31,3MiB [ ] /log
    7,4MiB [ ] /tmp
    . 592,0kiB [ ] /spool
    . 132,0kiB [ ] /run
    8,0kiB [ ] /lock
    e 4,0kiB [ ] /opt
    e 4,0kiB [ ] /local
    e 4,0kiB [ ] /games
    ! 4,0kiB [ ] /enigma
    4,0kiB [ ] /empty
    @ 0,0 B [ ] mail
    And this is /var/cache
    2,6GiB [##########] /pacman
    10,9MiB [ ] /pkgtools
    3,0MiB [ ] /man
    320,0kiB [ ] /cups
    280,0kiB [ ] /fontconfig
    252,0kiB [ ] /samba
    ! 4,0kiB [ ] /ldconfig
    e 4,0kiB [ ] /hald
    /usr
    2,8GiB [##########] /share
    1,7GiB [###### ] /lib
    415,2MiB [# ] /bin
    153,9MiB [ ] /include
    149,8MiB [ ] /lib32
    15,3MiB [ ] /src
    13,7MiB [ ] /sbin
    104,0kiB [ ] /local
    I think I have a very typical desktop here: Mostly web/office stuff and some multimedia.

  • How would you capture the stdout of Runtime.getRuntime().exec())?

    How would you capture the stdout of Runtime.getRuntime().exec())?
    Say you wanted to execute PKZIP25.exe from java using Runtime.getRuntime().exec(). How would you capture the output of PKZIP25 (the console IO) in a file so you could check the results?
    Thanks
    Bill Blalock

    Thanks.
    Could you explain a little more?
    The program I am calling seems to be executing, as far as Java is concerned, but nothing happens. I imagine I have made mistakes in calling it but can't see the output to the console.
    Should I use Runtime.getRuntime().exec() or Runtime.exec() for something like this?
    I appreciate the help!
    Bill B.

Maybe you are looking for