Java tutorial
/* * Copyright (C) 2015 Tim R. Coulson * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.timrcoulson.gymbro.entity; import com.j256.ormlite.field.DatabaseField; import org.apache.commons.lang3.builder.EqualsBuilder; import java.util.Iterator; import java.util.List; /* * Abstract class for sessions. */ public abstract class Session { private static final String TAG = Session.class.getName(); @DatabaseField(generatedId = true) public int id; @DatabaseField public String name; @DatabaseField(columnName = "order") public int order; public Session() { } public abstract List<? extends Exercise> getExercises(); @Override public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof Session)) return false; Session session = (Session) obj; if (!(new EqualsBuilder().append(name, session.name).append(order, session.order).isEquals())) return false; if (!(session.getExercises().size() == this.getExercises().size())) return false; Iterator<? extends Exercise> exerciseIterator = session.getExercises().iterator(); for (Exercise exercise : this.getExercises()) { if (!exerciseIterator.next().equals(exercise)) return false; } return true; } }