/*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/ package example; import java.util.*; // line 3 "../EqualsTest.ump" public class Student { //------------------------ // MEMBER VARIABLES //------------------------ //Student Attributes private int intId; private double doubleId; private boolean booleanId; private String stringId; private List<String> stringListIds; //Helper Variables private int cachedHashCode; private boolean canSetIntId; private boolean canSetDoubleId; private boolean canSetBooleanId; private boolean canSetStringId; private boolean canSetStringListIds; //------------------------ // CONSTRUCTOR //------------------------ public Student(int aIntId, double aDoubleId, boolean aBooleanId, String aStringId) { cachedHashCode = -1; canSetIntId = true; canSetDoubleId = true; canSetBooleanId = true; canSetStringId = true; canSetStringListIds = true; intId = aIntId; doubleId = aDoubleId; booleanId = aBooleanId; stringId = aStringId; stringListIds = new ArrayList<String>(); } //------------------------ // INTERFACE //------------------------ public boolean setIntId(int aIntId) { boolean wasSet = false; if (!canSetIntId) { return false; } intId = aIntId; wasSet = true; return wasSet; } public boolean setDoubleId(double aDoubleId) { boolean wasSet = false; if (!canSetDoubleId) { return false; } doubleId = aDoubleId; wasSet = true; return wasSet; } public boolean setBooleanId(boolean aBooleanId) { boolean wasSet = false; if (!canSetBooleanId) { return false; } booleanId = aBooleanId; wasSet = true; return wasSet; } public boolean setStringId(String aStringId) { boolean wasSet = false; if (!canSetStringId) { return false; } stringId = aStringId; wasSet = true; return wasSet; } /* Code from template attribute_SetMany */ public boolean addStringListId(String aStringListId) { boolean wasAdded = false; if (!canSetStringListIds) { return false; } wasAdded = stringListIds.add(aStringListId); return wasAdded; } public boolean removeStringListId(String aStringListId) { boolean wasRemoved = false; if (!canSetStringListIds) { return false; } wasRemoved = stringListIds.remove(aStringListId); return wasRemoved; } public int getIntId() { return intId; } public double getDoubleId() { return doubleId; } public boolean getBooleanId() { return booleanId; } public String getStringId() { return stringId; } /* Code from template attribute_GetMany */ public String getStringListId(int index) { String aStringListId = stringListIds.get(index); return aStringListId; } public String[] getStringListIds() { String[] newStringListIds = stringListIds.toArray(new String[stringListIds.size()]); return newStringListIds; } public int numberOfStringListIds() { int number = stringListIds.size(); return number; } public boolean hasStringListIds() { boolean has = stringListIds.size() > 0; return has; } public int indexOfStringListId(String aStringListId) { int index = stringListIds.indexOf(aStringListId); return index; } /* Code from template attribute_IsBoolean */ public boolean isBooleanId() { return booleanId; } public boolean equals(Object obj) { if (obj == null) { return false; } if (!getClass().equals(obj.getClass())) { return false; } Student compareTo = (Student)obj; if (getIntId() != compareTo.getIntId()) { return false; } if (getDoubleId() != compareTo.getDoubleId()) { return false; } if (getBooleanId() != compareTo.getBooleanId()) { return false; } if (getStringId() == null && compareTo.getStringId() != null) { return false; } else if (getStringId() != null && !getStringId().equals(compareTo.getStringId())) { return false; } if (getStringListIds().length != compareTo.getStringListIds().length) { return false; } for (int i=0; i<getStringListIds().length; i++) { String me = getStringListIds()[i]; String them = compareTo.getStringListIds()[i]; if (me == null && them != null) { return false; } else if (me != null && !me.equals(them)) { return false; } } return true; } public int hashCode() { if (cachedHashCode != -1) { return cachedHashCode; } cachedHashCode = 17; cachedHashCode = cachedHashCode * 23 + getIntId(); cachedHashCode = cachedHashCode * 23 + (Double.valueOf(getDoubleId())).hashCode(); cachedHashCode = cachedHashCode * 23 + (getBooleanId() ? 1 : 0); if (getStringId() != null) { cachedHashCode = cachedHashCode * 23 + getStringId().hashCode(); } else { cachedHashCode = cachedHashCode * 23; } if (getStringListIds() != null) { cachedHashCode = cachedHashCode * 23 + getStringListIds().hashCode(); } else { cachedHashCode = cachedHashCode * 23; } canSetIntId = false; canSetDoubleId = false; canSetBooleanId = false; canSetStringId = false; canSetStringListIds = false; return cachedHashCode; } public void delete() {} public String toString() { return super.toString() + "["+ "stringId" + ":" + getStringId()+ "," + "booleanId" + ":" + getBooleanId()+ "," + "doubleId" + ":" + getDoubleId()+ "," + "intId" + ":" + getIntId()+ "]"; } } /*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/ package example; // line 3 "../EqualsTest_AlreadyImmutable.ump" public class Student { //------------------------ // MEMBER VARIABLES //------------------------ //Student Attributes private int intId; private double doubleId; private boolean booleanId; private String stringId; //Helper Variables private int cachedHashCode; private boolean canSetIntId; //------------------------ // CONSTRUCTOR //------------------------ public Student(double aDoubleId, boolean aBooleanId, String aStringId) { cachedHashCode = -1; canSetIntId = true; doubleId = aDoubleId; booleanId = aBooleanId; stringId = aStringId; } //------------------------ // INTERFACE //------------------------ /* Code from template attribute_SetImmutable */ public boolean setIntId(int aIntId) { boolean wasSet = false; if (!canSetIntId) { return false; } canSetIntId = false; intId = aIntId; wasSet = true; return wasSet; } public int getIntId() { return intId; } public double getDoubleId() { return doubleId; } public boolean getBooleanId() { return booleanId; } public String getStringId() { return stringId; } /* Code from template attribute_IsBoolean */ public boolean isBooleanId() { return booleanId; } public boolean equals(Object obj) { if (obj == null) { return false; } if (!getClass().equals(obj.getClass())) { return false; } Student compareTo = (Student)obj; if (getIntId() != compareTo.getIntId()) { return false; } if (getDoubleId() != compareTo.getDoubleId()) { return false; } if (getBooleanId() != compareTo.getBooleanId()) { return false; } if (getStringId() == null && compareTo.getStringId() != null) { return false; } else if (getStringId() != null && !getStringId().equals(compareTo.getStringId())) { return false; } return true; } public int hashCode() { if (cachedHashCode != -1) { return cachedHashCode; } cachedHashCode = 17; cachedHashCode = cachedHashCode * 23 + getIntId(); cachedHashCode = cachedHashCode * 23 + (Double.valueOf(getDoubleId())).hashCode(); cachedHashCode = cachedHashCode * 23 + (getBooleanId() ? 1 : 0); if (getStringId() != null) { cachedHashCode = cachedHashCode * 23 + getStringId().hashCode(); } else { cachedHashCode = cachedHashCode * 23; } canSetIntId = false; return cachedHashCode; } public void delete() {} public String toString() { return super.toString() + "["+ "stringId" + ":" + getStringId()+ "," + "booleanId" + ":" + getBooleanId()+ "," + "doubleId" + ":" + getDoubleId()+ "," + "intId" + ":" + getIntId()+ "]"; } } /*PLEASE DO NOT EDIT THIS CODE*/ /*This code was generated using the UMPLE 1.35.0.7523.c616a4dce modeling language!*/ package example; import java.util.*; // line 15 "../EqualsTest.ump" public class Mentor { //------------------------ // MEMBER VARIABLES //------------------------ //Mentor Associations private Course main; private List<Course> secondaries; //Helper Variables private int cachedHashCode; private boolean canSetMain; private boolean canSetSecondaries; //------------------------ // CONSTRUCTOR //------------------------ public Mentor() { cachedHashCode = -1; canSetMain = true; canSetSecondaries = true; secondaries = new ArrayList<Course>(); } //------------------------ // INTERFACE //------------------------ /* Code from template association_GetOne */ public Course getMain() { return main; } public boolean hasMain() { boolean has = main != null; return has; } /* Code from template association_GetMany */ public Course getSecondary(int index) { Course aSecondary = secondaries.get(index); return aSecondary; } public List<Course> getSecondaries() { List<Course> newSecondaries = Collections.unmodifiableList(secondaries); return newSecondaries; } public int numberOfSecondaries() { int number = secondaries.size(); return number; } public boolean hasSecondaries() { boolean has = secondaries.size() > 0; return has; } public int indexOfSecondary(Course aSecondary) { int index = secondaries.indexOf(aSecondary); return index; } /* Code from template association_SetOptionalOneToOptionalOne */ public boolean setMain(Course aNewMain) { boolean wasSet = false; if (!canSetMain) { return false; } if (aNewMain == null) { Course existingMain = main; main = null; if (existingMain != null && existingMain.getMentorMain() != null) { existingMain.setMentorMain(null); } wasSet = true; return wasSet; } Course currentMain = getMain(); if (currentMain != null && !currentMain.equals(aNewMain)) { currentMain.setMentorMain(null); } main = aNewMain; Mentor existingMentorMain = aNewMain.getMentorMain(); if (!equals(existingMentorMain)) { aNewMain.setMentorMain(this); } wasSet = true; return wasSet; } /* Code from template association_MinimumNumberOfMethod */ public static int minimumNumberOfSecondaries() { return 0; } /* Code from template association_AddManyToOptionalOne */ public boolean addSecondary(Course aSecondary) { boolean wasAdded = false; if (!canSetSecondaries) { return false; } if (secondaries.contains(aSecondary)) { return false; } Mentor existingMentorSecondary = aSecondary.getMentorSecondary(); if (existingMentorSecondary == null) { aSecondary.setMentorSecondary(this); } else if (!this.equals(existingMentorSecondary)) { existingMentorSecondary.removeSecondary(aSecondary); addSecondary(aSecondary); } else { secondaries.add(aSecondary); } wasAdded = true; return wasAdded; } public boolean removeSecondary(Course aSecondary) { boolean wasRemoved = false; if (!canSetSecondaries) { return false; } if (secondaries.contains(aSecondary)) { secondaries.remove(aSecondary); aSecondary.setMentorSecondary(null); wasRemoved = true; } return wasRemoved; } /* Code from template association_AddIndexControlFunctions */ public boolean addSecondaryAt(Course aSecondary, int index) { boolean wasAdded = false; if(addSecondary(aSecondary)) { if(index < 0 ) { index = 0; } if(index > numberOfSecondaries()) { index = numberOfSecondaries() - 1; } secondaries.remove(aSecondary); secondaries.add(index, aSecondary); wasAdded = true; } return wasAdded; } public boolean addOrMoveSecondaryAt(Course aSecondary, int index) { boolean wasAdded = false; if(secondaries.contains(aSecondary)) { if(index < 0 ) { index = 0; } if(index > numberOfSecondaries()) { index = numberOfSecondaries() - 1; } secondaries.remove(aSecondary); secondaries.add(index, aSecondary); wasAdded = true; } else { wasAdded = addSecondaryAt(aSecondary, index); } return wasAdded; } public boolean equals(Object obj) { if (obj == null) { return false; } if (!getClass().equals(obj.getClass())) { return false; } Mentor compareTo = (Mentor)obj; if (getMain() == null && compareTo.getMain() != null) { return false; } else if (getMain() != null && !getMain().equals(compareTo.getMain())) { return false; } if (getSecondaries().size() != compareTo.getSecondaries().size()) { return false; } for (int i=0; i<getSecondaries().size(); i++) { Course me = getSecondaries().get(i); Course them = compareTo.getSecondaries().get(i); if (me == null && them != null) { return false; } else if (me != null && !me.equals(them)) { return false; } } return true; } public int hashCode() { if (cachedHashCode != -1) { return cachedHashCode; } cachedHashCode = 17; if (getMain() != null) { cachedHashCode = cachedHashCode * 23 + getMain().hashCode(); } else { cachedHashCode = cachedHashCode * 23; } if (getSecondaries() != null) { cachedHashCode = cachedHashCode * 23 + getSecondaries().hashCode(); } else { cachedHashCode = cachedHashCode * 23; } canSetMain = false; canSetSecondaries = false; return cachedHashCode; } public void delete() { if (main != null) { main.setMentorMain(null); } while( !secondaries.isEmpty() ) { secondaries.get(0).setMentorSecondary(null); } } }