List<Customer> customers = Lists.newArrayList(); ... while ((line = bufferedReader.readLine()) != null) { ... customers.add(new Customer(...)); } for (Customer customer : customers) { System.out.println(customer.getId()); }
System.out.println("Id :" + customer.getId());
private void reloadButtonActionPerformed(java.awt.event.ActionEvent evt) { try { ArrayList<Customer> customerList = null; try { try { customerList = CustomerController.getAllCustomer(); } catch (SQLException ex) { Logger.getLogger(veiwCustomerFrame.class.getName()).log(Level.SEVERE, null, ex); } } catch (Exception ex) { Logger.getLogger(ViewCustomerForm.class.getName()).log(Level.SEVERE, null, ex); } DefaultTableModel tableModel = (DefaultTableModel) customerTable.getModel(); tableModel.setRowCount(0); for (Customer customer : customerList) { Object rowData[] = {customer.getId(), customer.getName(), customer.getAddress(), customer.getSalary()}; tableModel.addRow(rowData); } } catch (Exception ex) { Logger.getLogger(ViewCustomerForm.class.getName()).log(Level.SEVERE, null, ex); } }
JComboBox cb = (JComboBox) e.getSource(); Customer c = (Customer) cb.getSelectedItem(); System.out.println(c.getId() + " " + c.getName());
@Test public void testFindCustomerByCity() { Customer customer = new Customer("Max", "Tester"); customer.addAddress(new Address("Street", "1", "12345", "City")); Customer savedCustomer = customerRepository.save(customer); Assert.assertTrue(savedCustomer.getId() > 0); List<Customer> customerList = customerRepository.findByCity("City"); Assert.assertThat(customerList.size(), is(1)); }
CouchbaseManager<String,Customer> cbmCustomer = new CouchbaseManager<String,Customer>(Customer.class); CouchbaseManager<String,Account> cbmAccount = new CouchbaseManager<String,Account>(Account.class); // and so on for other POJOs you have. // then get/put operations look simple Customer cust = cbmCustomer.get("cust-1234"); cust.setName("New Name"); // mutate value // store changes cbmCustomer.put(cust.getId(), cust);
User user = new User(); // Using the same one over and over, won't work List<Customer> customers = fetchCustomersFromSomeService(); for(Customer customer : customers) { // User user = new User(); <-- This would work, you get a new one each time user.setId(customer.getId()); user.setName(customer.getName()); saveUserToDB(user); }
while (rs.next()) { long cust_id = rs.getLong("cust_id"); if (customer == null || customer.getId() != cust_id) { customer = new Customer(); customer.setId(cust_id);
private List<Map<String,Object>> getCustomersSortedByName( final int count ) { final List<Map<String,Object>> toReturn = new LinkedList<Map<String,Object>>(); //I call all my return variables "toReturn" so I know what's going to come out. final Customer customers[count]; //populate your customer array and sort it here for( final Customer customer : customers ) { final Map<String,Object> customerMap = new HashMap<String,Object>(); customer.put( "id", customer.getId() ); customer.put( "name", customer.getName() ); customer.put( "email", customer.getEmail() ); customer.put( "investments", customer.getInvestments() ); toReturn.add( customerMap ); } return toReturn; }
@Test public void updateCustomer_WithValidInput_ShouldReturnUpdatedInput(){ //given final Customer customer = new Customer(); customer.setId("123"); customer.setAddress("Addr1"); customer.setName("Bob"); customer.setCity("St8") customer.setLanguage("Java"); final CustomerInputData inputData = new CustomerInputData(); inputData.setId(customer.getId()); //when when(customerService.getCustomerById(customer.getId())).thenReturn(customer); classUnderTest.updateCustomer(customerData); //then verify(customerService.getCustomerById("123")); assertThat(customerData.getCustomerName(), equalTo(customer.getName())) // and so forth }