Beispiel #1
0
  public static void main(String[] args) throws Exception {
    String hostname = args[0];
    String username = args[1];
    String password = args[2];

    ObjectMapper mapper = new ObjectMapper();

    AnotherObject ao = new AnotherObject();
    ao.setName("Foo");
    ao.getSomeList().add("Item 1");
    ao.getSomeList().add("Item 2");
    ao.getSomeList().add("Item 3");

    ao.getaMap().put("Key 1", "Value 1");
    ao.getaMap().put("Key 2", 34);
    ao.getaMap().put("Key 3", new BigDecimal(1234));
    ao.getaMap().put("Key 4", 100d);

    MyObject mo = new MyObject();
    mo.setName("Bar");
    // mo.setContent(mapper.writeValueAsBytes(ao));
    mo.setContent(mapper.writeValueAsString(ao).getBytes());

    Session s = new Session(hostname, 5984, username, password);

    Database db = s.createDatabaseIfNotExists("mydb");

    Document d = new Document();
    DocumentUtils.serialiseIntoDocument(d, mo);

    db.saveDocument(d);

    s.close();
  }
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Servlet TestServlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
    Client client = ClientBuilder.newClient();
    client.register(MyReader.class).register(MyWriter.class);

    WebTarget target =
        client.target(
            "http://"
                + request.getServerName()
                + ":"
                + request.getServerPort()
                + request.getContextPath()
                + "/webresources/endpoint");
    System.out.println("POST request");
    MyObject mo =
        target
            .request()
            .post(
                Entity.entity(new MyObject("Duke", 18), MediaType.APPLICATION_JSON),
                MyObject.class);
    out.println("Received response: " + mo.getName() + ", " + mo.getAge() + "<br><br>");

    out.println("Check server.log for client/server interceptor output.");
    out.println("</body>");
    out.println("</html>");
  }
 @Test
 public void test4() {
   MyObject mo = new MyObject();
   mo.str = "test4";
   List<Object> list = new ArrayList<Object>();
   list.add(mo);
   TestUtil.sp(list);
   TestUtil.sp(list.toArray(new String[] {}));
 }
 /** Test: Can String in Object be modified by reference? Result: Yes */
 @Test
 public void test1() {
   ArrayList<MyObject> mys = new ArrayList<ListTest.MyObject>();
   MyObject mo = new MyObject();
   mo.str = "init set";
   mys.add(mo);
   TestUtil.sp(mys);
   mo.str = "first set";
   TestUtil.sp(mys);
 }
 /**
  * Test: Can parameter modified by Method? Result: Properties can be modified, but can't set
  * parameter to null
  */
 @Test
 public void test3() {
   MyObject mo = new MyObject();
   mo.str = "lala";
   TestUtil.sp("Init - " + mo);
   test3_method(mo);
   TestUtil.sp("Change Property - " + mo);
   mo.str = "tonull";
   test3_method(mo);
   TestUtil.sp("Set Object to null - " + mo);
 }
 /** Test: Can enum in Object be modified by reference? Result: No, value type */
 @Test
 public void test2() {
   MyObject mo = new MyObject();
   mo.type = MyType.T1;
   TestUtil.sp(mo);
   @SuppressWarnings("unused")
   MyType t = mo.type;
   t = null;
   TestUtil.sp(mo);
   t = MyType.T2;
   TestUtil.sp(mo);
 }
 public void test3_method(MyObject obj) {
   if (obj.str.equals("tonull")) {
     TestUtil.sp("set obj to null");
     obj = null;
   } else {
     obj.str = "changed";
   }
 }
Beispiel #8
0
  static long insert(MyObject r) {
    ContentValues values;

    values = new ContentValues();
    values.put(res.getString(R.string.KEY_BOOKID), r.getVerseWrapper().getBookID());
    values.put(res.getString(R.string.KEY_BOOK_VERSION_NAME), r.getBookVersionName());
    values.put(res.getString(R.string.KEY_CHAPTER), r.getVerseWrapper().getChapter());
    values.put(res.getString(R.string.KEY_VERSE), r.getVerseWrapper().getVerse());
    values.put(res.getString(R.string.KEY_HEADER), r.getHeader());
    values.put(res.getString(R.string.KEY_TEXT), r.getText());
    values.put(res.getString(R.string.KEY_VERSION), r.getVersion());
    values.put(res.getString(R.string.KEY_LASTACCESS), r.getLastAccess());

    return sqlite.insert(res.getString(R.string.DATABASE_TABLE_MAIN), null, values);
  }
  public void testMatrixPickler() {
    Comparator<MyObject[][]> momCmp =
        new Comparator<MyObject[][]>() {
          @Override
          public int compare(MyObject[][] o1, MyObject[][] o2) {
            if (o1 == null && o2 == null) return 0;
            if (o1 == null || o2 == null) return 1;
            if (o1.length != o2.length) return 1;
            outer:
            for (int i = 0; i < o1.length; ++i) {
              if (o1[i] == null && o2[i] == null) continue outer;
              if (o1[i] == null || o2[i] == null) return 1;
              if (o1[i].length != o2[i].length) return 1;
              inner:
              for (int j = 0; j < o1[i].length; ++j) {
                if (o1[i][j] == null && o2[i][j] == null) continue inner;
                if (o1[i][j] == null || o2[i][j] == null) return 1;
                if (!o1[i][j].equals(o2[i][j])) return 1;
              }
            }
            return 0;
          }
        };

    MyObjectMatrixPickler p = GWT.create(MyObjectMatrixPickler.class);
    runPUTest(
        p,
        new MyObject[][] {
          MyObject.create(1, 2, 3),
          MyObject.create(4, 5, 6, 7),
          MyObject.create(7, 8, 9, 10, 11),
          MyObject.create(),
          null
        },
        momCmp);
    runPUTest(p, new MyObject[][] {}, momCmp);
    runPUTest(p, null, momCmp);
  }
 public void foo3() {
   Map.@SuppressWarnings("unsused") Entry entry;
   MyObject myObject = new MyObject();
   myObject.<@SuppressWarnings("unsused") String>myMethod();
   myObject.new @SuppressWarnings("unsused") MyObject2();
 }
 @Override
 public int compare(MyObject o1, MyObject o2) {
   return o1.getNumber() - o2.getNumber();
 }
 @Override
 public int compare(MyObject o1, MyObject o2) {
   return o1.getDay().compareToIgnoreCase(o2.getDay());
 }
Beispiel #13
0
 @Override
 public void run() {
   System.out.println(MyObject.getInstance().hashCode());
 }