Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8520793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:37:50+00:00 2026-06-11T06:37:50+00:00

Trying to understand the results I am getting from object equality … Ok first

  • 0

Trying to understand the results I am getting from object equality …
Ok first let me describe the problem
need to filter duplicates objects from two two tables from db (Hibenate all of the cluses are set up) preset condition is firstName, lastName, dateOfbirth

package com.equality.types;  

import com.google.common.base.Objects;  

import java.util.Date;  

public class AsignoreTypes{  
private String firstname;  
private String lastname;  
private Date doa;  

public String getFirstname() {  
    return firstname;  
}  

public void setFirstname(String firstname) {  
    this.firstname = firstname;  
}  

public String getLastname() {  
    return lastname;  
}  

public void setLastname(String lastname) {  
    this.lastname = lastname;  
}  

public Date getDoa() {  
    return doa;  
}  

public void setDoa(Date doa) {  
    this.doa = doa;  
}  


/*   @Override 
public boolean equals(Object obj) { 
    if (obj instanceof AsignoreTypes == false) { 
        return false; 
    } 

    if (this == obj) { 
        return true; 
    } 
    AsignoreTypes other = (AsignoreTypes) obj; 
    return new EqualsBuilder().append(this.firstname , other.firstname) 
            .append(this.lastname, other.lastname) 
            .append(this.doa , other.doa).isEquals(); 
} 

@Override 
public int hashCode() { 
    return new HashCodeBuilder().append(this.firstname) 
            .append(this.lastname) 
            .append(this.doa) 
            .hashCode(); 
} 
 */  
@Override  
public int hashCode(){  
    return Objects.hashCode(firstname, lastname, doa);  
}  

@Override  
public boolean equals(final Object obj){  
    if(obj instanceof AsignoreTypes){  
        final AsignoreTypes other = (AsignoreTypes) obj;  
           return Objects.equal(firstname, other.firstname)  
                &&Objects.equal(lastname, other.lastname)  
                && Objects.equal(doa, other.doa);  
    } else{  
        return false;  
    }  
}  

So in my service class I call Query on 2 tables and create object list Iterate over it

In one of the list creat a nested iteration anainst second list

So in my service class I call Query on 2 tables and create custom list Iterate over list and objects

So in my service class I call Query on 2 tables and create custom list Iterate over list and objects

Session session = service.getDataServiceManager().getSession();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Query query = session.createQuery("select upper(ass.firstName), upper(ass.lastName), ass.doa from AssignorInfo ass");
List < Object > ass1 = null;
ass1 = query.list();
List < AsignoreTypes > res1 = null;
res1 = new ArrayList < AsignoreTypes > ();
Iterator < Object > it = ass1.iterator();
while (it.hasNext()) {
        Object[] row = (Object[]) it.next();
AsignoreTypes ass = new AsignoreTypes();
if (row[0] != null) ass.setFirstname(row[0].toString());
if (row[1] != null) ass.setLastname(row[1].toString());
if (row[2] != null) ass.setDoa(formatter.parse(row[2].toString()));
res1.add(ass);
}
        log(INFO, "List one size " + res1.size());
Query q = session.createQuery("select upper(g.fname), upper(g.lname), g.doa from  GeneralInfo g where g.arbitrator like '%Bulel%' ");
List < Object > ass2 = null;
ass2 = q.list();
log(INFO, " Size from wizard " + ass2.size());
List < AsignoreTypes > res2 = null;
res2 = new ArrayList < AsignoreTypes > ();
Iterator < Object > iterator = ass2.iterator();
while (iterator.hasNext()) {
        Boolean f = null;
Object[] row = (Object[]) iterator.next();
AsignoreTypes ass = new AsignoreTypes();
if (row[0] != null) ass.setFirstname(row[0].toString());
if (row[1] != null) ass.setLastname(row[1].toString());
if (row[2] != null) ass.setDoa(formatter.parse(row[2].toString()));
for (AsignoreTypes a1: res1) {

        f = ass.equals(a1);
}
        if (f == false) {
        res2.add(ass);
log(INFO, "Got matchig element " + ass.getLastname());
}
        }
        log(INFO, "List tow size " + res2.size() + " List hash set size ");
HashSet < AsignoreTypes > asigors = new HashSet < AsignoreTypes > ();
HashSet < AsignoreTypes > wiz = new HashSet < AsignoreTypes > ();
asigors.addAll(res1);
wiz.addAll(res2);
wiz.removeAll(asigors);

log(INFO, "Added to hash set " + asigors.size());

log(INFO, "Added assignors to the list " + wiz.size());

So here is a part I dont undestand i implement equality method on the object but the equality returnus one or two matches…
2012-09-01 18:49:09,910 INFO [com.equality.service.CopareToServices] – (thread 1008 invoke CopareToServices.compareObjects)
Equality method only found a single duplicate record >>>

But when at the end I implement removeAll on the list the results

And this is after Implementing removeAll on the heshSet
2012-09-01 18:49:09,918 INFO [com.equality.service.CopareToServices] – (thread 1008 invoke CopareToServices.compareObjects)

171 Duplicates were removed which sound about right…

How come implementing removeAll on the list filters the list properly but equality method does not work

Tryed equals builder with apache commons too with the same output

Will Apriciate any help i can get
Sincerily

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:37:52+00:00Added an answer on June 11, 2026 at 6:37 am

