algorithm - How can I efficiently compare a list of objects' fields and display in JSF -


i have list of quite detailed objects compare:

list<myobject> objectstocompare; 

in objects there many fields object, string, int, list, etc.

i need present user table representation of these objects , fields using jsf this:

field    object1     object2    object3...  equal name     fred        john       george...   no age      26          26         26...       yes 

here's have planned far jsf page:

<p:panelgrid >         <f:facet name="header">             <p:row>                 <p:column>field</p:column>                 <ui:repeat var="loopobject" value="#{compareobjectsbean.objectsforcomparison}">                     <p:column><h:outputtext value="#{loopobject.id}" /></p:column>                 </ui:repeat>                 <p:column>all objects equal</p:column>             </p:row>         </f:facet>         <p:row>             <p:column>name</p:column>                 <ui:repeat var="loopobject" value="#{compareobjectsbean.objectsforcomparison}">                 <p:column><h:outputtext value="#{loopobject.name}" /></p:column>             </ui:repeat>             <p:column><h:outputtext value="#{compareobjectscontroller.namesequal()?'yes':'no'}"/> </p:column>         </p:row>         <p:row>             <p:column>age</p:column>                 <ui:repeat var="loopobject" value="#{compareobjectsbean.objectsforcomparison}">                 <p:column><h:outputtext value="#{loopobject.age}" /></p:column>             </ui:repeat>             <p:column><h:outputtext value="#{compareobjectscontroller.agesequal()?'yes':'no'}"/> </p:column>         </p:row> 

and example in compareobjectscontroller comparison method each field:

public boolean namesequal(){         string firstobjectname = compareobjectsbean.getobjectsforcomparison().get(0).getname();         for(int = 1; i< compareobjectsbean.getobjectsforcomparison().size(); i++){             if(!compareobjectsbean.getobjectsforcomparison().get(i).getname().equals(firstobjectname)){                 return false;             }         }         return true;//all matched first, equal     } 

this doesn't seem efficient, when objects being compared have approx 300 fields (includes fields of objects belonging myobject).

how can optimise/optimize not need write ~300 comparison methods in controller, , possibly ~300 rows?

note: using primefaces, simple table.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -