Problem overring equals, hashcode on a LinkedHashMap

Hello,
I have a "LinkedHashMap<MyObject, Integer> mymap;
now I filled it and I want to keep the order of insertion;
{code}
class MyObject {
public Map<String,Integer> names = new LinkedHashMap<String, Integer>();
{code}
after that I created a new MyObject ob; filled its names and then I wanted to see if it was inside my map; it was actually there, but the MyObject contained within myMap had the <String, integer> in names in a different order; so it failed; BUT I wouldn't like this. Can I change the override to equals? How? I generate if by Eclipse.
thanks.

Here's what I would have done in the good ol' days.
import java.lang.Comparable;
import java.util.Date;
public class MyObject implements Comparable
  protected Date dateInserted = new Date();
  public Date getDateInserted()
    return dateInserted;
  public int compareTo(Object obj)
    MyObject mo = (MyObject)obj;
    return dateInserted.compareTo(mo.getDateInserted());
}Then make a MyObject[] myObjects, then call Arrays.sort(myObjects).
import java.util.Arrays;
public class test
  public static void main(String[] args)
    MyObject[] myObjects = new MyObject[10];
    // create instances.
    Arrays.sort(myObjects);
    // use sorted instances.
}

Similar Messages

  • Implementation of equals, hashCode, and

    I am writing an RMI application where the implementation of the remote interface cannot extend UnicastRemoteObject because it already extends another class. So, I need to explicitly export the server object using UnicastRemoteObject.exportObject(server, 0);� no problem.
    Problem is I�ve read that in order to make the class behave as if it had extend UnicastRemoteObject, you must provide implementations for equals, hashCode, and toString. I�ve searched the world over for implementations of these methods equivalent to those found in UnicastRemoteObject� no luck so far.
    Could you help me out?
    I�ve found some code that I�ve listed below� Is it equivalent to the equals and hashCode method found in UnicastRemoteObject? What about toString()?
    public class RemoteDataServer extends LocalDataServer implements RemoteInterface{
        private Remote serverStub;
        public RemoteDataServer() throws IOException {
            super();
            //export remote object
            serverStub = UnicastRemoteObject.exportObject(this);
        public boolean equals(Object obj) {
            return (obj == this || serverStub.equals(obj));
        public int hashCode() {
            return serverStub.hashCode();
    //toString()???

    Hi,
    At book Effective Java by Joshua Bloch you can see some info
    overriding these members.
    See at http://java.sun.com/docs/books/effective/index.html
    Here is the toString()spec method from Object :
    Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
    The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
    getClass().getName() + '@' + Integer.toHexString(hashCode())
    but toString from class String simply returns the string contents of
    an object.
    Hope this help

  • Interactive report performance problem over database link - Oracle Gateway

    Hello all;
    This is regarding a thread Interactive report performance problem over database link that was posted by Samo.
    The issue that I am facing is when I use Oracle function like (apex_item.check_box) the query slow down by 45 seconds.
    query like this: (due to sensitivity issue, I can not disclose real table name)
    SELECT apex_item.checkbox(1,b.col3)
    , a.col1
    , a.col2
    FROM table_one a
    , table_two b
    WHERE a.col3 = 12345
    AND a.col4 = 100
    AND b.col5 = a.col5
    table_one and table_two are remote tables (non-oracle) which are connected using Oracle Gateway.
    Now if I run above queries without apex_item.checkbox function the query return or response is less than a second but if I have apex_item.checkbox then the query run more than 30 seconds. I have resolved the issues by creating a collection but it’s not a good practice.
    I would like to get ideas from people how to resolve or speed-up the query?
    Any idea how to use sub-factoring for the above scenario? Or others method (creating view or materialized view are not an option).
    Thank you.
    Shaun S.

    Hi Shaun
    Okay, I have a million questions (could you tell me if both tables are from the same remote source, it looks like they're possibly not?), but let's just try some things first.
    By now you should understand the idea of what I termed 'sub-factoring' in a previous post. This is to do with using the WITH blah AS (SELECT... syntax. Now in most circumstances this 'materialises' the results of the inner select statement. This means that we 'get' the results then do something with them afterwards. It's a handy trick when dealing with remote sites as sometimes you want the remote database to do the work. The reason that I ask you to use the MATERIALIZE hint for testing is just to force this, in 99.99% of cases this can be removed later. Using the WITH statement is also handled differently to inline view like SELECT * FROM (SELECT... but the same result can be mimicked with a NO_MERGE hint.
    Looking at your case I would be interested to see what the explain plan and results would be for something like the following two statements (sorry - you're going have to check them, it's late!)
    WITH a AS
    (SELECT /*+ MATERIALIZE */ *
    FROM table_one),
    b AS
    (SELECT /*+ MATERIALIZE */ *
    FROM table_two),
    sourceqry AS
    (SELECT  b.col3 x
           , a.col1 y
           , a.col2 z
    FROM table_one a
        , table_two b
    WHERE a.col3 = 12345
    AND   a.col4 = 100
    AND   b.col5 = a.col5)
    SELECT apex_item.checkbox(1,x), y , z
    FROM sourceqry
    WITH a AS
    (SELECT /*+ MATERIALIZE */ *
    FROM table_one),
    b AS
    (SELECT /*+ MATERIALIZE */ *
    FROM table_two)
    SELECT  apex_item.checkbox(1,x), y , z
    FROM table_one a
        , table_two b
    WHERE a.col3 = 12345
    AND   a.col4 = 100
    AND   b.col5 = a.col5If the remote tables are at the same site, then you should have the same results. If they aren't you should get the same results but different to the original query.
    We aren't being told the real cardinality of the inners select here so the explain plan is distorted (this is normal for queries on remote and especially non-oracle sites). This hinders tuning normally but I don't think this is your problem at all. How many distinct values do you normally get of the column aliased 'x' and how many rows are normally returned in total? Also how are you testing response times, in APEX, SQL Developer, Toad SQLplus etc?
    Sorry for all the questions but it helps to answer the question, if I can.
    Cheers
    Ben
    http://www.munkyben.wordpress.com
    Don't forget to mark replies helpful or correct ;)

  • Syncing problem over cloud for all my devices

    I have severe syncing problems over the cloud with all iWorks apps (Pages, Numbers, Keynote) across ALL my devices (iMac, MacBook, iPad2, IPhone4) and even on web: It JUST DOESN'T WORK!!!
    Internet works perfectly, Docs sync is set to ON in every device, but since 6 October 2012, syncing was stoped for unknonw reasons.
    I tried to find someone to contact for by email, but it was impossible. So I ended up here ...
    Can help someone?

    For each device, backup first, then on the device use Settings > General > Software Update. Each one still has to download the update individually, but they are smaller files so should download more reliably.
    tt2

  • NotFilter doesn't have equals/hashCode implementation

    Hi Guys,
    I'm using 3.4.2/411 and NotFilter doesn't have an equals/hashCode implementation - this means that it doesn't get properly removed when you unregister a listener/CQC.
    It's easy to work around by extending the class, but it would be nice to have a proper fix.
    I'm also suspicius of InFilter...
    Thanks, Paul

    Thanks for your note.
    This issue has been filed as COH-2586 for future reference.

  • Large file transfer problems over client/server socket

    Hi,
    I wrote a simple chat problem in which I can send files from client to client. The problem is when I send large files over 101 MB the transfer freezes. I do not even get any error mesages in the console. The files I am sending are of any type (Ex mp3, movies, etc...). I am serializing the data into a "byteArray[packetSize]" and sending the file packet by packet until the whole file has been sent, and reconstructed on the other side. The process works perfectly for files smaller than 101MB, but for some reason freezes after that if the file is larger. I have read many forums and there aren't too many solutions out there. I made sure to use the .reset() method to reset my ObjectOutputStream each time I write to it.
    Here's my file sending code:
    byte[] byteArray = new byte[defaultPacketSize];
    numPacketsRequired = Math.ceil(fileSize / defaultPacketSize);
    try {
    int i = 0;
    reader = new FileInputStream(filePath);
    while (reader.available() > 0) {
    if (reader.available() < defaultPacketSize) {
    byte[] lastPacket = new byte[reader.available()];
    reader.read(lastPacket);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(lastPacket);
    output.reset();
    output.writeObject("DONE");
    output.reset();
    output.close();
    socket.close();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    else {
    reader.read(byteArray);
    try {
    if (socket == null || output == null) {
    throw new SocketException("socket does not exist");
    output.writeObject(byteArray);
    output.reset();
    catch (Exception e) {
    System.out.println("Exception ***: " + e);
    output.close();
    socket.close();
    reader.close();
    catch (Exception e) {
    System.out.println("COULD NOT READ PACKET");
    Here's my file receiving code:
    try {
    // The message from the client
    Object streamInput;
    FileOutputStream writer;
    byte[] packet;
    while (true) {
    streamInput = input.readObject();
    if (streamInput instanceof byte[]) {
    packet = (byte[]) streamInput;
    try {
    writer = new FileOutputStream(outputPath, true);
    writer.write(packet); //Storing the bytes on file
    writer.close();
    catch (Exception e) {
    System.out.println("Exception: " + e);
    else if (streamInput.equals("DONE")) {
    socket.close();
    input.close();
    break;
    catch (Exception e) {
    I'm looking for any way I can possibly send large files from client to client without having it freeze. Are there any better file transfer ways other than socket? I don't really want FTP. I think I want to keep it HTTP.
    Any suggestions would be helpful.Thanks!
    Evan

    I've taken a better look a the code you posted, and
    there is one problem with the receiving code. You
    keep repeatedly opening and closing the
    FileOutputStream. This is not going to be efficient
    as the file will keep needing to be positioned to its
    end.Yes sorry I did change that code so that it leaves the file open until completely done writing. Basically I have a progress bar that records how far along in the writing process the client is, and when the progress bar reaches 100%, meaning the file is complete, the file.close() method is invoked. Sorry about that.
    I also ran some memory tests using the "Runtime.getRuntime().totalMemory()", and "Runtime.getRuntime().freeMemory()" methods. I put these methods inside the loop where I read in the file and send it to the client. here's the output:
    Sender's free memory: 704672
    File reader read 51200 bytes of data.
    767548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 702968
    File reader read 51200 bytes of data.
    716348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 701264
    File reader read 51200 bytes of data.
    665148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 699560
    File reader read 51200 bytes of data.
    613948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 697856
    File reader read 51200 bytes of data.
    562748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 696152
    File reader read 51200 bytes of data.
    511548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 694448
    File reader read 51200 bytes of data.
    460348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 692744
    File reader read 51200 bytes of data.
    409148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 691040
    File reader read 51200 bytes of data.
    357948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 689336
    File reader read 51200 bytes of data.
    306748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 687632
    File reader read 51200 bytes of data.
    255548 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 685928
    File reader read 51200 bytes of data.
    204348 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 684224
    File reader read 51200 bytes of data.
    153148 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 682520
    File reader read 51200 bytes of data.
    101948 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 680816
    File reader read 51200 bytes of data.
    50748 left to read.
    Sender's runtime memory: 2818048
    Sender's free memory: 679112
    File reader read 50748 bytes of data.
    0 left to read.
    Creating last packet of size: 50748
    Last packet size after setting it equal to byteArray: 50748
    Here's the memory stats from the receiver:
    Receiver's free memory: 639856
    Receiver's total memory: 2842624
    Receiver's free memory: 638920
    Receiver's total memory: 2842624
    Receiver's free memory: 637984
    Receiver's total memory: 2842624
    Receiver's free memory: 637048
    Receiver's total memory: 2842624
    Receiver's free memory: 636112
    Receiver's total memory: 2842624
    Receiver's free memory: 635176
    Receiver's total memory: 2842624
    Receiver's free memory: 634240
    Receiver's total memory: 2842624
    Receiver's free memory: 633304
    Receiver's total memory: 2842624
    Receiver's free memory: 632368
    Receiver's total memory: 2842624
    Receiver's free memory: 631432
    Receiver's total memory: 2842624
    Receiver's free memory: 630496
    Receiver's total memory: 2842624
    Receiver's free memory: 629560
    Receiver's total memory: 2842624
    Receiver's free memory: 628624
    Receiver's total memory: 2842624
    Receiver's free memory: 627688
    Receiver's total memory: 2842624
    Receiver's free memory: 626752
    Receiver's total memory: 2842624
    Receiver's free memory: 625816
    Receiver's total memory: 2842624
    Receiver's free memory: 624880
    Receiver's total memory: 2842624
    Receiver's free memory: 623944
    Receiver's total memory: 2842624
    Receiver's free memory: 623008
    Receiver's total memory: 2842624
    Receiver's free memory: 622072
    Receiver's total memory: 2842624
    Receiver's free memory: 621136
    Receiver's total memory: 2842624
    Receiver's free memory: 620200
    Receiver's total memory: 2842624
    Receiver's free memory: 619264
    Receiver's total memory: 2842624
    Receiver's free memory: 618328
    Receiver's total memory: 2842624
    Receiver's free memory: 617392
    Receiver's total memory: 2842624
    Receiver's free memory: 616456
    Receiver's total memory: 2842624
    Receiver's free memory: 615520
    Receiver's total memory: 2842624
    Receiver's free memory: 614584
    this is just a sample of both receiver and sender's stats. Everything appears to be fine! Hope this message post isn't too long.
    Thanks!

  • Have this problem over a month now

    Afternoon everyone,
    Where should I start..
    About a month ago my hub started resetting itself whenever I used internet, i spoke to numerous amount of people over at the call centre and about 2 weeks after calling them nearly every day they sent openreach engineer over to my house to check whats going on. He did what he had to do inside my house and outside my house, then he did some tests which all said "passed", but hey after the visit i went straight on my computer and checked the speeds which were at about 1mb at the time which still are not good enough considering i had 6-8mb about 3 months ago, anyway back on the subject i contacted bt yet again and they said the line needs to be running few days for the connection to stabilise. A week of waiting and still nonthing speeds the same and my hub was still resetting itself but not as often as it used to. After a week I decided im not going to bother with those useless people in the call centre so I emailed bt and started to explain my problem all over again, first they sent an engineer to my exchange to see whats going on there, still nothing improved after that. They then decided that they should send an engineer again which came to my house yesterday and replaced the master socket and also did other things which i didnt see. He then like the first engineer did some tests and he said that the speed hes getting from the master socket is 9.7mb i was all excited that i finally got back speeds i used to have about 3months ago but hey, went on the computer straight away after the visit and the speeds were at 500kb/s. I had an idea today that maybe i should bring my computer downstairs with the hub and connect it to the master socket but still nothing.. same speeds and the hub is still resetting from time to time, if i counted correctly the hub resetted 7 times today and 4/7 of them resets the hub didnt connect to the broadband for about an hour and on one reset it didnt connect for 4 hours the rest connected in about a minute. This is really going beyond a joke now, really unuhappy with the whole situation which i repeat had for over a MONTH now. Im thinking of changing to another ISP and as bt said if i change from bt to any isp the problem will still remain id prefer to talk to normal people and not the callcentre which as a matter of fact everybody knows is useless and you can barely understand what they are trying to say due to obvious reasons.
                                             TEST
    Quite line is fine not much noise even though im using a cordless phone.
    Connection information
    Line state
    Connected
    Connection time
    0 days, 0:57:48
    Downstream
    1,151 Kbps
    Upstream
    708 Kbps
    ADSL settings
    VPI/VCI
    0/38
    Type
    PPPoA
    Modulation
    ITU-T G.992.5
    Latency type
    Interleaved
    Noise margin (Down/Up)
    25.0 dB / 8.8 dB
    Line attenuation (Down/Up)
    42.5 dB / 21.8 dB
    Output power (Down/Up)
    20.1 dBm / 12.4 dBm
    FAQ
    Test1 comprises of two tests
    1. Best Effort Test:  -provides background information.
    Download Speed
    622 Kbps
    0 Kbps
    1000 Kbps
    Max Achievable Speed
     Download speedachieved during the test was - 622 Kbps
     For your connection, the acceptable range of speedsis 400-1000 Kbps.
     Additional Information:
     Your DSL Connection Rate :1148 Kbps(DOWN-STREAM), 708 Kbps(UP-STREAM)
     IP Profile for your line is - 750 Kbps
    The throughput of Best Efforts (BE) classes achieved during the test is - 11.79:25.54:62.8 (SBE:NBEBE)
    These figures represent the ratio while sententiously passing Sub BE, Normal BE and Priority BE marked traffic.
    The results of this test will vary depending on the way your ISP has decided to use these traffic classes.
    2. Upstream Test:  -provides background information.
    Upload Speed
    572 Kbps
    0 Kbps
    708 Kbps
    Max Achievable Speed
    >Upload speed achieved during the test was - 572 Kbps
     Additional Information:
     Upstream Rate IP profile on your line is - 708 Kbps
    We were unable to identify any performance problem with your service at this time.
    It is possible that any problem you are currently, or had previously experienced may have been caused by traffic congestion on the Internet or by the server you were accessing responding slowly.
    If you continue to encounter a problem with a specific server, please contact the administrator of that server in the first instance.
    Please visit FAQ section if you are unable To understand the test results.
    http://www.speedtest.net/result/1221794792.png
    Thank you to anyone who will bother to read my rant, but hopefully im going to get my message across now....

    rest of the stats : 
    ADSL settings
    VPI/VCI
    0/38
    Type
    PPPoA
    Modulation
    ITU-T G.992.5
    Latency type
    Interleaved
    Noise margin (Down/Up)
    21.9 dB / 8.3 dB
    Line attenuation (Down/Up)
    42.5 dB / 21.8 dB
    Output power (Down/Up)
    20.1 dBm / 12.4 dBm
    Loss of Framing (Local)
    0
    Loss of Signal (Local)
    0
    Loss of Power (Local)
    0
    FEC Errors (Down/Up)
    11189 / 22
    CRC Errors (Down/Up)
    8 / 2147480000
    HEC Errors (Down/Up)
    nil / 878043
    Error Seconds (Local)
    5

  • My MacBook Air keyboard isn't working, except the power button. I had the same problem over the summer and had it repaired ~4 months ago. What should I do?

    The keyboard of my 11-inch MacBook Air, purchased in November 2011, isn't working at all. None of the keys respond except the power button. I'm able to restart the computer, and have done so multiple times. I've attempted SMC and PRAM resets, but they haven't worked.
    I've never spilled anything on the laptop, haven't stepped on it, and haven't otherwise damaged it ever. I use the laptop very lightly. I only use it to take notes for class, browse the Internet, and watch movies. I don't download anything but PDFs, PowerPoints, images, and Word documents. I don't even have music on it. So I don't think I had any part in creating the problem.
    I had this same problem with my laptop over the summer, and I took it into the Apple Store to get it repaired for $200. They told me that they didn't know the cause of the problem. I think they replaced the bottom half of my laptop entirely (receipt says there's a new "Housing, Top Case with Keyboard, US") and told me the problem was fixed. This was on June 30. The laptop keyboard stopped working again today, October 19. I called Apple Support and they told me that I would have to pay for the repair again because it's been 90 days since the last repair. I'm annoyed and upset that I have to pay $200 again to re-repair a problem that should've been properly fixed the first time. Plus, if the problem keeps happening despite multiple repairs, I can't afford to keep getting the laptop repaired over and over again due to the Apple employees' incompetence.
    Does anyone have any advice on how to fix the laptop? I'm a grad student and don't have the funds to pay for another repair, and there's no way for me to get to an Apple Store without hiring a car service, so I'm trying to avoid going to the store if possible. Thank you.

    Get the new keyboard at eBay and replace by yourself may be cheaper way, though you're required higher skill and well know about MacBook Air.
    http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR0.TRC0.H0 .Xmacbook+air+2011+keyboard&_nkw=macbook+air+2011+keyboard&_sacat=0
    https://www.youtube.com/watch?v=gLbasVD69xo

  • Problem - over lie of data series in Line chart (Web Application Designer)

    Dear Experts,
    I have created a chart with below requiments from my user by using web application designer.
    1) Key Figure 1 (Chart type -> column )
    2) Key Figure 2 (Chart type -> column )
    3) Key Figure 3 (Chart type -> Line; color assigned -> BLACK;    Visibility: Visible)
    4) Key Figure 4 (Chart type -> Line; color assigned -> YELLOW; Visibility: Visible/Hidden)
    5) Key Figure 5 (Chart type -> Line; color assigned -> RED;         Visibility: Visible/Hidden)
    The line chart of Key Figure 3 must always appear in Front then others Key Figures.
    Then following by, Key Figure 4. Last is Key Figure 5.
    As I know the order of display line chart is infflucing by the order of Key Figure in structure by descending, likes below
    1) Key Figure 3 (Rank of front -> 3rd; Chart type -> Line; color assigned -> BLACK;    Visibility: Visible)
    2) Key Figure 4 (Rank of front -> 2nd; Chart type -> Line; color assigned -> YELLOW; Visibility: Visible/Hidden)
    3) Key Figure 5 (Rank of front -> 1st; Chart type -> Line; color assigned -> RED;         Visibility: Visible/Hidden)
    So, I have conflict on fulfilling these 2 request on assigning the color and control their visibility and lines over lie.
    Please advice me if you have any suggestion on controlling the lines order.
    Thanks!
    ~ GP
    Edited by: GP Poh on Jun 9, 2010 12:32 PM

    Hi Priya, thanks for input.
    I think I should further elaborate the problems. Thanks for your highlight.
    I have a lines chart with five key figures. So my chart will have five lines.
    Some lines from chart will overlap if the data are same.
    When overlapping of lines happens, I want to control the order of which series should be appear first.
    Likes below example,
    1) Key Figure 1 (Chart type -> column )
    2) Key Figure 2 (Chart type -> column )
    3) Key Figure 3 (Chart type -> Line; color assigned -> BLACK; Visibility: Visible)
    4) Key Figure 4 (Chart type -> Line; color assigned -> YELLOW; Visibility: Visible/Hidden)
    5) Key Figure 5 (Chart type -> Line; color assigned -> RED; Visibility: Visible/Hidden)
               KF1  KF2  KF3  KF4  KF5
    CW 1    30     30    80    80    50
    CW 2    40     50    90    60    90
    CW 3    70     50    90    90    90
    CW 4    80     70    70    90    70
    As you can see, there is overlap in these value.
    CW 1 KF3, KF4  -->80
    CW 2 KF3, KF5 --> 90
    CW 3 KF3, KF4, KF5 --> 90
    The order which i want the series should appear first when overlapping.
    - KF3 must appear on top.
    - Then, follow by KF5
    - Last is KF4.
    So now, i have no idea to control the overlap orders except adjusting the sequence of keyfigure from query.
    Feel free to give me any input!

  • Problem with Equals/Contains

    Hello,
    I am learning .net c# and i wanted to rewrite Stack collection.
    But when i tried rewriting Contains method, i think i found little bug.
    I cant compare two instances of class.
    I created class Test and i put it into stack, then i made new instance of class Test and i tried do Contains, how i found out it always returns False. Same is with Equals, ReferenceEquals and ==. Why is this happening? Both classes contains same items with
    same things. Why it isnt True?
    Thanks for answer.

    Comparison and equality are one of the things that are done in an strange way in .NET.
    First thing to pay attention is that, there is difference between equality comparison and less than/greater than comparison. On the whole, equality is used in searching and looking up while comparison is used in sorting. Equality comparison is always doable.
    You compare whether two things are equal. But less than/greater than might not necessarily possible in all situations.
    There are also two general ways when comparing two things (whether for equality or less than/greater than):
    Objects themselves perform comparison on each other
    Another object -and external object- performs comparison on them
    In first approach, we call the Equals() method an object, passing it the other object we intend to compare its equality with, and the former object performs equality comparison himself and sees whether it is equal to the given object or not. While Equals()
    method provides us a good point to override comparison, the limitation is that, we can override Equals() only once in a class, while there might be different equality contexts available for comparison.
    For example in a collection of Person objects, one time we might compare equality based on Lastname and another time we might want to do it based on Birthdate. Using Equals() method regretfully gives us an only chance for comparison. Also, it corrupts the
    equality rule of all of our objects. Apparently we don't want to change the equality algorithm of our objects, one of which is equality comparison based on reference that is done intrinsically by object base class. Also, what if we don't access to the source
    code of the class we are using its instances in our application?! Let's not think about such a frightening situation (in that case, inheritance is an ultimate shot, however, not the only shot, as we will see soon). This leads us to the other approach.
    In the second approach we use another object as a judge that performs comparison (whether it be equality or less than/greater than) and proclaims the result. Because the judge object is external and can be any object, we will potentially have numerous
    choices at hand to use for comparison. One time we might use a LastNameEqualityComparer object, another time use a BirthdateEqualityComparer and another time use whatever equality comparer we want. We have total freedom.
    Now, we get to the point where I said there is strange or anomaly behavior in .NET collections regarding comparison.
    Some collections such as Dictionary<TKey, TValue> provides us a way to pass them an equality comparer object in their constructors when we are creating an instance of them.
    public Dictionary(IEqualityComparer<TKey> comparer)
    exmaple: https://msdn.microsoft.com/en-us/library/ms132072(v=vs.110).aspx
    public class Example
    public static void Main()
    // Create a new Dictionary of strings, with string keys
    // and a case-insensitive comparer for the current culture.
    Dictionary<string, string> openWith =
    new Dictionary<string, string>(
    StringComparer.CurrentCultureIgnoreCase);
    // Add some elements to the dictionary.
    openWith.Add("txt", "notepad.exe");
    openWith.Add("bmp", "paint.exe");
    openWith.Add("DIB", "paint.exe");
    openWith.Add("rtf", "wordpad.exe");
    // Try to add a fifth element with a key that is the same
    // except for case; this would be allowed with the default
    // comparer.
    try
    openWith.Add("BMP", "paint.exe");
    catch (ArgumentException)
    Console.WriteLine("\nBMP is already in the dictionary.");
    // List the contents of the sorted dictionary.
    Console.WriteLine();
    foreach( KeyValuePair<string, string> kvp in openWith )
    Console.WriteLine("Key = {0}, Value = {1}", kvp.Key,
    kvp.Value);
    But some collections don't provides us a way in their constructors to pass them a custom comparer. Unfortunately your case, Stack, is among them and Stack doesn't have such a constructor.
    If we read the MSDN documentation of the Contains() method in the non-generic Stack, and generic Stack<T> classes, we get the following sayings that reveals everything:
    non-generic Stack.Contains(): this method determines equality by calling Object.Equals.
    generic Stack<T>.Contains(): this method determines equality using the default equality comparer EqualityComparer<T>.Default for T, the type of values in the list.
    If we use a non-generic Stack class, our only choice is overriding Equals() in the class of our object, as Andy ONeill mentioned before. But if we use non-generic Stack<T>, .NET team generously favored us one other tiny choice. We can implement the
    IEquatable<T> interface in our class that has an Equals() method and implement the algorithm of our new equality comparison in this Equals() method. Why we should do that? Because that is what EqualityComparer<T>.Default does! See MSDN documentation
    again:
    https://msdn.microsoft.com/en-us/library/ms224763(v=vs.110).aspx
    The Default property
    checks whether type T implements
    the System.IEquatable<T> interface
    and, if so, returns an EqualityComparer<T> that
    uses that implementation. Otherwise, it returns an EqualityComparer<T> that
    uses the overrides of Object.Equals and Object.GetHashCode provided
    by T.
    Although this explanation is a little misleading or vague, simply put it says, the Default property returns a comparer object that checks whether the objects being compared have implemented IEquatable<T> interface or not. If so, it uses the implemented
    Equals() of that interface in the objects, otherwise it resorts to the intrinsic Equals() method that is inherited to all objects from the object, father of all, base type.
    This IEqualityComparer<T>.Default object and that IEquatable<T> interface together help not to corrupt the innate Equals() methods of our classes.
    However, as good as what .NET team might have thought by favoring us using an IEqualityComparer<T>.Default in the Contains() method of the non-generic Stack<T> class, their solution is far from what is expected. Because again it stucks us to
    the first problem. We have only one and only one chance to define an equality comparison algorithm in our class. Naturally we can't implement an IEquatable<T> interface multiple times in our class.
    The tiny problem is that, they missed adding a new constructor in Stack<T> class that accepts an IEqualityComparer<T> like what they have done in Dictionary<TKey, TValue>. This is a shame. Because this is not a rare occasion. The same is
    true for some other collections such as Queue<T>, HashSet<T>, LinkedList<T> and List<T>. I don't know whether they have did this intentionally or they simply forgot to do that.
    So what? What should we do if we had multiple equality testing algorithms.
    Fortunatey there is still hope.
    If .NET team working on generic collections were that lazy to forget adding new constructors to generic classes, they did a good job and solved the problem from the root by adding a bunch of extension methods to all IEnumerable, IEnumerable<T> collections
    in System.Linq namspace and freed themselves forever. Look at the following extension methods in System.Linq namespace:
    public static bool Contains<TSource>(
    this IEnumerable<TSource> source,
    TSource value,
    IEqualityComparer<TSource> comparer
    You got the idea? They defined a general Contains() method for any IEnumerable<T> collection that allows us to give it a custom equality comparer object. Hooray! Problem solved. But wait. Why should we be happy? That comparer parameter might still
    use IEquatable<T> and presumes the objects have an Equals() method! Oh my gush! Still returned to the same point and the problem exists. We stuck forever! Don't freak out. Be calm.
    The IEqualityComparer<T> interface is defined this way:
    public interface IEqualityComparer<in T>
    bool Equals(T x, T y);
    int GetHashCode(T obj);
    It says, an equality comparer should have an Equals() method and it is in this very method that the equality comparison algorithm will go. This method receives two objects and compares them together using whatever algorithm the creator of the equality comparer
    class has intended.
    The good point of this IEqualityComparer<T> and that Contains<T>() extension method is that, your objects are not expected to implement an IEquatable<T> as well. This is another good news. Because we are neither forced to override
    Equals() in our class and corrupt it, nor we have to implement IEquatable<T> in them. In fact, our classes remain clean and intact and we even don't have to have their source code.
    So, this was the final cure for the malignant issue of equality comparison. The same story is true for less than/greater than comparison.
    In conclusion, what I recommend is that, never override the intrinsic Equals() method, inherited from Object, in your classes. Instead use the extension methods that has a comparer parameter in their signature and receive a comparer object (like Contains<T>()).
    I don't want to again raise a depression air here. But you should know that. You have the right. All extension methods does not have an overload that has a comparer parameter. But don't worry. You can yourself write the required extension method you need and
    complete the probably incomplete work in .NET.
    Good luck

  • Ichat problems over apple network

    We have 2 WDS network participating airport express base stations connected to the internet via Comcast cable. The network is really fast and we never had a problem with multi-way video chatting inside or outside the house.
    Now that the family upgraded to leopard, we can't screen share via AIM or bonjour (connection doctor says we don't have capabilities because the network is too slow. We can video chat and it's extremely fast, but when I enabled the effects, we were disconnected.
    It seams that 2 mac laptops connected with the latest software over a relatively standard apple network should work...

    Hi
    Set the Quicktime streaming setting, goto sys prefs/quicktime/streaming/streaming speed, set to 1.5mbps(dont use automatic)
    In ichats prefs click on video and change bandwidth limit to 500.
    Restart iChat.
    Tony

  • Macmini 2010 sound problem over hdmi

    Hi, my name is Diego im from Argentina, well i have a problem with my macmini 2010 unibody, i have set up the mini over hdmi in to my receiver ( yamaha 663 ) and hdmi out to my LCDTV, i set up in sound properties HDMI output ok all is fine but if i am listening music in itunes and turn off the tv the signal is off to receiver and the music sounds in the built in speaker of the mac mini, any idea to disable this speakers o built sound card ? i want to passtrough over hdmi with the TV off, thanks to all best regards, Diego.-

    I still get daleks too from time to time if I try to use 1080i with Dolby Digital into a Sony Bravia.
    The BT Vision box HDMI is known to be flaky, though it sounds like you've got an extreme example of the problem with the Tosh.
    It's possible to improve things a bit by using an HDMI extender to recondition the signal before it enters the TV. It might be worth a try. Try http://www.hdcable.co.uk/

  • Problem over VAN starting IR and ID

    hello experts
    I am facing a problem starting XI server over VAN. Everytime i have to manually add the domain name in the URL to start IR and ID.
    Moreover i am not able to get JAR file through java web start.
    Can anybody please solve this problem.

    Hello Deepanjali
    We also faced the same problem. All we did was very simple.
    just maintain an entry in the ETC\HOST file (system32\drivers\etc\hosts) as your server name = complete path.
    also check your java version, try downloading JRE 1.4
    I hope it would solve your problem.

  • ClassLoader problems over IIOP

    I'm currently porting our application from WebSphere to WebLogic and I have got the following issue concerning class loading on the client side:
    org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 211 completed: Maybe
         at com.sun.corba.se.impl.logging.ORBUtilSystemException.valuehandlerReadException(ORBUtilSystemException.java:6500)
         at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1045)
         at com.sun.corba.se.impl.encoding.CDRInputStream.read_value(CDRInputStream.java:253)
         at com.j2fe.general.interfaces._RegistryBeanRemote_Stub.getFacade(Ljava.lang.String;)Lcom.j2fe.general.HibernateFacade;(Unknown Source)
         at com.j2fe.ui.base.model.GSApplication.setAdditionalFacadeProxies(GSApplication.java:505)
         at com.j2fe.ui.base.model.GSApplicationServerConnectionParser$1.run(GSApplicationServerConnectionParser.java:289)
         at javax.security.auth.Subject.doAs(Subject.java:337)
         at com.ibm.websphere.security.auth.WSSubject.doAs(WSSubject.java:118)
         at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
         at com.j2fe.ui.base.model.GSApplicationServerConnectionParser.createApplication(GSApplicationServerConnectionParser.java:320)
         at com.j2fe.ui.base.jobs.ConnectAndParseJob.run(ConnectAndParseJob.java:97)
         at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)
    Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
         at com.sun.corba.se.impl.io.ObjectStreamClass.readResolve(ObjectStreamClass.java:316)
         at com.sun.corba.se.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:403)
         at com.sun.corba.se.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:327)
         at com.sun.corba.se.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:293)
         at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1034)
         ... 10 more
    Caused by: java.lang.reflect.InvocationTargetException
         at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
         at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
         at com.sun.corba.se.impl.io.ObjectStreamClass.readResolve(ObjectStreamClass.java:314)
         ... 14 more
    Caused by: java.lang.ClassNotFoundException
         at weblogic.iiop.ProxyDesc.readResolve(ProxyDesc.java:47)
         ... 17 more
    Caused by: java.lang.IllegalArgumentException: interface com.j2fe.general.HibernateFacade is not visible from class loader
         at java.lang.reflect.Proxy.getProxyClass(Proxy.java:345)
         at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:564)
         at weblogic.iiop.ProxyDesc.readResolve(ProxyDesc.java:45)
         ... 17 more
    Is it a problem for WebLogic to transfere Proxy classes over IIOP? The com.j2fe.general.HibernateFacade-interface is available on client side and can be loaded by the application class loader (which is an Eclipse application).
    The strange thing is that it's possible to do a Class.forName with that class immediately before and after the EJB-call which should get that proxy class from the server.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Thomas Brandl <> writes:
    Proxy is only supported in 9.x, this looks like a trace from 8.1
    andy
    I'm currently porting our application from WebSphere to WebLogic and I have got the following issue concerning class loading on the client side:
    org.omg.CORBA.MARSHAL: vmcid: SUN minor code: 211 completed: Maybe
         at com.sun.corba.se.impl.logging.ORBUtilSystemException.valuehandlerReadException(ORBUtilSystemException.java:6500)
         at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1045)
         at com.sun.corba.se.impl.encoding.CDRInputStream.read_value(CDRInputStream.java:253)
         at com.j2fe.general.interfaces._RegistryBeanRemote_Stub.getFacade(Ljava.lang.String;)Lcom.j2fe.general.HibernateFacade;(Unknown Source)
         at com.j2fe.ui.base.model.GSApplication.setAdditionalFacadeProxies(GSApplication.java:505)
         at com.j2fe.ui.base.model.GSApplicationServerConnectionParser$1.run(GSApplicationServerConnectionParser.java:289)
         at javax.security.auth.Subject.doAs(Subject.java:337)
         at com.ibm.websphere.security.auth.WSSubject.doAs(WSSubject.java:118)
         at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
         at com.j2fe.ui.base.model.GSApplicationServerConnectionParser.createApplication(GSApplicationServerConnectionParser.java:320)
         at com.j2fe.ui.base.jobs.ConnectAndParseJob.run(ConnectAndParseJob.java:97)
         at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)
    Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
         at com.sun.corba.se.impl.io.ObjectStreamClass.readResolve(ObjectStreamClass.java:316)
         at com.sun.corba.se.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:403)
         at com.sun.corba.se.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:327)
         at com.sun.corba.se.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:293)
         at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1034)
         ... 10 more
    Caused by: java.lang.reflect.InvocationTargetException
         at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava.lang.Object;[Ljava.lang.Object;)Ljava.lang.Object;(Unknown Source)
         at java.lang.reflect.Method.invoke(Ljava.lang.Object;[Ljava.lang.Object;I)Ljava.lang.Object;(Unknown Source)
         at com.sun.corba.se.impl.io.ObjectStreamClass.readResolve(ObjectStreamClass.java:314)
         ... 14 more
    Caused by: java.lang.ClassNotFoundException
         at weblogic.iiop.ProxyDesc.readResolve(ProxyDesc.java:47)
         ... 17 more
    Caused by: java.lang.IllegalArgumentException: interface com.j2fe.general.HibernateFacade is not visible from class loader
         at java.lang.reflect.Proxy.getProxyClass(Proxy.java:345)
         at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:564)
         at weblogic.iiop.ProxyDesc.readResolve(ProxyDesc.java:45)
         ... 17 more
    Is it a problem for WebLogic to transfere Proxy classes over IIOP? The com.j2fe.general.HibernateFacade-interface is available on client side and can be loaded by the application class loader (which is an Eclipse application).
    The strange thing is that it's possible to do a Class.forName with that class immediately before and after the EJB-call which should get that proxy class from the server.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Interactive report performance problem over database link

    Hi gurus,
    I have an interactive report that retrieves values from two joined tables both placed on the same remote database. It takes 45 seconds to populate (refresh) a page after issuing a search. If I catch the actual select that is generated by apex ( the one with count(*) over ()...) and run it from sql environment, it takes 1 or 2 seconds. What on earth does consume the rest of the time and how to speed this up? I would like to awoid creating and maintaining local materialized views if possible.
    Regards
    Samo

    Hi
    APEX normally needs to return the full result set for the purposes of pagination (where you have it set to something along the lines of show x-y of z), changing this or the max row count can affect performance greatly.
    The driving site hint would need to refer to the name of the view, but can be a bit temperamental with this kind of thing. The materialize hint only works for sub-factored queries (in a 'WITH blah AS(SELECT /*+ MATERIALIZE */ * FROM etc. etc.)). They tend to materialize anyway and its best not to use hints like that for production code unless there is absolutely no other option, but just sub factoring without hints can often have a profound effect on performance. For instance
    WITH a AS
    SELECT c1,
            c2,
            c3,
            c4,
            c5
    FROM schema1.view1)
    , b AS
    SELECT c1,
            c2,
            c3
    FROM schema1.view2)
    SELECT *
    FROM a, b
    WHERE a.c5 = b.c3May produce a different plan or even just sub factoring one of the external tables may have an effect.
    You need to try things out here and experiment and keep looking at the execution plans. You should also change Toads row fetch setting to be all 9's to get a real idea of performance.
    Let me know how you get on.
    Cheers
    Ben
    http://www.munkyben.wordpress.com
    Don't forget to mark replies helpful or correct ;)
    Edited by: Munky on Sep 29, 2009 1:41 PM

