/** * Tests XmlDirectCollectionMapping configuration via eclipselink-oxm.xml. Here an unmarshal * operation is performed. * * <p>Positive test. */ public void testDirectCollectionUnmarshal() { // load instance doc String src = PATH + "employee.xml"; InputStream iDocStream = loader.getResourceAsStream(src); if (iDocStream == null) { fail("Couldn't load instance doc [" + src + "]"); } // tweak control object Employee ctrlEmp = getControlObject(); // unmarshal null will result in "" being set in the object ctrlEmp.projectIds.remove(1); ctrlEmp.projectIds.add(1, ""); // 'privateData' is write only ctrlEmp.privateData = null; try { Employee empObj = (Employee) jaxbContext.createUnmarshaller().unmarshal(iDocStream); assertNotNull("Unmarshalled object is null.", empObj); assertTrue("Accessor method was not called as expected", empObj.wasSetCalled); assertTrue("Unmarshal failed: Employee objects are not equal", ctrlEmp.equals(empObj)); } catch (JAXBException e) { e.printStackTrace(); fail("Unmarshal operation failed."); } }
public static ProjectParams fromStdIn() throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int numTeams = Integer.parseInt(in.readLine()); // System.out.println("Reading in " + numTeams + " teams..."); List<Team> teams = new ArrayList<Team>(numTeams); List<Set<Employee>> employees = new ArrayList<Set<Employee>>(NUM_LOCATIONS); employees.add(new HashSet<Employee>()); employees.add(new HashSet<Employee>()); String currLine = in.readLine(); // Could use while on readLine(), but this handles empty lines at the end better for (int currTeam = 0; currTeam < numTeams; currTeam++) { String[] idStrings = currLine.split(" "); assert (idStrings.length == 2); Employee e1 = Employee.getEmployeeFromId(Integer.parseInt(idStrings[0])); Employee e2 = Employee.getEmployeeFromId(Integer.parseInt(idStrings[1])); assert (e1 != e2 && !e1.equals(e2)); employees.get(0).add(e1); employees.get(1).add(e2); teams.add(new Team(e1, e2)); currLine = in.readLine(); } in.close(); assert (teams.size() == uniqueTeams(teams)); return new ProjectParams(teams, employees); }
public static void main(String[] args) { int i = 10; int j = 10; if (i == j) { System.out.println("Equals"); } Employee e1 = new Employee(10); Employee e2 = new Employee(10); e1 = e2; if (e1 == e2) { System.out.println("Equals"); } System.out.println(e1.hashCode()); System.out.println(e2.hashCode()); if (e1.equals(e2)) { System.out.println("Employee Equals"); } String s1 = new String("ABC"); String s2 = "ABC"; if (s1.equals(s2)) { System.out.println("String Equals"); } System.out.println(e1.toString()); }
/** * Tests XmlAnyObjectMapping configuration via eclipselink-oxm.xml. Here an unmarshal operation is * performed. In this case, the 'any' is marked write-only, and should not be read in. * * <p>Positive test. */ public void testAnyObjectWriteOnlyUnmarshal() { // load instance doc String src = PATH + "write-only-employee.xml"; InputStream iDocStream = loader.getResourceAsStream(src); if (iDocStream == null) { fail("Couldn't load instance doc [" + src + "]"); } JAXBContext jCtx = null; try { jCtx = createContext( new Class[] {Employee.class}, CONTEXT_PATH, PATH + "write-only-employee-oxm.xml"); } catch (JAXBException e1) { fail("JAXBContext creation failed: " + e1.getMessage()); } // unmarshal Employee ctrlEmp = getControlObject(); ctrlEmp.stuff = null; Employee eObj = null; Unmarshaller unmarshaller = jCtx.createUnmarshaller(); try { eObj = (Employee) unmarshaller.unmarshal(iDocStream); assertNotNull("Unmarshalled object is null.", eObj); assertTrue("Unmarshal failed: Employee objects are not equal", ctrlEmp.equals(eObj)); } catch (JAXBException e) { e.printStackTrace(); fail("Unmarshal operation failed."); } }
boolean hasChanged() { Employee e = view.get(); if (e.isEmpty()) { return old != null && !old.isEmpty(); } else { return !e.equals(old); } }
public static void main(String[] args) { Employee ram1 = new Employee(1001, "Ram"); Employee ram2 = new Employee(1001, "Ram"); if (ram1.equals(ram2)) { System.out.println("Same"); } else { System.out.println("Not Same"); } }
public static void main(String[] args) throws CloneNotSupportedException { Department dept = new Department(1, "Human Resource"); Employee original = new Employee(dept, 1, "Admin"); Employee cloned = (Employee) original.clone(); System.out.println(cloned.getEmployeeId()); System.out.println(original != cloned); System.out.println(original.getClass() == cloned.getClass()); System.out.println(original.equals(cloned)); }
public void addEmployee(Employee emp) { if (personnel.size() == 0) { personnel.add(emp); } else for (Employee employee : personnel) { if (employee.equals(emp)) { System.out.println("Such employee is already exist, try another one"); return; } } personnel.add(emp); System.out.println("Emlployee added succesfully"); }
@Test public void testEqualForTwoEmployeeWithTheSameName() { // Given Employee employeeOne = new Employee("first name", "second name", new Address("2", "", "", "", "")); Employee employeeTwo = new Employee("first name", "second name", new Address("3", "", "", "", "")); // When boolean isTheSame = employeeOne.equals(employeeTwo); // Then assertThat(isTheSame, is(true)); }
public static void main(String[] args) { Employee e1 = new Employee("Joe", 1999, 10, 2); Employee e2 = new Employee("Joe", 2001, 9, 4); Employee e3 = new Employee("Amila", 2010, 9, 14); NameComparatorGood comp = new NameComparatorGood(); System.out.println(e1.equals(e2)); System.out.println(comp.compare(e1, e2)); List<Employee> list = new ArrayList<Employee>(); list.add(e1); list.add(e2); list.add(e3); Collections.sort(list, comp); System.out.println(list); }
public boolean setEmployee(Employee aEmployee) { boolean wasSet = false; if (aEmployee == null) { return wasSet; } Employee existingEmployee = employee; employee = aEmployee; if (existingEmployee != null && !existingEmployee.equals(aEmployee)) { existingEmployee.removeAccident(this); } employee.addAccident(this); wasSet = true; return wasSet; }
void update() { Employee e = view.get(); try { if (old == null) { if (!e.isEmpty()) { service.create(e); old = e; } } else if (!old.equals(e)) { service.update(e); old = e; } } catch (EmployeeException ex) { MessagePopup.warning( this, MessageUtil.getMessage("employee.update.warning") + ":\n" + ex.getMessage()); GemLogger.logException(ex); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Account other = (Account) obj; if (employee == null) { if (other.employee != null) return false; } else if (!employee.equals(other.employee)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (password == null) { if (other.password != null) return false; } else if (!password.equals(other.password)) return false; if (userId == null) { if (other.userId != null) return false; } else if (!userId.equals(other.userId)) return false; return true; }
/** * Tests XmlChoiceCollectionMapping configuration via eclipselink-oxm.xml. Here an unmarshal * operation is performed. Utilizes xml-attribute and xml-element. * * <p>Positive test. */ public void testChoiceCollectionMappingUnmarshal() { // load instance doc InputStream iDocStream = loader.getResourceAsStream(PATH + "employee.xml"); if (iDocStream == null) { fail("Couldn't load instance doc [" + PATH + "employee.xml" + "]"); } // setup control Employee Employee ctrlEmp = getControlObject(); // writeOnlyThings should not be read in ctrlEmp.writeOnlyThings = null; try { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Employee empObj = (Employee) unmarshaller.unmarshal(iDocStream); assertNotNull("Unmarshalled object is null.", empObj); assertTrue("Accessor method was not called as expected", empObj.wasSetCalled); assertTrue("Unmarshal failed: Employee objects are not equal", ctrlEmp.equals(empObj)); } catch (JAXBException e) { e.printStackTrace(); fail("Unmarshal operation failed."); } }