I am checking if ArrayList contains object:
List<Property> propertiesByName = getPropertiesByCategory(propertyCategory);
for(Property property: propertiesByName){
List<Property> propertyList = getVariationItem().getProperties();
Galgo.log("*******************");
Galgo.log(propertyList.toString());
Galgo.log(property.toString());
Galgo.log("contains:"+propertyList.contains(property));
}
I am getting following log:
*******************
[Property{name='color', value='red'}, Property{name='size', value='42'}]
Property{name='color', value='red'}
contains:false
*******************
[Property{name='color', value='red'}, Property{name='size', value='42'}]
Property{name='color', value='blue'}
contains:false
Database: get 2 variations
*******************
[Property{name='color', value='red'}, Property{name='size', value='42'}]
Property{name='size', value='42'}
contains:false
*******************
[Property{name='color', value='red'}, Property{name='size', value='42'}]
Property{name='size', value='34'}
contains:false
As you can see in the first and third cases, it should return true. What is wrong?
Other parts of my code. First method to get properties by category(color, size). Second method is to get all available properties:
private List<Property> getPropertiesByCategory(String category){
List<Property> properties = new ArrayList<>();
for(Property property: getAllProperties()){
if(property.getName().equals(category)){
if(!properties.contains(property)){
properties.add(property);
}
}
}
return properties;
}
private List<Property> getAllProperties() {
List<Property> propertyList = new ArrayList<>();
for(VariationItem variationItem: getProductItem().getVariationsList()){
for(Property property: variationItem.getProperties()){
if(!propertyList.contains(property))
{
propertyList.add(property);
}
}
}
return propertyList;
}