Maybe you are looking for

  • Windows 8.1 RT or full Windows 8.1 on HP Stream 8 5901?

    What version of Windows 8.1 is on the new HP Stream 8 tablet,  product #K4F55UA#ABA?

  • Every time I try to restore my phone i get error 3149?

    I've done everything suggested in the online help category for error codes, my internet connection is working very well, my usb cable connections are fine, I don't know what else to do to get rid of this error so i can restore my I.O.S on i tunes, an

  • Need to decommission a Windows 2003 server....

    I have a Windows 2003 DC with all the FSMO roles.  It was the first DC of the domain I also have 3 other DCs that are Windows 2008 R2.   All of the DCs are global catalogs.   DHCP Server is running on the Windows 2003 DC.   All of the DCs run DNS Ser

  • Oops in abap

    •     Create an ABAP program (e.g. an executable program). •     Define a (local) class CL_FLIGHT_DATA that cannot be instantiated outside the class and contains a private internal table attribute of line type SPFLI, which is filled during instance c

  • Alert Configuration and Alert Inbox Does Not Show Up

    Hello All, We are having a strange problem regarding alerts in XI. We are on NW2004s XI 7.0 SP 9. The TCode 'ALRTCATDEF' works fine. But when we go for configuring alerts in RWB, it says '404 Not Found: The requested resource does not exist'. Can any