public static void main(String[] args) { Person pekka = new Person("Pekka", 15, 2, 1993); Person steve = new Person("Thomas", 1, 3, 1955); System.out.println(steve.getName() + " age " + steve.age() + " years"); System.out.println(pekka.getName() + " age " + pekka.age() + " years"); }
static Person checkPerson() { System.out.println("What is your user name?"); String keyPersonName = input.nextLine(); Person person; if (Person.getPeople().containsKey(keyPersonName)) { person = Person.getPeople().get(keyPersonName); System.out.println("Welcome " + person.getName()); Money.setLoggedIn(true); return person; } else { System.out.println(keyPersonName + " is not an existing user."); System.out.println("Would you like to create a new user called " + keyPersonName + "?"); if (input.nextLine().toLowerCase().equals("yes")) { createNewPerson(keyPersonName); person = Person.getPeople().get(keyPersonName); System.out.println("Welcome " + person.getName() + "!"); Money.setLoggedIn(true); return person; } } return null; }
public void changeName(Person who) { if (who.getName().equals("설까치")) { who = new Person("둘리"); } else if (who.getName().equals("홍길동")) { who = new Person("고길동"); } }
public void testNamePropertyComponent() { JTextField nameTextField = (JTextField) findComponent(JTextField.class, "NamePropertyComponent"); nameTextField.setText(""); getHelper().sendString(new StringEventData(this, nameTextField, person2.getName())); getHelper().sendKeyAction(new KeyEventData(this, nameTextField, KeyEvent.VK_ENTER)); assertEquals(person2.getName(), person1.getName()); }
@Override public int compare(Person o1, Person o2) { int result = o2.getName().compareToIgnoreCase(o1.getName()); if (0 == result) { return o1.getId() - o2.getId(); } return result; }
public static void main(String args[]) { Person p1 = new Person(); p1.name = "zhongshan"; Person p2 = new Person(); p2.name = "lisi"; System.out.println(p1.getName()); System.out.println(p2.getName()); }
/** * Tests to {@link EntityManager#find(Class, Object)} person. * * @since $version * @author hceylan */ @Test public void testFind() { final Person person = this.person(); this.persist(person); this.commit(); this.close(); final Person person2 = this.find(Person.class, person.getId()); Assert.assertEquals(person.getName(), person2.getName()); Assert.assertEquals(person.getPhones().size(), person2.getPhones().size()); }
public void testFiltersWithJoinedSubclass() { Session s = openSession(); s.enableFilter("region").setParameter("userRegion", "US"); Transaction t = s.beginTransaction(); prepareTestData(s); s.clear(); List results; Iterator itr; results = s.createQuery("from Person").list(); assertEquals("Incorrect qry result count", 4, results.size()); s.clear(); results = s.createQuery("from Employee").list(); assertEquals("Incorrect qry result count", 2, results.size()); s.clear(); results = new ArrayList( new HashSet(s.createQuery("from Person as p left join fetch p.minions").list())); assertEquals("Incorrect qry result count", 4, results.size()); itr = results.iterator(); while (itr.hasNext()) { // find john final Person p = (Person) itr.next(); if (p.getName().equals("John Doe")) { Employee john = (Employee) p; assertEquals("Incorrect fecthed minions count", 1, john.getMinions().size()); break; } } s.clear(); results = new ArrayList( new HashSet(s.createQuery("from Employee as p left join fetch p.minions").list())); assertEquals("Incorrect qry result count", 2, results.size()); itr = results.iterator(); while (itr.hasNext()) { // find john final Person p = (Person) itr.next(); if (p.getName().equals("John Doe")) { Employee john = (Employee) p; assertEquals("Incorrect fecthed minions count", 1, john.getMinions().size()); break; } } t.commit(); s.close(); }
public void deletePerson(String name) { for (Person p : list) { if (p.getName().equals(name)) { list.remove(p); } } }
@Test public void testIntegration() { assertNotNull(person); assertEquals("Joe bloggs", person.getName()); assertEquals(42, person.getAge()); assertEquals("testPwd", person.getPassword()); }
@Override public void onBindViewHolder(MyViewHolder holder, int position) { Person person = listPerson.get(position); holder.name.setText(person.getName()); holder.age.setText(person.getAge() + ""); }
@Test public void testGetName() { // fail("Not yet implemented"); Person p = new Person("Last", "First"); String name = p.getName(); assertEquals(name, "First Last"); }
/** * 1. 可以看到select中可以直接使用一个对象表示当前所有的字段, 并且当查询出来之后直接赋值, 这样时非常强大的。 2. * 可以比较不同的select后面的值, 最终打包成的结果, 可以看到hibernate会为我们打包任何值对象, 并且这一切 都是自动的, 无须做任何操作 */ public void select() { Session session = HibernateUtils.getSessionFactory().getCurrentSession(); Transaction tx = null; try { tx = session.beginTransaction(); // 查询出那些存在邮箱的人 List<Person> persons = session.createQuery("select p from Person as p inner join p.emails").list(); for (Person person : persons) { System.out.println(person.getName()); } // 查询出所有的人名, 可以看到这里distinct也可以使用 List<String> names = session.createQuery("select distinct p.name from Person p inner join p.emails").list(); for (String name : names) { System.out.println(name); } tx.rollback(); } catch (Exception e) { if (tx != null) { tx.rollback(); } throw new RuntimeException(e); } }
private ArrayList<ArrayList<HashMap<String, String>>> getChilds() { ArrayList<ArrayList<HashMap<String, String>>> result = new ArrayList<ArrayList<HashMap<String, String>>>(); // Do requests. ArrayList<HashMap<String, String>> requestChildren = new ArrayList<HashMap<String, String>>(); for (Request r : requests) { HashMap<String, String> h = new HashMap<String, String>(); h.put("HUID", r.HUID); h.put("name", r.name); h.put("img", r.img); requestChildren.add(h); } result.add(requestChildren); // Do friends. ArrayList<HashMap<String, String>> friendChildren = new ArrayList<HashMap<String, String>>(); for (Person f : friends) { HashMap<String, String> h = new HashMap<String, String>(); h.put("HUID", f.getHUID()); h.put("name", f.getName()); h.put("img", f.getImg()); h.put("status", f.getStatus()); h.put("table", f.getTable()); h.put("time", f.getTime()); friendChildren.add(h); } result.add(friendChildren); return result; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_detail); name = (TextView) findViewById(R.id.detail_name); phone = (TextView) findViewById(R.id.detail_phone); buttonCall = (Button) findViewById(R.id.call_button); buttonCall.setOnClickListener(this); buttonDelete = (Button) findViewById(R.id.delete_button); buttonDelete.setOnClickListener(this); this.list = MainActivity.list; this.list_seasrched = MainActivity.list_searched; intent = getIntent(); Bundle bundle = intent.getExtras(); pos = bundle.getInt("pos"); Toast.makeText(this, "pos: " + pos, Toast.LENGTH_LONG).show(); // todo 검색중이면, list가 아니라 list_searched에서 가져오기. boolean isSearching = bundle.getBoolean("isSearching"); Person person; if (isSearching) { person = this.list_seasrched.get(pos); } else { person = this.list.get(pos); } phoneStr = person.getPhone(); name.setText(person.getName()); phone.setText(person.getPhone()); }
@Override public Person process(Person person) throws Exception { Person modifiedPerson = new Person(); modifiedPerson.setName(person.getName().toUpperCase()); modifiedPerson.setSurname(person.getSurname().toUpperCase()); return modifiedPerson; }
@Override public View getView(int position, View convertView, ViewGroup parent) { // A ViewHolder keeps references to children views to avoid unneccessary calls // to findViewById() on each row. ViewHolder holder; // When convertView is not null, we can reuse it directly, there is no need // to reinflate it. We only inflate a new View when the convertView supplied // by ListView is null. if (convertView == null) { convertView = mInflater.inflate(R.layout.person_item_layout, null); // Creates a ViewHolder and store references to the two children views // we want to bind data to. holder = new ViewHolder(convertView); convertView.setTag(holder); } else { // Get the ViewHolder back to get fast access to the TextView // and the ImageView. holder = (ViewHolder) convertView.getTag(); } // Bind the data efficiently with the holder. Person person = getItem(position); if (null != person) { holder.name.setText(person.getName()); holder.age.setText(String.valueOf(person.getAge())); holder.location.setText(person.getLocation()); holder.work.setText(person.getWork()); } return convertView; }
public TableModel createModel() { String[] header = new String[] {"ID", "Imię", "Nazwisko", "Płeć", "Data urodzenia", "Data śmierci"}; Class[] types = new Class[] { Integer.class, String.class, String.class, String.class, String.class, String.class }; Object[][] values = new Object[count()][6]; for (int i = 0; i < count(); i++) { Person p = get(i); values[i][0] = i; values[i][1] = p.getName(); values[i][2] = p.getSurname(); values[i][3] = p.getGender().toString(); if (p.getBirthday() == null) { values[i][4] = "Nieznana"; } else { values[i][4] = Utilities.calendarToTable(p.getBirthday()); } if (!p.isDead()) { values[i][5] = "Żyje"; } else if (p.getDeathday() == null) { values[i][5] = "Nieznana"; } else { values[i][5] = Utilities.calendarToTable(p.getDeathday()); } } return new TableModel(values, header, types); }
public void sendMessage(final Person person) { System.out.println("Producer sends " + person); Map<String, Object> map = new HashMap<String, Object>(); map.put("name", person.getName()); map.put("age", person.getAge()); getJmsTemplate().convertAndSend(map); }
@Test public void testProxyMethod() { Datastore ds = new RedisDatastore(); ds.getMappingContext().addPersistentEntity(Person.class); Session conn = ds.connect(); Person p = new Person(); p.setName("Bob"); Address a = new Address(); a.setNumber("22"); a.setPostCode("308420"); p.setAddress(a); conn.persist(p); Person personProxy = (Person) conn.proxy(Person.class, p.getId()); EntityProxy proxy = (EntityProxy) personProxy; assertFalse(proxy.isInitialized()); assertEquals(p.getId(), personProxy.getId()); assertFalse(proxy.isInitialized()); assertEquals("Bob", personProxy.getName()); assertTrue(proxy.isInitialized()); }
public static void main(String[] args) { if (args[0].equals("-c")) { create(args); } else if (args[0].equals("-u")) { update(args); } else if (args[0].equals("-d")) { delete(args); } else if (args[0].equals("-i")) { select(args); } else { // return; } SimpleDateFormat format = new SimpleDateFormat("dd-MMM-yyyy", Locale.ENGLISH); for (Person person : allPeople) { System.out.println( person.getName() + " " + (person.getSex().equals(Sex.MALE) ? "м" : (person.getSex().equals(Sex.FEMALE) ? "ж" : "")) + " " + ((person.getBirthDay() != null) ? format.format(person.getBirthDay()) : person.getBirthDay())); } }
public void save(Person person) { SQLiteDatabase db = dbOpenHelper.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("name", person.getName()); values.put("phone", person.getPhone()); db.insert("person", null, values); }
private void assertContainsOnlyNonEmptyPersons(Collection<Person> persons) { for (Person person : persons) { assertThat(person).isNotNull(); assertThat(person.getAddress().getCity()).isNotEmpty(); assertThat(person.getAddress().getZipCode()).isNotEmpty(); assertThat(person.getName()).isNotEmpty(); } }
public static void printNames() { System.out.println("~~~Print Names of Students~~~"); for (Person temp : people) { if (temp instanceof Student) { System.out.println(temp.getName()); } } }
@Test public void _2_load() { Account account = em().find(Account.class, 1l); Person person = account.getPerson(); assertThat(person.getId()).isNotNull(); assertThat(person.getName()).isEqualTo("Augusto"); }
private Document createDocument(Person person) { Document doc = new Document(); doc.add(new Field("id", person.getId(), Store.YES, Index.NOT_ANALYZED)); doc.add(new Field("name", person.getName(), Store.YES, Index.NOT_ANALYZED)); doc.add( new Field("birthDate", person.getBirthDate().toString(), Store.YES, Index.NOT_ANALYZED)); return doc; }
@JExercise( tests = "setName(String)", description = "The setName(String) sets the name to the argument string, given that the name is within a valid format") public void testSetName() { String name = person.getName(); testInvalidName("Ola", name); testInvalidName("O N", name); testInvalidName("Ola Mellom Nordmann", name); testInvalidName("O. Nordmann", name); try { person.setName("Espen Askeladd"); assertEquals("Espen Askeladd", person.getName()); } catch (Exception e) { fail("Espen Askeladd is a valid name"); } }
private void testInvalidName(String invalidName, String existingName) { try { person.setName(invalidName); fail(invalidName + " is an invalid name"); } catch (Exception e) { testExceptionAndValue(e, IllegalArgumentException.class, existingName, person.getName()); } }
public boolean equals(Person p) { boolean check = false; if (p.getLastName().equals(lastName) && p.getName().equals(firstName) && p.getSSN().equals(this.getSSN())) { check = true; } return check; }
@Override public void insert(Person p) throws MapperException { Long buddyId = p.getBuddy() == null ? null : p.getBuddy().getId(); try { PersonTDG.insert(p.getId(), p.getVersion(), p.getName(), p.getAge(), buddyId); } catch (SQLException e) { throw new MapperException(e); } }