選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

BeanItemContainerGenerator.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package com.vaadin.tests.components.beanitemcontainer;
  2. import java.util.Date;
  3. import com.vaadin.tests.util.PortableRandom;
  4. import com.vaadin.v7.data.util.BeanItemContainer;
  5. public class BeanItemContainerGenerator {
  6. public static BeanItemContainer<TestBean> createContainer(int size) {
  7. return createContainer(size, new Date().getTime());
  8. }
  9. public static BeanItemContainer<TestBean> createContainer(int size,
  10. long seed) {
  11. BeanItemContainer<TestBean> container = new BeanItemContainer<>(
  12. TestBean.class);
  13. PortableRandom r = new PortableRandom(seed);
  14. for (int i = 0; i < size; i++) {
  15. container.addBean(new TestBean(r));
  16. }
  17. return container;
  18. }
  19. public static class TestBean {
  20. private String name, address, city, country;
  21. private int age, shoesize;
  22. public int getAge() {
  23. return age;
  24. }
  25. public void setAge(int age) {
  26. this.age = age;
  27. }
  28. public int getShoesize() {
  29. return shoesize;
  30. }
  31. public void setShoesize(int shoesize) {
  32. this.shoesize = shoesize;
  33. }
  34. public TestBean(PortableRandom r) {
  35. age = r.nextInt(100) + 5;
  36. shoesize = r.nextInt(10) + 35;
  37. name = createRandomString(r, r.nextInt(5) + 5);
  38. address = createRandomString(r, r.nextInt(15) + 5) + " "
  39. + r.nextInt(100) + 1;
  40. city = createRandomString(r, r.nextInt(7) + 3);
  41. if (r.nextBoolean()) {
  42. country = createRandomString(r, r.nextInt(4) + 4);
  43. }
  44. }
  45. public String getName() {
  46. return name;
  47. }
  48. public void setName(String name) {
  49. this.name = name;
  50. }
  51. public String getAddress() {
  52. return address;
  53. }
  54. public void setAddress(String address) {
  55. this.address = address;
  56. }
  57. public String getCity() {
  58. return city;
  59. }
  60. public void setCity(String city) {
  61. this.city = city;
  62. }
  63. public String getCountry() {
  64. return country;
  65. }
  66. public void setCountry(String country) {
  67. this.country = country;
  68. }
  69. }
  70. public static String createRandomString(PortableRandom r, int len) {
  71. StringBuilder b = new StringBuilder();
  72. for (int i = 0; i < len; i++) {
  73. b.append((char) (r.nextInt('z' - 'a') + 'a'));
  74. }
  75. return b.toString();
  76. }
  77. }