id
stringlengths
36
36
text
stringlengths
1
1.25M
44967e55-3b39-4831-a1c0-d562850c502d
public void setEntityManager(EntityManager entityManager) { this.entityManager = entityManager; }
2a29b41a-4cf8-46d7-9c36-9b6c12476591
@Override public E save(E entity) { if (entity.getId() == null) { entityManager.persist(entity); } else { entityManager.merge(entity); } return entity; }
d4625d55-d75d-4018-94e2-e547e81d528e
@Override public void delete(E entity) { entityManager.remove(entity); }
09337890-1952-4879-9a04-f22b39445d3b
@Override public E findById(K id) { return entityManager.find(entityClass, id); }
9845410f-5e76-497c-8590-3cb5c05de90e
public Employee getEmployee(Long id);
75720cd4-b132-47d3-bf0c-639661b528f5
public List<Employee> getEmployeesByName(Name name);
abdd3e2b-1f1e-47a4-a77f-d405b711bf62
public Employee save(Employee employee);
bde8be33-3a72-4cdb-8c40-4027eaf12a7b
public Employee remove(Employee employee);
60535367-ba3f-45f9-ab67-fbbcc9a44185
public EmployeeDao getEmployeeDao() { return employeeDao; }
c7a3d13f-27eb-4c98-b83a-a785d55b7673
public void setEmployeeDao(EmployeeDao employeeDao) { this.employeeDao = employeeDao; }
852c83ae-835e-4fea-ad08-806cafa11781
@Override public Employee getEmployee(Long id) { return getEmployeeDao().findById(id); }
be708169-df2c-4643-b427-ad99e958285a
@Override public List<Employee> getEmployeesByName(Name name) { return getEmployeeDao().getEmployeesByName(name); }
28b8a5c5-b69b-4127-b60d-648a07ea58d3
@Override public Employee save(Employee employee) { return getEmployeeDao().save(employee); }
0a822999-6ae5-4b6c-b0aa-e74cb7da928e
@Override public Employee remove(Employee employee) { return null; }
7be32f7e-374b-4641-909b-96fb70e47d39
public void customize(Session session) throws Exception { ServerSession serverSession = (ServerSession) session; int work = serverSession.getNumberOfActiveUnitsOfWork(); ConnectionPool cPool = serverSession.getConnectionPool("default"); int totalNumberOfConnections = cPool.getTotalNumberOfConnections(); System.out.println("Details- NumberOfActiveUnitsOfWork : " + work + ", ConnectionPool size : " + totalNumberOfConnections ); }
55ff1e1f-8ba7-48ac-80e5-5d646c739b02
public Name getName() { return name; }
83e8aedf-606f-4e67-8024-1c5eac5c0b7d
public void setName(Name name) { this.name = name; }
9a02ba77-320f-475b-b64d-82336744f16c
public Phone getLandPhone() { return landPhone; }
7e98f054-f0d8-4f67-83a4-9a18f3928857
public void setLandPhone(Phone landPhone) { this.landPhone = landPhone; }
74bcd556-e947-47de-b04f-0e647a96c96e
public Band getBand() { return band; }
7f6a7b28-5e39-4459-a59a-af8e249ca698
public void setBand(Band band) { this.band = band; }
f3fb5d60-2cbc-4455-91d4-176c3cb0545f
public Date getDoj() { return doj; }
58d198de-e4af-4607-982c-65d41551a01b
public void setDoj(Date doj) { this.doj = doj; }
d7256273-1f35-4293-88cc-c02f45a022b0
public Date getDol() { return dol; }
dda9853f-bb45-4c42-8952-347f4c52e366
public void setDol(Date dol) { this.dol = dol; }
8953ff9b-6765-402f-b429-fc682f86fa70
public String getBloodGroup() { return bloodGroup; }
848614a1-803a-4527-b9a8-d13168f2ba3a
public void setBloodGroup(String bloodGroup) { this.bloodGroup = bloodGroup; }
b5080887-9dc5-41a7-9bd9-02b61dba65b2
public Name() { }
ca0065d7-ea8f-44cc-bfb5-0312074aa72b
public Name(String firstName, String middleName, String lastName) { this.firstName = firstName; this.middleName = middleName; this.lastName = lastName; }
394ed2ad-fc7c-446b-b809-14ce82925a7f
public String getFirstName() { return firstName; }
e7f32f79-48c4-4fa2-9649-859b79a0e22d
public void setFirstName(String firstName) { this.firstName = firstName; }
098d4638-e41e-4767-9d26-30e3df2fdeab
public String getMiddleName() { return middleName; }
d4628846-b5a9-4e04-821d-fa948676e6b7
public void setMiddleName(String middleName) { this.middleName = middleName; }
61c2a947-44c9-4d53-9aef-88ec7473b68f
public String getLastName() { return lastName; }
82c4eeb8-6b9d-484c-9bb2-ed5efead1c55
public void setLastName(String lastName) { this.lastName = lastName; }
6eb38671-e876-495f-aa62-548d7048273a
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("Name"); sb.append("{firstName='").append(firstName).append('\''); sb.append(", middleName='").append(middleName).append('\''); sb.append(", lastName='").append(lastName).append('\''); sb.append('}'); return sb.toString(); }
6ca46ba5-bb56-40c8-a48f-b6fee001cf37
public Long getId() { return id; }
3ac6108b-75ab-4c53-bd4a-074fd8729175
public void setId(Long id) { this.id = id; }
2bbd788a-94aa-47c2-873a-726491a59e6c
public Phone() { }
162bd46b-a1e7-4ab9-8ac0-a0d34dd6d06e
public Phone(int countryCode, int stdCode, int number) { this.countryCode = countryCode; this.stdCode = stdCode; this.number = number; }
fd0e3f6f-faee-44a0-be75-92c9883752f7
public int getCountryCode() { return countryCode; }
0746273c-f867-47a8-a056-1a78597e6533
public void setCountryCode(int countryCode) { this.countryCode = countryCode; }
d6ff9629-01e6-4dcb-b86a-73236f3f1ec0
public int getStdCode() { return stdCode; }
c2fde9e1-5a9e-405a-91b5-2ab55c596039
public void setStdCode(int stdCode) { this.stdCode = stdCode; }
5c082414-49c2-4817-acf5-041316056532
public int getNumber() { return number; }
b06ff1d7-b48e-4cf7-b279-43f502e550b0
public void setNumber(int number) { this.number = number; }
31f93a81-4534-4ee7-8cf1-28fe1d39b209
@Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("Phone"); sb.append("{countryCode=").append(countryCode); sb.append(", stdCode=").append(stdCode); sb.append(", number=").append(number); sb.append('}'); return sb.toString(); }
0ff274ba-f844-492e-83fe-6f027e1dc892
@Test public void testSaveEmployee() { employeeService.save(createEmployee()); employeeService.save(createEmployee()); employeeService.save(createEmployee()); employeeService.save(createEmployee()); employeeService.save(createEmployee()); employeeService.save(createEmployee()); employeeService.save(createEmployee()); employeeService.save(createEmployee()); employeeService.save(createEmployee()); employeeService.save(createEmployee()); }
71b6868d-2131-466d-a7ea-2e7c6bde65a6
@Test public void testGetEmployee(){ Employee employee = employeeService.getEmployee(new Long(1)); System.out.println("======================> " + employee); }
d6d01408-0171-4562-accb-e3c8ecfd483f
private Employee createEmployee() { Employee employee = new Employee(); Name name = new Name(); name.setFirstName("Deepak"); name.setLastName("Jacob"); employee.setName(name); employee.setBand(Band.A); employee.setBloodGroup("A+"); employee.setDoj(new Date()); employee.setDol(new Date()); Phone landPhone = new Phone(); landPhone.setCountryCode(91); landPhone.setStdCode(1234); landPhone.setNumber(12121212); employee.setLandPhone(landPhone); return employee; }
6d3ffa70-7432-4acd-9c5b-d33aa5ea5b36
@Test public void insertTest() { //test insert() method testBST.insert(testBST.getRoot(), 5); //if this method works, should print out success to terminal if (testBST.getRoot().getData().compareTo(5) == 0) System.out.println("insertTest() passes"); else System.out.println("insertTest() fails"); }
1fbf558a-2406-4248-a228-e32f6cc50c50
@Test public void insertTestL() { //insert node to root testBST.insert(testBST.getRoot(), 5); //test insert() method again testBST.insert(testBST.getRoot(), 2); //if method works it should print out successful to terminal if (testBST.getRoot().getLeft().getData().compareTo(2) == 0) System.out.println("insertTestL() passes"); else System.out.println("insertTestL() fails"); }
bd441fe3-5510-433a-8be4-7580d01f1db2
@Test public void insertTestR() { //insert node to root testBST.insert(testBST.getRoot(), 5); //test insert() method again testBST.insert(testBST.getRoot(), 9); //if method works it should print out successful to terminal if (testBST.getRoot().getRight().getData().compareTo(9) == 0) System.out.println("insertTestR() passes"); else System.out.println("insertTestR() fails"); }
0b26b274-2ab8-42eb-9d1f-283b776386eb
@Test public void searchTest() { //build a tree using insert() testBST.insert(testBST.getRoot(), 5); testBST.insert(testBST.getRoot(), 2); testBST.insert(testBST.getRoot(), 6); //assign to temporary values Integer actual = testBST.getRoot().getRight().getData(); Integer test = testBST.search(testBST.getRoot(), 6).getData(); //if actual and test integers are equal, print out success if (test.compareTo(actual)==0) System.out.println("searchTest() passes"); else System.out.println("searchTest() fails"); }
516ba70f-7516-43d6-8d7a-654782644c6a
@Test public void searchTestNotInTree() { //build a tree using insert() testBST.insert(testBST.getRoot(), 5); testBST.insert(testBST.getRoot(), 2); testBST.insert(testBST.getRoot(), 6); //assign to temporary values Integer actual = null; Integer test = testBST.search(testBST.getRoot(), 1).getData(); //if actual and test integers are equal, print out success if (test == null && actual == null) System.out.println("searchTestNotInTree() passes"); else System.out.println("searchTestNotInTree() fails"); }
ee5a9727-70b0-483d-a5df-d4514c47505b
@Test public void getMinTest() { //build a tree using insert() testBST.insert(testBST.getRoot(), 5); testBST.insert(testBST.getRoot(), 2); testBST.insert(testBST.getRoot(), 6); //Test for the Min, which is 2 if (testBST.getMin(testBST.getRoot()).compareTo(2) == 0) System.out.println("getMinTest() passes"); else System.out.println("getMinTest() fails"); }
e1996229-08a3-4598-8b9b-a8f0104e3816
@Test public void getMinTestAgain() { //build a tree using insert() testBST.insert(testBST.getRoot(), 5); testBST.insert(testBST.getRoot(), 2); testBST.insert(testBST.getRoot(), 6); testBST.insert(testBST.getRoot(), 0); testBST.insert(testBST.getRoot(), 1); //Test for the Min, which is 2 if (testBST.getMin(testBST.getRoot()).compareTo(0) == 0) System.out.println("getMinTestAgain() passes"); else System.out.println("getMinTestAgain() fails"); }
671a480b-37f6-48a5-952b-5241ceaeef5b
@Test public void getMaxTest() { //build a tree using insert() testBST.insert(testBST.getRoot(), 5); testBST.insert(testBST.getRoot(), 2); testBST.insert(testBST.getRoot(), 6); //Test for the Max, which is 6 if (testBST.getMax(testBST.getRoot()).compareTo(6) == 0) System.out.println("getMaxTest() passes"); else System.out.println("getMaxTest() fails"); }
ccb10297-8eaa-4a66-af61-2259ea07bdaf
@Test public void getMaxTestAgain() { //build a tree using insert() testBST.insert(testBST.getRoot(), 5); testBST.insert(testBST.getRoot(), 2); testBST.insert(testBST.getRoot(), 6); testBST.insert(testBST.getRoot(),100); testBST.insert(testBST.getRoot(), 94); //Test for the Max, which is 6 if (testBST.getMax(testBST.getRoot()).compareTo(100) == 0) System.out.println("getMaxTestAgain() passes"); else System.out.println("getMaxTestAgain() fails"); }
11803fa3-e780-48e8-b5bf-f4ff549fce71
public PostFixCalculator(String equation) { //create new stackLL which will hold integers calcStack = new StackLL<Integer>(); System.out.println(generateOutput(equation)); }
19f103cd-377a-4fd5-afea-3a2ebc7bacab
public Integer generateOutput(String equation) { StringTokenizer stringTokenizer = new StringTokenizer(equation); String currentToken = ""; //need to build and evaluate the stack while(stringTokenizer.hasMoreTokens()) { //update the current token so you aren't starting with blank currentToken = stringTokenizer.nextToken(); //if current token is an arrow, do nothing (push and pop immediately) if (currentToken.equals("->")) { calcStack.push(0); calcStack.pop(); } //if a multiplication sign is seen (*) else if(currentToken.equals("*")) { //call helper method and push return value to stack calcStack.push(multiplication()); } //if an addition sign is seen (+) else if (currentToken.equals("+")) { //call helper method and push return value to stack calcStack.push(addition()); } //otherwise the string returns an integer else { calcStack.push(Integer.valueOf(currentToken)); } } //temporary return return calcStack.pop(); }
2ed1a7ab-133a-4fbc-99c8-02eb7930f624
public Integer addition() { return calcStack.pop() + calcStack.pop(); }
cb8259f4-3824-4ec3-b6e9-34de8e0a0109
public Integer multiplication() { return calcStack.pop() * calcStack.pop(); }
1aab3161-9981-46b5-99d4-599b86c83ee8
public static void main(String[] args) { //create new PostFixCalculator object and read input from terminal new PostFixCalculator(args[0]); }
2ccb60db-a260-4f37-9fa9-4477a6fc6326
@Test public void getDataTest() { //use assertEquals to test functionality assertEquals("The correct return for this test is null", null, testNode.getData()); }
38eda5fc-9171-4db2-9686-bd0de2a97285
@Test public void setDataTest() { //must try to set the data using the method being tested testNode.setData("a"); //now do assertEquals to test functionality assertEquals("The correct return for this test will be 'a'", "a", testNode.getData()); }
62030b6c-bd7f-46eb-8f5f-25a4fad97917
@Test public void getLeftTest() { //use assertEquals to test functionality assertEquals("The correct return for this test should be null", null, testNode.getLeft()); }
97571c9b-60f8-44e9-856a-ebbc8e283c8f
@Test public void setLeftTest() { //try setting data using the setLeft() method testNode.setLeft("l"); //use assertEquals to test functionality assertEquals("The correct return for this test should be 'l'", "l", testNode.getLeft().getData()); }
8bad975a-c604-4adc-9744-feff633981ed
@Test public void getRightTest() { assertEquals("The correct return for this test should be null", null, testNode.getRight()); }
380722db-659d-4d63-be8c-7ce439d6910d
@Test public void setRightTest() { //perform the method we wish to test: setRight() testNode.setRight("r"); //use assertEquals to test functionality assertEquals("The correct return for this method should be 'r'", "r", testNode.getRight().getData()); }
f75ae16f-e724-4d01-ba58-e1fd306f57a7
@Test public void getRootTest() { //use assertEquals to test functionality assertEquals("The correct return for this method is null", null, testTree.getRoot()); }
d62327ac-4619-48c5-8edd-21627b4c328f
@Test public void setRootTest() { //try assigning the root to be "root" using desired method testTree.setRoot("root"); //use assertEquals to test functionality assertEquals("The correct return for this method should be 'root'", "root", testTree.getRoot().getData()); }
7f14ce83-a20d-42ff-9f8b-9beb0003639c
@Test public void getLeftChildTest() { //set there to be a root node testTree.setRoot("root"); //use assertEquals to test functionality assertEquals("The correct return for this method should be null", null, testTree.getLeftChild(testTree.getRoot())); }
7957ead2-5e92-474c-b4e9-b82f66a27b40
@Test public void insertLeftTest() { //set there to be a root node testTree.setRoot("root"); //try method to insert left child testTree.insertLeft(testTree.getRoot(), "left"); //use assertEquals to test functionality assertEquals("The correct return for this method should be 'left'", "left", testTree.getLeftChild(testTree.getRoot()).getData()); }
0f9cd402-0a13-4f9e-a5f8-e163f2e6ed5c
@Test public void getRightChildTest(){ //set there to be a root node testTree.setRoot("root"); //use assertEquals to test functionality assertEquals("The correct return for this method should be null", null, testTree.getRightChild(testTree.getRoot())); }
41cecba3-f4bd-4ae4-aa3b-eaf6ab3caefd
@Test public void setLeftChildTest() { //set there to be a root node testTree.setRoot("root"); //try method to insert right child testTree.insertRight(testTree.getRoot(), "right"); //use assertEquals to test functionality assertEquals("The correct return for this method should be 'right'", "right", testTree.getRightChild(testTree.getRoot()).getData()); }
e772a09e-da2e-413a-8d3e-0687dd93bddb
@Test public void inorderTraversalTest(){ //set up a tree with a root, a left child, and a right child testTree.setRoot("root"); testTree.insertLeft(testTree.getRoot(),"left"); testTree.insertRight(testTree.getRoot(), "right"); //use assertEquals to test functionality assertEquals("This method should return a linkedList of size 4", 4, //there is one additional node since the head node will be the type of traversal testTree.inorderTraversal(testTree.getRoot(), "In-order Traversal").size()); System.out.println(testTree.inorderTraversal(testTree.getRoot(), "In-order Traversal").toString()); }
2d2dc06d-e059-49b0-b567-e2285cad92e8
@Test public void preorderTraversalTest(){ //set up a tree with a root, a left child, and a right child testTree.setRoot("root"); testTree.insertLeft(testTree.getRoot(),"left"); testTree.insertRight(testTree.getRoot(), "right"); //use assertEquals to test functionality assertEquals("This method should return a linkedList of size 4", 4, //there is one additional node since the head node will be the type of traversal testTree.preorderTraversal(testTree.getRoot(), "Pre-order Traversal").size()); System.out.println(testTree.preorderTraversal(testTree.getRoot(), "Pre-order Traversal").toString()); }
52743438-fe53-4b23-99f6-397ea5d7123e
@Test public void postorderTraversalTest(){ //set up a tree with a root, a left child, and a right child testTree.setRoot("root"); testTree.insertLeft(testTree.getRoot(),"left"); testTree.insertRight(testTree.getRoot(), "right"); //use assertEquals to test functionality assertEquals("This method should return a linkedList of size 4", 4, //there is one additional node since the head node will be the type of traversal testTree.postorderTraversal(testTree.getRoot(), "Post-order Traversal").size()); System.out.println(testTree.postorderTraversal(testTree.getRoot(), "Post-order Traversal").toString()); }
a1afbeaf-26d3-4bd2-81af-100be9b6b145
@Test public void arithmeticTest(){ //set up simple arithmetic expression with root as an operation and children as integers testTree.setRoot("+"); testTree.insertLeft(testTree.getRoot(), "5"); testTree.insertRight(testTree.getRoot(), "3"); //show the arithmetic expressing using in-order traversal System.out.println(testTree.inorderTraversal(testTree.getRoot(), "Arithmetic Expression Representation, disregard arrows").toString()); }
0f3eb3ea-0018-4df7-b3ed-f37494cfa690
@Test public void arithmeticEvalTest(){ //set up a simple arithmetic expression with root as operation and children as integers testTree.setRoot("+"); testTree.insertLeft(testTree.getRoot(), "5"); testTree.insertRight(testTree.getRoot(), "3"); //use postorder traversal to then evaluate using postorder calculator new PostFixCalculator(testTree.postorderTraversal(testTree.getRoot(), "").toString()); //should see "8" on a separate line in terminal output }
a75cff81-5d71-4346-8cf5-f3cc41c131fc
public static void main(String[] args) throws FileNotFoundException, IOException, ParseException { setFilePath(); SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd");// 设置日期格式 today = "thunder_" + df.format(new Date()); read(); // write(); }
c7677e6f-0868-4522-9680-976bc1cc5339
public static void setFilePath() { String pathBin = Main.class.getClass().getResource("/").getFile(); String path = pathBin.substring(0, pathBin.lastIndexOf("/")); path = path.substring(0, path.lastIndexOf("/")); path = path + "/doc/"; Config.FILE_PATH = path; System.out.println("file save path " + Config.FILE_PATH); }
0667292a-7c5a-457e-9354-39ac56083058
public static void read() { new Thread(new Runnable() { @Override public void run() { try { // 省份链接 String privicenUrl = Config.PROVINCE_URL; ArrayList<PersonModel> listCache = new ArrayList<PersonModel>(); int time = 0; // 循环34个省 for (int i = 1; i < 35; i++) { // 间隔1-10S ,再去请求,防止400错误 time = (int) (Math.random() * 9000) + 5000; String requestUrl = privicenUrl + i + "&cachetime=" + System.currentTimeMillis(); System.out.println(i + " : " + requestUrl); String content = HttpUtil.sendGet(requestUrl); PersonListModel listModel = new Gson().fromJson(content, PersonListModel.class); System.out.println(listModel.data.get(0).region + " : " + listModel.data.size()); for (PersonModel model : listModel.data) { // 这里是第一次加,不会有重复的 hashMap.put(model.innerno, model); } Thread.sleep(time); // 没请求10次,强制休息10S if (i % 10 == 0) { Thread.sleep(10000); } } // 请求完省份,休息10S Thread.sleep(10000); // 称号URL ,这个能弥补部分没有选择省份的用户 String chenghaoUrl = Config.CHENGHAO_URL; for (int i = 0; i < 5; i++) { time = (int) (Math.random() * 9000) + 1000; String requestUrl = chenghaoUrl + i + "&cachetime=" + System.currentTimeMillis(); System.out.println(i + " : " + requestUrl); String content = HttpUtil.sendGet(requestUrl); PersonListModel listModel = new Gson().fromJson(content, PersonListModel.class); System.out.println(i + " size " + listModel.data.size()); for (PersonModel model : listModel.data) { // 去重 if (!hashMap.containsKey(model.innerno)) { hashMap.put(model.innerno, model); } } Thread.sleep(time); } // 遍历hashmap,把数据都放到 listCache中 Iterator iter = hashMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); listCache.add((PersonModel) entry.getValue()); } System.out.println("list cache size " + listCache.size()); // 按经验值,降序排序 Collections.sort(listCache, new ComparatorUser()); // 基于经验值取数据 // for (int i = 0; i < listCache.size(); i++) { // if (listCache.get(i).exp > STANDER) { // list.add(listCache.get(i)); // } else { // break; // } // } // 基于排名取数据 for (int i = 0; i < STANDER_RANK; i++) { list.add(listCache.get(i)); } System.out.println("read data size " + list.size()); String content = new Gson().toJson(list); // 写入本地,以防以外.如果write方法有误,可以在main里直接调用write方法进行调试,不用每次都等待read完毕 FileUtil.writeFileToSD(today + Config.SUFFIX_TEXT, content); write(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); }
34d193db-2b7d-4d08-996a-e450d6291516
@Override public void run() { try { // 省份链接 String privicenUrl = Config.PROVINCE_URL; ArrayList<PersonModel> listCache = new ArrayList<PersonModel>(); int time = 0; // 循环34个省 for (int i = 1; i < 35; i++) { // 间隔1-10S ,再去请求,防止400错误 time = (int) (Math.random() * 9000) + 5000; String requestUrl = privicenUrl + i + "&cachetime=" + System.currentTimeMillis(); System.out.println(i + " : " + requestUrl); String content = HttpUtil.sendGet(requestUrl); PersonListModel listModel = new Gson().fromJson(content, PersonListModel.class); System.out.println(listModel.data.get(0).region + " : " + listModel.data.size()); for (PersonModel model : listModel.data) { // 这里是第一次加,不会有重复的 hashMap.put(model.innerno, model); } Thread.sleep(time); // 没请求10次,强制休息10S if (i % 10 == 0) { Thread.sleep(10000); } } // 请求完省份,休息10S Thread.sleep(10000); // 称号URL ,这个能弥补部分没有选择省份的用户 String chenghaoUrl = Config.CHENGHAO_URL; for (int i = 0; i < 5; i++) { time = (int) (Math.random() * 9000) + 1000; String requestUrl = chenghaoUrl + i + "&cachetime=" + System.currentTimeMillis(); System.out.println(i + " : " + requestUrl); String content = HttpUtil.sendGet(requestUrl); PersonListModel listModel = new Gson().fromJson(content, PersonListModel.class); System.out.println(i + " size " + listModel.data.size()); for (PersonModel model : listModel.data) { // 去重 if (!hashMap.containsKey(model.innerno)) { hashMap.put(model.innerno, model); } } Thread.sleep(time); } // 遍历hashmap,把数据都放到 listCache中 Iterator iter = hashMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); listCache.add((PersonModel) entry.getValue()); } System.out.println("list cache size " + listCache.size()); // 按经验值,降序排序 Collections.sort(listCache, new ComparatorUser()); // 基于经验值取数据 // for (int i = 0; i < listCache.size(); i++) { // if (listCache.get(i).exp > STANDER) { // list.add(listCache.get(i)); // } else { // break; // } // } // 基于排名取数据 for (int i = 0; i < STANDER_RANK; i++) { list.add(listCache.get(i)); } System.out.println("read data size " + list.size()); String content = new Gson().toJson(list); // 写入本地,以防以外.如果write方法有误,可以在main里直接调用write方法进行调试,不用每次都等待read完毕 FileUtil.writeFileToSD(today + Config.SUFFIX_TEXT, content); write(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
b3dde06a-181f-4fdf-b4f0-17a5730cd552
public static void write() throws FileNotFoundException, IOException { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); String yesterday = "thunder_" + new SimpleDateFormat("yyyy_MM_dd").format(cal.getTime()); File file = new File(Config.FILE_PATH + yesterday + Config.SUFFIX_EXCEL); // 寻找昨天的数据,存在的话就读取,用于计算两天相差经验值 if (file.exists()) { hashMapYesterday = new HashMap<Integer, PersonModel>(); String[][] result = ExcelUtil.readExcel(file, 1); int rowLength = result.length; for (int i = 0; i < rowLength; i++) { PersonModel model = new PersonModel(); for (int j = 0; j < result[i].length; j++) { if (j == 2) { model.name = result[i][j]; } else if (j == 3) { try { model.exp = Integer.parseInt(result[i][j]); } catch (Exception e) { // TODO: handle exception model.exp = 0; } } else if (j == 5) { model.isvip = "是".equals(result[i][j]) ? 1 : 0; } else if (j == 6) { model.vip_level = EnumVipLevel.valueOf(result[i][j]); } else if (j == 0) { model.innerno = Integer.parseInt(result[i][j]); } else if (j == 1) { model.rank_display = Integer.parseInt(result[i][j]); } // System.out.print(result[i][j]+"\t\t"); } // System.out.println(); hashMapYesterday.put(model.innerno, model); } // for (int i = 0; i < expArr.length; i++) { // System.out.println(expArr[i]); // } } else { System.out.println("no yesterday data!!!"); } String content = FileUtil.getJsonFromAssets(Config.FILE_PATH + today + Config.SUFFIX_TEXT); Type type = new TypeToken<List<PersonModel>>() { }.getType(); list = new Gson().fromJson(content, type); System.out.println("write data size " + list.size()); ExcelUtil.writeExcel(today + Config.SUFFIX_EXCEL, list, hashMapYesterday); }
8a7c5154-cbcd-4b3e-882b-0364e0af982a
@Override public String toString() { return "PersonListModel [result=" + result + ", message=" + message + ", data=" + data + "]"; }
609b94f0-25ec-4b6c-b238-1d0a35419a8d
@Override public String toString() { return "PersonModel [name=" + name + ", region=" + region + ", isme=" + isme + ", isvip=" + isvip + ", rank=" + rank + ", rank_display=" + rank_display + ", innerno=" + innerno + ", exp=" + exp + ", title_type=" + title_type + ", region_id=" + region_id + ", oltime=" + oltime + ", dlgiga=" + dlgiga + ", dlfile=" + dlfile + ", level_img=" + level_img + ", vip_level=" + vip_level + "]"; }
d555f39a-07ea-448f-a258-fdccd8a05987
public static void writeExcel(String fileName, ArrayList<PersonModel> list, HashMap<Integer, PersonModel> hashMapYesterday) { // 第一步,创建一个webbook,对应一个Excel文件 HSSFWorkbook wb = new HSSFWorkbook(); // 第二步,在webbook中添加一个sheet,对应Excel文件中的sheet HSSFSheet sheet = wb.createSheet("迅雷用户排行"); // 第三步,在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制short HSSFRow row = sheet.createRow((int) 0); // 第四步,创建单元格,并设置值表头 设置表头居中 HSSFCellStyle style = wb.createCellStyle(); style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式 HSSFCell cell = row.createCell((short) 0); cell.setCellValue("内部ID"); cell.setCellStyle(style); cell = row.createCell((short) 1); cell.setCellValue("排名"); cell.setCellStyle(style); cell = row.createCell((short) 2); cell.setCellValue("用户名"); cell.setCellStyle(style); cell = row.createCell((short) 3); cell.setCellValue("经验"); cell.setCellStyle(style); cell = row.createCell((short) 4); cell.setCellValue("省份"); cell.setCellStyle(style); cell = row.createCell((short) 5); cell.setCellValue("是否是会员"); cell.setCellStyle(style); cell = row.createCell((short) 6); cell.setCellValue("会员等级"); cell.setCellStyle(style); cell = row.createCell((short) 7); cell.setCellValue("经验等级"); cell.setCellStyle(style); cell = row.createCell((short) 8); cell.setCellValue("昨日增加经验"); cell.setCellStyle(style); cell = row.createCell((short) 9); cell.setCellValue("名次变化"); cell.setCellStyle(style); // 第五步,写入实体数据 实际应用中这些数据从数据库得到, for (int i = 0; i < list.size(); i++) { row = sheet.createRow((int) i + 1); PersonModel model = list.get(i); // 第四步,创建单元格,并设置值 row.createCell((short) 0).setCellValue(model.innerno); row.createCell((short) 1).setCellValue(i + 1); row.createCell((short) 2).setCellValue(model.name); row.createCell((short) 3).setCellValue(model.exp); row.createCell((short) 4).setCellValue(model.region); row.createCell((short) 5).setCellValue(model.isvip == 1 ? "是" : "不是"); EnumVipLevel vipLevel = EnumVipLevel.未知; int expAdded = 0; // System.out.println(nameArr[i]+" "+model.name); if (hashMapYesterday != null) { PersonModel modelYesterday = hashMapYesterday.get(model.innerno); if (hashMapYesterday != null && modelYesterday != null) { int rankDisplay=i+1; //排名变化 if(rankDisplay==modelYesterday.rank_display){ row.createCell((short) 9).setCellValue("-"); }else if(rankDisplay>modelYesterday.rank_display){ //排名降低了 row.createCell((short) 9).setCellValue("↓ "+(rankDisplay-modelYesterday.rank_display)); }else{ row.createCell((short) 9).setCellValue("↑ "+(modelYesterday.rank_display-rankDisplay)); } //经验值计算 expAdded = model.exp - modelYesterday.exp; if (modelYesterday.isvip == 1) { int expAdd = model.exp - modelYesterday.exp; if (expAdd > 160) { //sb迅雷自己的经验值都搞不明白,部分用户可以今天经验值是0,明天是180 if(modelYesterday.vip_level!=EnumVipLevel.未知){ //这种sb的情况下,如果昨天不是未知,那继续采用昨天的等级。否则仍旧是未知 vipLevel=modelYesterday.vip_level; } } else if (expAdd > 150) { vipLevel = EnumVipLevel.白金vip7; } else if (expAdd > 140) { vipLevel = EnumVipLevel.白金vip6; } else if (expAdd > 130) { vipLevel = EnumVipLevel.白金vip5; } else if (expAdd > 120) { vipLevel = EnumVipLevel.白金vip4或普通vip6; } else if (expAdd > 110) { vipLevel = EnumVipLevel.白金vip3或普通vip5; } else if (expAdd > 100) { vipLevel = EnumVipLevel.白金vip2或普通vip4; } else if (expAdd > 90) { vipLevel = EnumVipLevel.白金vip1或普通vip3; } else if (expAdd > 80) { vipLevel = EnumVipLevel.普通vip2; } else if (expAdd > 70) { vipLevel = EnumVipLevel.普通vip1; } // 如果通过经验值得出的vipLevel比昨天的要低,那就用昨天的 if (vipLevel.compareTo(modelYesterday.vip_level) > 0) { vipLevel = modelYesterday.vip_level; } } } } row.createCell((short) 6).setCellValue(String.valueOf(vipLevel)); row.createCell((short) 7).setCellValue(ExpUtil.getLevel(model.exp)); row.createCell((short) 8).setCellValue(expAdded); } // 第六步,将文件存到指定位置 try { FileOutputStream fout = new FileOutputStream(Config.FILE_PATH + fileName); wb.write(fout); fout.close(); } catch (Exception e) { e.printStackTrace(); } }
7266c959-979f-4810-b11c-96610312baf7
public static String[][] readExcel(File file, int ignoreRows) throws FileNotFoundException, IOException { List<String[]> result = new ArrayList<String[]>(); int rowSize = 0; BufferedInputStream in = new BufferedInputStream(new FileInputStream( file)); // 打开HSSFWorkbook POIFSFileSystem fs = new POIFSFileSystem(in); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFCell cell = null; for (int sheetIndex = 0; sheetIndex < wb.getNumberOfSheets(); sheetIndex++) { HSSFSheet st = wb.getSheetAt(sheetIndex); // 第一行为标题,不取 for (int rowIndex = ignoreRows; rowIndex <= st.getLastRowNum(); rowIndex++) { HSSFRow row = st.getRow(rowIndex); if (row == null) { continue; } int tempRowSize = row.getLastCellNum() + 1; if (tempRowSize > rowSize) { rowSize = tempRowSize; } String[] values = new String[rowSize]; Arrays.fill(values, ""); boolean hasValue = false; for (short columnIndex = 0; columnIndex <= row.getLastCellNum(); columnIndex++) { String value = ""; cell = row.getCell(columnIndex); if (cell != null) { // 注意:一定要设成这个,否则可能会出现乱码 // cell.setEncoding(HSSFCell.ENCODING_UTF_16); switch (cell.getCellType()) { case HSSFCell.CELL_TYPE_STRING: value = cell.getStringCellValue(); break; case HSSFCell.CELL_TYPE_NUMERIC: if (HSSFDateUtil.isCellDateFormatted(cell)) { Date date = cell.getDateCellValue(); if (date != null) { value = new SimpleDateFormat("yyyy-MM-dd") .format(date); } else { value = ""; } } else { value = new DecimalFormat("0").format(cell .getNumericCellValue()); } break; case HSSFCell.CELL_TYPE_FORMULA: // 导入时如果为公式生成的数据则无值 if (!cell.getStringCellValue().equals("")) { value = cell.getStringCellValue(); } else { value = cell.getNumericCellValue() + ""; } break; case HSSFCell.CELL_TYPE_BLANK: break; case HSSFCell.CELL_TYPE_ERROR: value = ""; break; case HSSFCell.CELL_TYPE_BOOLEAN: value = (cell.getBooleanCellValue() == true ? "Y" : "N"); break; default: value = ""; } } if (columnIndex == 0 && value.trim().equals("")) { break; } values[columnIndex] = rightTrim(value); hasValue = true; } if (hasValue) { result.add(values); } } } in.close(); String[][] returnArray = new String[result.size()][rowSize]; for (int i = 0; i < returnArray.length; i++) { returnArray[i] = (String[]) result.get(i); } return returnArray; }
ed5216a6-e109-488e-b58e-92c28483dd49
public static String rightTrim(String str) { if (str == null) { return ""; } int length = str.length(); for (int i = length - 1; i >= 0; i--) { if (str.charAt(i) != 0x20) { break; } length--; } return str.substring(0, length); }
b410f540-531f-4bfc-9edb-fb4410bfd44f
@Override public int compare(PersonModel lhs, PersonModel rhs) { if (lhs.exp > rhs.exp) { return -1; } else { return 1; } }
0bd5436a-39a1-41d8-9715-c2b64257eb6b
public static void writeFileToSD(String fileName, String content) { try { String pathName = Config.FILE_PATH; File path = new File(pathName); File file = new File(pathName + fileName); if (!path.exists()) { path.mkdir(); } if (!file.exists()) { file.createNewFile(); } FileOutputStream stream = new FileOutputStream(file); String s = content; byte[] buf = s.getBytes(); stream.write(buf); stream.close(); } catch (Exception e) { System.out.println("error + " + e.toString()); } }
2ae4ae34-14c6-4892-9692-5d8b7b5e1754
public static String getJsonFromAssets(String filePath) { InputStream is; Writer writer = new StringWriter(); char[] buffer = new char[8 * 1024]; try { is = new FileInputStream(new File(filePath)); Reader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); int n = 0; while ((n = reader.read(buffer)) != -1) { writer.write(buffer, 0, n); } is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { } return writer.toString(); }
b8125c78-b079-4cc5-b94f-81b2fb760919
public static int getLevel(int exp){ int level=0; while(exp>0){ //基数为EXP_BASIC,每增加一级,累加EXP_ADD exp-=(level*EXP_ADD+EXP_BASIC); level++; } return level-1; }
2a495713-a23d-458c-a77f-69352f5be3cf
public static String sendGet(String url) { String result = ""; BufferedReader in = null; try { URL realUrl = new URL(url); // 打开和URL之间的连接 URLConnection connection = realUrl.openConnection(); // 设置通用的请求属性 connection.setRequestProperty("accept", "*/*"); connection.setRequestProperty("connection", "Keep-Alive"); connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"); // 建立实际的连接 connection.connect(); // 获取所有响应头字段 Map<String, List<String>> map = connection.getHeaderFields(); // 遍历所有的响应头字段 // for (String key : map.keySet()) { // System.out.println(key + "--->" + map.get(key)); // } // 定义 BufferedReader输入流来读取URL的响应 in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = in.readLine()) != null) { result += line; } } catch (Exception e) { System.out.println("发送GET请求出现异常!" + e); e.printStackTrace(); } // 使用finally块来关闭输入流 finally { try { if (in != null) { in.close(); } } catch (Exception e2) { e2.printStackTrace(); } } return result; }
f0b68faa-4ad3-4b2e-8c77-67cac2a66a47
String getData();
f6348d99-6ccb-46a0-8b60-542ee6a7f41b
Double getX();
82776115-675a-4510-819c-0114b5299cfc
Double getY();
492ee90a-cdb7-4e2c-9b53-bb0448e4ab5c
public ClojureBeanDefinitionParser() { }