    If I understand well, I think the problem is:

    for (AsignoreTypes a1: res1) {
        f = ass.equals(a1);
    }
    

    because this is like testing only the last element of res1.


    EDIT: proposal for correction:

    private List<AsignoreTypes> getAssignoreTypesList(final String sql) {
        final List<AsignoreTypes> result = new ArrayList<AsignoreTypes>();
        final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        final Session session = service.getDataServiceManager().getSession();
        final Query query = session.createQuery(sql);
        final List<?> rows = query.list();
        for (final Object row : rows) {
            final Object[] columns = (Object[]) row;
            final AsignoreTypes ass = new AsignoreTypes();
            ass.setFirstname((String) columns[0]);
            ass.setLastname((String) columns[1]);
            if (columns[2] != null) {
                try {
                    ass.setDoa(formatter.parse(columns[2].toString()));
                } catch (final ParseException e) {
                    // ignore?
                }
            }
            result.add(ass);
        }
    
        return result;
    }
    
    public void foo()
    {
        final List<AsignoreTypes> assignorInfos = getAsignoreTypesList("select upper(ass.firstName), upper(ass.lastName), ass.doa from AssignorInfo ass");
        log(INFO, "List one size " + assignorInfos.size());
    
        final List<AsignoreTypes> generalInfos = getAsignoreTypesList("select upper(g.fname), upper(g.lname), g.doa from  GeneralInfo g where g.arbitrator like '%Bulel%' ");
        log(INFO, "Size from wizard " + generalInfos.size());
    
        final List<AsignoreTypes> filtered = new ArrayList<AsignoreTypes>();
        for (final AsignoreTypes asignoreTypes : generalInfos) {
            if (!assignorInfos.contains(asignoreTypes)) {
                filtered.add(asignoreTypes);
                log(INFO, "Got matching element " + asignoreTypes.getLastname());
            }
        }
    
        log(INFO, "Filtered : " + filtered.size() + "/" + generalInfos.size());
    }
    

    see List#contains(Object)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to understand different ways of getting table data from Oracle stored procedures
I have been trying to understand how to return links from yql results, but
Trying to understand PNG format. Consider this PNG Image: The Image is taken from
I'm getting into LinqToSql and using the NerdDinner tutorial. I'm trying to understand the
I am trying to understand something about getTime() , My problem is that, I
I am trying understand ViewModels deeper and I have read many articles and blogs
Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.
Trying to understand the Deezer API. When I visit: http://connect.deezer.com/oauth/auth.php?app_id=MY_APP_ID&redirect_uri=http://mydomain.me&perms=basic_access I end up at
Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
Trying to understand Ruby a bit better, I ran into this code surfing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.