public void testCustomCollections() {
   assertEquals(LinkedHashSet.class, custom.getClass());
   final Iterator<?> i = custom.iterator();
   assertEquals(new File("FOO"), i.next());
   assertEquals("BAR", i.next());
   assertFalse(i.hasNext());
 }
Example #2
0
 /**
  * Create a new {@link Set} with the same type as the provided {@code set} and populate it with
  * all elements of {@code list}.
  *
  * @param set the {@link Set} to be used as return type, must not be null
  * @param list the {@link List} to populate the {@link Set}
  * @return a new {@link Set} populated with all elements of the provided {@link List}
  */
 @SuppressWarnings("unchecked")
 protected Set<E> createSetBasedOnList(final Set<E> set, final List<E> list) {
   Set<E> subSet;
   if (set.getClass().equals(HashSet.class)) {
     subSet = new HashSet<E>(list.size());
   } else {
     try {
       subSet = set.getClass().newInstance();
     } catch (final InstantiationException ie) {
       subSet = new HashSet<E>();
     } catch (final IllegalAccessException iae) {
       subSet = new HashSet<E>();
     }
   }
   subSet.addAll(list);
   return subSet;
 }
 @Override
 public void writeObject(ObjectOutput output, Set set) throws IOException {
   int number = numbers.get(set.getClass(), UNKNOWN_ENUM_SET);
   if (number == UNKNOWN_ENUM_SET) {
     // Fallback on standard object write
     output.writeObject(set);
   } else {
     output.writeByte(number);
     MarshallUtil.marshallCollection(set, output);
   }
 }
Example #4
0
 public void show() {
   System.out.println(cid);
   System.out.println(cname);
   System.out.println(email);
   System.out.println(phone);
   System.out.println(emails);
   System.out.println(phones);
   System.out.println(refs);
   System.out.println(myprops);
   System.out.println(address);
   for (Account acc : accounts) {
     System.out.println(acc);
   }
   System.out.println(emails.getClass().getName());
   System.out.println(phones.getClass().getName());
   System.out.println(myprops.getClass().getName());
 }
  @Test
  public void wrapperTypesTest() throws Exception {

    Object[] inputs = {
      true,
      new Byte("1").byteValue(),
      new Character('a').charValue(),
      new Double(23.01).doubleValue(),
      new Float(46.02).floatValue(),
      1011,
      1012,
      new Short("10").shortValue(),
      "string",
    };

    for (Object input : inputs) {
      logger.debug("Testing round trip serialization in wrapper for " + input.getClass().getName());
      Object copyInput = wrapperRoundTrip(input);
      assertEquals(
          input.getClass().getSimpleName() + " wrapped round trip failed!", input, copyInput);
    }

    Integer[] integerArr = {1039, 3858, 239502};
    int[] intArr = {1039, 3858, 239502};
    double[] doubleArr = {2.01, 3.02, 4.03};
    String[] stringArr = {"all", "about", "that", "base"};

    // check that constructor works
    new JaxbArray(doubleArr);

    Object[] arrInputs = {intArr, integerArr, doubleArr, stringArr};

    for (Object input : arrInputs) {
      logger.debug("Testing round trip serialization in wrapper for " + input.getClass().getName());
      int length = Array.getLength(input);
      Object copyInput = wrapperRoundTrip(input);
      assertNotNull("Null copy for " + input.getClass().getName(), copyInput);
      assertEquals("Array length", Array.getLength(input), Array.getLength(copyInput));
      for (int i = 0; i < length; ++i) {
        assertEquals(
            "Element " + i + " inequal in " + input.getClass().getSimpleName() + " instance",
            Array.get(input, i),
            Array.get(copyInput, i));
      }
    }

    {
      List<String> list = new ArrayList<String>();
      list.add("one");
      List<String> copyList = wrapperRoundTrip(list);
      assertEquals(
          list.getClass().getSimpleName() + "round trip failed!",
          list.iterator().next(),
          copyList.iterator().next());
    }

    {
      Set<String> set = new HashSet<String>();
      set.add("one");
      Set<String> copySet = wrapperRoundTrip(set);
      assertEquals(
          set.getClass().getSimpleName() + "round trip failed!",
          set.iterator().next(),
          copySet.iterator().next());
    }

    {
      Map<String, Object> map = new HashMap<String, Object>(1);
      map.put("one", "two");
      Map<String, Object> copyMap = wrapperRoundTrip(map);
      assertEquals(
          copyMap.getClass().getSimpleName() + " round trip failed!",
          map.get("one"),
          copyMap.get("one"));
    }
  }