public void doFunctionalQueryTest(IMap imap) {
   Employee em = new Employee("joe", 33, false, 14.56);
   imap.put("1", new Employee("joe", 33, false, 14.56));
   imap.put("2", new Employee("ali", 23, true, 15.00));
   for (int i = 3; i < 103; i++) {
     imap.put(
         String.valueOf(i), new Employee("name" + i, i % 60, ((i % 2) == 1), Double.valueOf(i)));
   }
   Set<Map.Entry> entries = imap.entrySet();
   assertEquals(102, entries.size());
   int itCount = 0;
   for (Map.Entry entry : entries) {
     Employee c = (Employee) entry.getValue();
     itCount++;
   }
   assertEquals(102, itCount);
   EntryObject e = new PredicateBuilder().getEntryObject();
   Predicate predicate = e.is("active").and(e.get("age").equal(23));
   entries = imap.entrySet(predicate);
   assertEquals(3, entries.size());
   for (Map.Entry entry : entries) {
     Employee c = (Employee) entry.getValue();
     assertEquals(c.getAge(), 23);
     assertTrue(c.isActive());
   }
   imap.remove("2");
   entries = imap.entrySet(predicate);
   assertEquals(2, entries.size());
   for (Map.Entry entry : entries) {
     Employee c = (Employee) entry.getValue();
     assertEquals(c.getAge(), 23);
     assertTrue(c.isActive());
   }
 }
 /**
  * Returns a list of employees that have a specified age.
  *
  * @param age
  * @return a list of employees that have a specified age.
  */
 public List<Employee> getListOfEmployeesWithAge(int age) {
   List<Employee> aE_sList = new ArrayList<Employee>();
   for (Employee aEmployee : myE_sList) {
     if (aEmployee.getAge() == age) {
       aE_sList.add(aEmployee);
     }
     ;
   }
   return aE_sList;
 }
 @Test
 public void putAndGetEmployeeObjects() {
   HazelcastClient hClient = getHazelcastClient();
   int counter = 1000;
   Map<String, Employee> clientMap = hClient.getMap("putAndGetEmployeeObjects");
   for (int i = 0; i < counter; i++) {
     Employee employee = new Employee("name" + i, i, true, 5000 + i);
     employee.setMiddleName("middle" + i);
     employee.setFamilyName("familiy" + i);
     clientMap.put("" + i, employee);
   }
   for (int i = 0; i < counter; i++) {
     Employee e = clientMap.get("" + i);
     assertEquals("name" + i, e.getName());
     assertEquals("middle" + i, e.getMiddleName());
     assertEquals("familiy" + i, e.getFamilyName());
     assertEquals(i, e.getAge());
     assertEquals(true, e.isActive());
     assertEquals(5000 + i, e.getSalary(), 0);
   }
   //        }
 }
Beispiel #4
0
  public String toString() {
    StringBuffer buf = new StringBuffer();
    buf.append("<company ")
        .append("id=\"")
        .append(id)
        .append("\"")
        .append(" name=\"")
        .append(name)
        .append("\"")
        .append(" address=\"")
        .append(address)
        .append("\">");
    if (allEmployees != null) {
      for (Employee employee : allEmployees) {
        buf.append("\n\t<employee")
            .append(" id=\"")
            .append(employee.getId())
            .append("\"")
            .append(" name=\"")
            .append(employee.getName())
            .append("\"")
            .append(" age=\"")
            .append(employee.getAge())
            .append("\"")
            .append(" salary=")
            .append(employee.getSalary())
            .append("\"")
            .append(" deptId=\"")
            .append(employee.getDeptId())
            .append("\"/>");
      }
    }

    buf.append("\n</company>");

    return buf.toString();
  }
Beispiel #5
0
 public static void showList(Stack<Employee> list) {
   while (!list.isEmpty()) {
     Employee e = list.pop();
     System.out.println(e.getEmpId() + "\t" + e.getName() + "\t" + e.getAge());
   }
 }