/** * Package a {@link org.litepal.tablemanager.model.AssociationsModel}, and add it into {@link * #mAssociationModels} Collection. * * @param className The class name for {@link org.litepal.tablemanager.model.AssociationsModel}. * @param associatedClassName The associated class name for {@link * org.litepal.tablemanager.model.AssociationsModel}. * @param classHoldsForeignKey The class which holds foreign key. * @param associationType The association type for {@link * org.litepal.tablemanager.model.AssociationsModel}. */ private void addIntoAssociationModelCollection( String className, String associatedClassName, String classHoldsForeignKey, int associationType) { AssociationsModel associationModel = new AssociationsModel(); associationModel.setTableName(DBUtility.getTableNameByClassName(className)); associationModel.setAssociatedTableName(DBUtility.getTableNameByClassName(associatedClassName)); associationModel.setTableHoldsForeignKey( DBUtility.getTableNameByClassName(classHoldsForeignKey)); associationModel.setAssociationType(associationType); mAssociationModels.add(associationModel); }
/** * Override equals method to make sure that if two associated tables in the association model are * same ignoring sides, they are same association model. */ @Override public boolean equals(Object o) { if (o instanceof AssociationsModel) { AssociationsModel association = (AssociationsModel) o; if (association.getTableName() != null && association.getAssociatedTableName() != null) { if (association.getAssociationType() == associationType && association.getTableHoldsForeignKey().equals(tableHoldsForeignKey)) { if (association.getTableName().equals(tableName) && association.getAssociatedTableName().equals(associatedTableName) && association.getTableHoldsForeignKey().equals(tableHoldsForeignKey)) { return true; } else if (association.getTableName().equals(associatedTableName) && association.getAssociatedTableName().equals(tableName) && association.getTableHoldsForeignKey().equals(tableHoldsForeignKey)) { return true; } } } } return false; }