@Test public void testSaveTwoRootObjectsWithNoType() { JsonNode expected = mapper .createArrayNode() .add(mapper.createObjectNode().put("userId", "1").put("name", "Paul")) .add( mapper .createObjectNode() .put("userId", "2") .put("name", "Anna") .put("sex", "FEMALE")); User u1 = ModelFactory.eINSTANCE.createUser(); u1.setUserId("1"); u1.setName("Paul"); User u2 = ModelFactory.eINSTANCE.createUser(); u2.setUserId("2"); u2.setName("Anna"); u2.setSex(Sex.FEMALE); Resource resource = new JsonResource(URI.createURI("test"), mapper); resource.getContents().add(u1); resource.getContents().add(u2); JsonNode result = mapper.valueToTree(resource); assertEquals(expected, result); }
public User[] getAllUser() { Vector<User> v = new Vector<User>(); Cursor cursor = null; try { cursor = db.find("select * from " + TABLENAME, null); while (cursor.moveToNext()) { User temp = new User(); temp.setId_DB(cursor.getInt(cursor.getColumnIndex("id_DB"))); temp.setAddress(cursor.getString(cursor.getColumnIndex(User.ADDRESS))); temp.setQq(cursor.getString(cursor.getColumnIndex(User.QQ))); temp.setDanwei(cursor.getString(cursor.getColumnIndex(User.DANWEI))); temp.setName(cursor.getString(cursor.getColumnIndex(User.NAME))); temp.setMobile(cursor.getString(cursor.getColumnIndex(User.MOBILE))); v.add(temp); } } catch (Exception e) { e.printStackTrace(); } finally { if (cursor != null) cursor.close(); db.closeConnection(); } if (v.size() > 0) { return v.toArray(new User[] {}); } else { User[] users = new User[1]; User user = new User(); user.setName("无结果111"); users[0] = user; return users; } }
public static void testTtansaction_1() { for (User user : getSession().findAll(User.class)) { getSession().delete(User.class, user.getId()); } Transaction transaction = getSession().getTransaction(); transaction.begin(); User user = new User(); try { user.setId(1231234); getSession().insert(user); user = getSession().find(User.class, "1231234"); System.out.println("1:" + user); user.setName("123"); getSession().update(user); } catch (Exception e) { e.printStackTrace(); } finally { transaction.end(); } user = getSession().find(User.class, "1231234"); System.out.println("2" + user); System.out.println("=========="); transaction = getSession().getTransaction(); transaction.begin(); user = new User(); try { user.setId(1231234567); getSession().insert(user); user = getSession().find(User.class, "1231234567"); System.out.println("1:" + user); user.setName("123"); getSession().update(user); transaction.submit(); } finally { transaction.end(); } user = getSession().find(User.class, "1231234567"); System.out.println("2" + user); System.out.println("=========="); transaction = getSession().getTransaction(); transaction.begin(); user = new User(); try { user.setId(12312345); getSession().insert(user); user = getSession().find(User.class, "12312345"); System.out.println("1:" + user); user.setName("123"); getSession().update(user); transaction.submit(); } finally { transaction.end(); } user = getSession().find(User.class, "12312345"); System.out.println("2" + user); }
@Override public User getUserByName(String name) throws NoSuchCustomerTypeException { User user = new User(); if (name == null) { System.out.println("--null--"); user.setName("NULL"); } else if (name.length() <= 4) { System.out.println("--not null--"); user.setName(name.toUpperCase()); } else { throw new NoSuchCustomerTypeException(); } return user; }
public void testReservedTableOrderBy() throws Exception { // Drop the table removeAll(User.class); // Create User user = new User(); user.setName("demon"); getStore().save(user); User aUser = new User(); aUser.setName("root"); getStore().save(aUser); // Do query List result = getStore().find("find user order by user.name"); Assert.assertEquals(result.size(), 2); }
/** 测试以List对象作为根节点时的XML输出 */ @Test public void toXmlWithListAsRoot() { User user1 = new User(); user1.setId(1L); user1.setName("calvin"); User user2 = new User(); user2.setId(2L); user2.setName("kate"); List<User> userList = Lists.newArrayList(user1, user2); String xml = JaxbMapper.toXml(userList, "userList", User.class, "UTF-8"); System.out.println("Jaxb Object List to Xml result:\n" + xml); }
@OnClick(R.id.sign_up) public void signUpClicked(View view) { Utils.hideKeyboard(this); Utils.showProgressBar(this, progress, "Signing Up..."); User user = new User(); user.setSuperDefaults(); user.setUsername(username.getText().toString().trim()); user.setPassword(password.getText().toString().trim()); user.setEmail(email.getText().toString().trim()); user.setPhone(phone.getText().toString().trim()); user.setName(name.getText().toString().trim()); user.signUpInBackground( new SignUpCallback() { @Override public void done(ParseException exception) { Utils.hideProgressBar(progress); if (exception == null) { Toast.makeText( getApplicationContext(), "Sign up done successfully", Toast.LENGTH_SHORT) .show(); } else { new Builder(SignUpActivity.this) .setTitle(R.string.error_title) .setMessage(exception.getMessage()) .setPositiveButton(string.ok, null) .create() .show(); } startActivity( new Intent(SignUpActivity.this, MainActivity.class) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)); } }); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case 1: // 保存 if (!nameET.getText().toString().equals("")) { user.setName(nameET.getText().toString()); user.setMobile(mobileET.getText().toString()); user.setDanwei(danweiET.getText().toString()); user.setQq(qqET.getText().toString()); user.setAddress(addressET.getText().toString()); ContactsTable ct = new ContactsTable(UpdateContactsActivity.this); // 修改数据库联系人信息 if (ct.updateUser(user)) { Toast.makeText(UpdateContactsActivity.this, "修改成功!", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(UpdateContactsActivity.this, "修改失败!", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(UpdateContactsActivity.this, "数据不能为空!", Toast.LENGTH_SHORT).show(); } break; case 2: // 返回 finish(); break; default: break; } return super.onOptionsItemSelected(item); }
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { ObjectMapper objMapper = new ObjectMapper(); // JsonToJava User user = objMapper.readValue(new File("D:/sirish/work_files/samplejson.json"), User.class); System.out.println("user name is : " + user.getName()); System.out.println("user city is : " + user.getCity()); System.out.println("user job is : " + user.getJob()); for (String str : user.getHobbies()) { System.out.println("user hobbies are : " + str); } User newUser = new User(); newUser.setName("loknath"); newUser.setCity("Odisha"); newUser.setJob("swe"); newUser.setHobbies(new String[] {"browsing", "travelling"}); // JavaToJson objMapper.writeValue(new File("D:/sirish/work_files/sampleoutputjson.json"), newUser); }
/** Web service operation */ @WebMethod(operationName = "getUserByToken") @WebResult(name = "User") public User getUserByToken(@WebParam(name = "token") String token) { User user = new User(); try { Statement stmt = conn.createStatement(); String sql; sql = "SELECT user_id FROM token WHERE token_id = ?"; PreparedStatement dbStatement = conn.prepareStatement(sql); dbStatement.setString(1, token); ResultSet rs = dbStatement.executeQuery(); while (rs.next()) { user.setUserID(rs.getInt("user_id")); } rs.close(); String sql2 = "SELECT * FROM user WHERE user_id = ?"; PreparedStatement dbStatement2 = conn.prepareStatement(sql); dbStatement2.setInt(1, user.getUserID()); ResultSet rs2 = dbStatement2.executeQuery(); while (rs2.next()) { user.setName(rs.getString("name")); user.setEmail(rs.getString("email")); user.setPassword(rs.getString("password")); } rs2.close(); stmt.close(); } catch (SQLException ex) { Logger.getLogger(UserWS.class.getName()).log(Level.SEVERE, null, ex); } return user; }
private void read() { try { line = is.readLine(); while (line.compareTo("QUIT") != 0) { // System.out.println("Response from Client : " + line); if (line.toLowerCase().contains("@101|")) { send("Got username"); String name = line.substring(line.indexOf('|', 0) + 1, line.indexOf('|', line.indexOf('|', 0) + 1)); user.setName(name); System.out.println("Got username = "******"IO Error/ Client " + line + " terminated abruptly"); } catch (NullPointerException e) { line = this.getName(); // reused String line for getting thread name System.out.println("Client " + line + " Closed"); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case 1: // 保存 if (!nameET.getText().toString().equals("")) { User user = new User(); user.setName(nameET.getText().toString()); user.setDanwei(danweiET.getText().toString()); user.setMobile(mobileET.getText().toString()); user.setQq(qqET.getText().toString()); user.setAddress(addressET.getText().toString()); ContactsTable ct = new ContactsTable(this); if (ct.addData(user)) { Toast.makeText(this, "添加成功!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "添加失败!", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(this, "请先输入姓名!", Toast.LENGTH_LONG).show(); } break; case 2: // 返回 finish(); break; default: break; } return super.onOptionsItemSelected(item); }
/** * Checks the given username and password, returning a User object if if the username and password * identify a valid user. * * @param username The username * @param password The password * @return The signed in user */ @Override public final boolean authenticate(final String username, final String password) { final String WICKET = "wicket"; if (WICKET.equalsIgnoreCase(username) && WICKET.equalsIgnoreCase(password)) { // Create User object final User user = new User(); user.setName(username); final List<Book> books = user.getBooks(); books.add(new Book("Effective Java", "Joshua Bloch", Book.NON_FICTION)); books.add(new Book("The Illiad", "Homer Simpson", Book.FICTION)); books.add(new Book("Why Stock Markets Crash", "Didier Sornette", Book.NON_FICTION)); books.add(new Book("The Netherlands", "Mike Jones", Book.NON_FICTION)); books.add(new Book("Windows, Windows, Windows!", "Steve Ballmer", Book.FICTION)); books.add(new Book("This is a test", "Vincent Rumsfield", Book.FICTION)); books.add(new Book("Movies", "Mark Marksfield", Book.NON_FICTION)); books.add(new Book("DOS Capitol", "Billy G", Book.FICTION)); books.add(new Book("Whatever", "Jonny Zoom", Book.FICTION)); books.add(new Book("Tooty Fruity", "Rudy O", Book.FICTION)); setUser(user); return true; } return false; }
@Override public User modify(User user) { System.out.println("ԭ�û���:" + user.getName() + "������:" + user.getPassword()); user.setName("admin"); user.setPassword("111111"); System.out.println("�ĺ���û���:" + user.getName() + "������:" + user.getPassword()); return user; }
@GET public User getUser() { User user = new User(); user.setId(12345L); user.setName("smallnest"); user.setCreatedOn(new Date()); return user; }
public static void testInsert() { User user = new User(); user.setId(123454321); user.setAge(12); user.setName("ceshi"); getSession().insert(user); System.out.println(user.getId()); }
@Override public User getUser() { User user = new User(); user.setName("nick"); user.setScore(99); return user; }
@Test public void UserNameTest() { User u = new User(); u.setName("foo"); assertEquals("foo", u.getName()); }
public static void main(String[] args) { User person = new User(); person.setName("Name: "); person.setAge("Age: 1 - 100", 1, 100); person.setHeight("Height: 36 - 92", 36, 92); person.setWeight("Weight: 80 - 400", 80, 400); person.setFavNumber("Favorite Numner: 0 - 1", 0, 1); System.out.println("Name:\t" + person.getName()); System.out.println("Age:\t" + person.getAge()); System.out.println("Height:\t" + person.getHeight()); System.out.println("Weight:\t" + person.getWeight()); System.out.println("Number:\t" + person.getFavNumber()); // get a filename String filename = (System.getProperty("user.dir") + File.separatorChar + "file2015Oct.txt"); // write to a file PrintWriter writer = null; try { writer = new PrintWriter(new File(filename)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } writer.println(person.getName()); writer.println(person.getAge()); writer.println(person.getHeight()); writer.println(person.getWeight()); writer.println(person.getFavNumber()); writer.close(); // read a file // This will reference one line at a time String line = null; try { // FileReader reads text files in the default encoding. FileReader fileReader = new FileReader(filename); // Always wrap FileReader in BufferedReader. BufferedReader bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { System.out.println(line); } // Always close files. bufferedReader.close(); } catch (FileNotFoundException ex) { System.out.println("Unable to open file '" + filename + "'"); } catch (IOException ex) { System.out.println("Error reading file '" + filename + "'"); // Or we could just do this: // ex.printStackTrace(); } }
public static void main(String[] args) { User user1 = new User(); user1.setName("zhuzhen"); WeakReference<User> user2 = new WeakReference<User>(user1); System.out.println(user1); System.out.println(user2); System.out.println(user1.getName()); System.out.println(user2.get().getName()); }
public User getPersonalDetails(User user) { user.setUsername(sharedPreferences.getString("username", "")); user.setPassword(sharedPreferences.getString("password", "")); user.setName(sharedPreferences.getString("name", "")); user.setEmail(sharedPreferences.getString("email", "")); user.setAge(sharedPreferences.getString("age", "")); user.setPhone(sharedPreferences.getString("phone", "")); return user; }
public User build() { User createdUser = new User(this.nickname, this.email, this.cityID, this.countryID, this.password); createdUser.setAge(this.age); createdUser.setTag(this.tag); createdUser.setName(this.name); createdUser.setLastName(this.lastName); createdUser.setUserTagID(this.userTagID); return createdUser; }
public static void testUpdateAndFind() { User user = new User(); user = getSession().insert(user); user.setName("name12"); getSession().update(user); User user1 = getSession().find(User.class, user.getId()); System.out.println(user1.getId() == user.getId()); System.out.println(user1.getName().equals(user.getName())); System.out.println(user1.getAge() == user.getAge()); System.out.println(user.getId()); }
@Override public User findUser(String name) { User user = new User(); user.setName("serj"); user.setPassword("123456"); ArrayList<Address> addressArrayList = new ArrayList<Address>(); addressArrayList.add(new Address("jiangsu nanking", "serj1")); addressArrayList.add(new Address("china shanghai", "serj2")); user.setAddressList(addressArrayList); return user; }
public static void testQuerySingleValue() { clear(); User user = new User(); user.setId(123454321); user.setAge(12); user.setName("ceshi"); getSession().insert(user); System.out.println(user.getId()); Integer age = getSession().queryObject("select age from sm_user where id=?", new Object[] {123454321}); System.out.println(age); }
@Test public void testSaveSingleObjectWithNoType() { JsonNode expected = mapper.createObjectNode().put("userId", "1").put("name", "Paul"); User u1 = ModelFactory.eINSTANCE.createUser(); u1.setUserId("1"); u1.setName("Paul"); JsonNode result = mapper.valueToTree(u1); assertEquals(expected, result); }
@Test public void ifAgeNotRange_ageValidationFails() { User user = new User(); user.setName("MyName"); user.setAboutMe("Its all about me!!"); user.setAge(8); ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); Validator validator = factory.getValidator(); Set<ConstraintViolation<User>> violations = validator.validate(user); assertEquals(violations.isEmpty(), false); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView myListView = (ListView) findViewById(R.id.myListView); // データを準備 ArrayList<User> users = new ArrayList<>(); int[] icons = { R.mipmap.ic_launcher, R.mipmap.ic_launcher, R.mipmap.ic_launcher, }; String[] names = {"Taguchi", "Fkoji", "Dotinstall"}; String[] locs = {"Ebisu", "shibuya", "Tokyo"}; for (int i = 0; i < icons.length; i++) { User user = new User(); user.setIcon(BitmapFactory.decodeResource(getResources(), icons[i])); user.setName(names[i]); user.setLoc(locs[i]); users.add(user); } // Adapter - ArrayAdapter - UserAdapter UserAdapter adapter = new UserAdapter(this, 0, users); // ListViewに表示 myListView.setAdapter(adapter); // Event myListView.setOnItemClickListener( new AdapterView.OnItemClickListener() { @Override public void onItemClick( AdapterView<?> adapterView, View view, // タップされたView int i, // 何番目? long l // View id ) { TextView name = (TextView) view.findViewById(R.id.name); Toast.makeText( MainActivity.this, Integer.toString(i) + ":" + name.getText().toString(), Toast.LENGTH_SHORT) .show(); name.setText("Tapped!"); } }); }
@Test public void objectToXml() { User user = new User(); user.setId(1L); user.setName("calvin"); user.getInterests().add("movie"); user.getInterests().add("sports"); String xml = JaxbMapper.toXml(user, "UTF-8"); System.out.println("Jaxb Object to Xml result:\n" + xml); assertXmlByDom4j(xml); }
private static User getUser(Node node) { // XMLReaderDOM domReader = new XMLReaderDOM(); User user = new User(); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; user.setName(getTagValue("name", element)); user.setAge(Integer.parseInt(getTagValue("age", element))); user.setGender(getTagValue("gender", element)); user.setRole(getTagValue("role", element)); } return user; }