package domain;

import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef;

import java.util.HashSet;
import java.util.Set;

@FilterDef(name="firstOrLastName", parameters=@ParamDef(name="name", type="string"))
@Filter(name="firstOrLastName", condition="firstName LIKE :name OR lastName like :firstName")
public class ContactGroup {

    private long groupId;
    private String groupName;
    private Set<Contact> contacts = new HashSet<>();

    public ContactGroup() {
    }
	public ContactGroup(long groupId) {
		this.groupId = groupId;
	}

    public ContactGroup(long groupId, String groupName) {
        this.groupId = groupId;
        this.groupName = groupName;
    }

    public ContactGroup(long groupId, String groupName, Set<Contact> contacts) {
        this.groupId = groupId;
        this.groupName = groupName;
        this.contacts = contacts;
    }

    public long getGroupId() {
        return groupId;
    }

    public void setGroupId(long groupId) {
        this.groupId = groupId;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public Set<Contact> getContacts() {
    	return this.contacts;
    }

	public void setContacts(Set<Contact> contacts) {
		this.contacts = contacts;
	}

	public void addContact(Contact contact) {
		contacts.add(contact);
		if (!contact.isMemberOfGroup(this))
			contact.addBook(this);
	}

	public void removeContact(Contact contact) {
		contacts.remove(contact);
		if (!contact.isMemberOfGroup(this))
			contact.removeBook(this);
	}

	public Boolean hasContact(Contact contact) {
		return contacts.contains(contact);
	}

	@Override
	public int hashCode() {
		return (int) this.groupId;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (obj instanceof ContactGroup) {
			if (((ContactGroup) obj).getGroupId() == this.groupId)
				return true;
		}
		return false;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("ContactGroup {\n").append("id=").append(groupId);
		sb.append("groupName=").append(groupName).append("\n");
		sb.append("contacts = [\n");
		for (Contact c : contacts) {
			sb.append("id: ").append(c.getId()).append(", ")
				.append(c.getFullName()).append(",\n");
		}
		sb.append("]}\n");
		return sb.toString();
	}
}

@@ -21,357 +21,49 @@
 ort 
-org.hibernate.annotations.Filter;%0Aimport org.hibernate.annotations.FilterDef;%0Aimport org.hibernate.annotations.ParamDef;%0A%0Aimport java.util.HashSet;%0Aimport java.util.Set;%0A%0A@FilterDef(name=%22firstOrLastName%22, parameters=@ParamDef(name=%22name%22, type=%22string%22))%0A@Filter(name=%22firstOrLastName%22, condition=%22firstName LIKE :name OR lastName like :firstName%22)
+java.util.HashSet;%0Aimport java.util.Set;%0A
 %0Apub

Remove old annotations in ContactGroup class