Hash Map Object Key

If you would move the declaration of your array into the for loop all would go as expected. The problem is now that all your Design instances have the same array.

for(int i=0; i<5; i++){
    double[] dbl = new double[2];
    for(int j=0; j<2; j++){
        System.out.println(j+i);
        dbl[j] = j+i;
    }
    Design des = new Design(dbl);
    map.put(des, Double.valueOf(i));
}

Furthermore, your equals method will yield to incorrect results when you have a subclass of Design. Instead of using instanceof, compare the classes. So change

if (!(obj instanceof Design))
        return false;

to

if (!(obj.getClass() == getClass() ) )
  return false;

This is however unrelated to your problem

Answer:1

You are not copying your double[] factors array in the setFactors and the constructor. That is why all instances of the key class end up sharing the same array that you modify in the loop.

You should change setFactors as follows:

public void setFactors(double[] factors) {
    this.factors = new double[factors];
    System.arrayCopy(factors, 0, this.factors, 0, factors.length);
}

public Design(double[] factors) {
    setFactors(factors);
}
Answer:2

The problem is you're using the same array of doubles for all the instances you create of Design. When you initialize the next numbers in the main loop, you're modifying the first object again. Try this:

public double[] getFactors() {
    return factors.clone();
}

public void setFactors(double[] factors) {
    this.factors = factors.clone();
}

public Design(double[] factors) {
    setFactors(factors);
}

Or, if that would have a performance overhead that's not acceptable in your application, just be very careful about how you use the arrays passed to setFactors and the return value of getFactors.

Answer:3

I didn't understand why I am getting empty list from criteria, and I have data in my table. code where I'm getting List: hibernateSession_destination = HibernateUtilReports.INSTANCE.getSession(); ...

I've recently began using EHCache for caching purposes. I know, how to use it in Java code, but I'm still not sure about the configuration file. So, I have an ear project, that includes several war ...

I have two questions(problems actually) while parsing the html page using HtmlUnit.I tried their 'Getting Started` as well as searched google but no help.Here is my first problem. 1) I want to ...

I had done the development of my Java EE backend application, which using Hibernate JPA and JAX-RS. Time to deploy into production server. Currently, the generation of database schema is done by ...