Finding matching objects in Java -


i'm trying match 2 objects based on values. except, it's not a.a = a.a, a.a = a.b , a.b = b.a. means overriding equals option it's not right option.

while sorting these objects make matching time quicker, population small unnecessary. also, compareto isn't right either same reason given equals.

do make own method in case? there 4 fields match why not using if statement front.

public boolean isopposite(object other) {     return (this.a == other.b) ? true : false; } 

there possibility object implement/extend base object take on more fields , implement own way of matching.

i'm considering using linkedlist because know quicker use arraylist, i've been considering maps. edit: better explanation of objects

    public class obj {      public string a;      public string b;      public string c;      public double d;     } 

the relationships follows:

    obj obj1, obj2; obj1.a == obj2.b //.equals string of course obj1.b == obj2.a obj1.c == obj2.c obj1.d == obj2.d * -1 

overriding equals or compareto not right way go, you've mentioned. because there assumption both methods should transitive, i.e. a eq b , b eq c => eq c doesn't hold "opposite" objects. it's know, because can't define equivalence class , partition subsets, need find pairs (depending on use case).

not sure, goal. if have containers such objects , need find pairs suffice condition, afraid you'd need n^2 comparisons.

i'll create 2 hash sets, 1 originals , second opposites , ask if second hash set contains opposite of each member of original hash set.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -