@Test public void testSizeOf() throws Exception { Assume.assumeThat(CURRENT_JVM_INFORMATION.getMinimumObjectSize(), is(CURRENT_JVM_INFORMATION.getObjectAlignment())); SizeOf sizeOf = new CrossCheckingSizeOf(); Assert.assertThat(deepSizeOf(sizeOf, TimeUnit.SECONDS), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, Object.class), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, 1), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, BigInteger.ZERO), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, BigDecimal.ZERO), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, MathContext.UNLIMITED), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, Locale.ENGLISH), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, Logger.global), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, Collections.EMPTY_SET), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, Collections.EMPTY_LIST), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, Collections.EMPTY_MAP), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, String.CASE_INSENSITIVE_ORDER), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, System.err), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, Proxy.NO_PROXY), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, CodingErrorAction.REPORT), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, DatatypeConstants.DAYS), is(0L)); Assert.assertThat(deepSizeOf(sizeOf, DatatypeConstants.TIME), is(0L)); assertThat(sizeOf.sizeOf(new Object()), "sizeOf(new Object())"); assertThat(sizeOf.sizeOf(new Integer(1)), "sizeOf(new Integer(1))"); assertThat(sizeOf.sizeOf(1000), "sizeOf(1000)"); assertThat(deepSizeOf(sizeOf, new SomeClass(false)), "deepSizeOf(new SomeClass(false))"); assertThat(deepSizeOf(sizeOf, new SomeClass(true)), "deepSizeOf(new SomeClass(true))"); assertThat(sizeOf.sizeOf(new Object[] { }), "sizeOf(new Object[] { })"); assertThat(sizeOf.sizeOf(new Object[] { new Object(), new Object(), new Object(), new Object() }), "sizeOf(new Object[] { new Object(), new Object(), new Object(), new Object() })"); assertThat(sizeOf.sizeOf(new int[] { }), "sizeOf(new int[] { })"); assertThat(sizeOf.sizeOf(new int[] { 987654, 876543, 765432, 654321 }), "sizeOf(new int[] { 987654, 876543, 765432, 654321 })"); assertThat(deepSizeOf(sizeOf, new Pair(null, null)), "deepSizeOf(new Pair(null, null))"); assertThat(deepSizeOf(sizeOf, new Pair(new Object(), null)), "deepSizeOf(new Pair(new Object(), null))"); assertThat(deepSizeOf(sizeOf, new Pair(new Object(), new Object())), "deepSizeOf(new Pair(new Object(), new Object()))"); assertThat(deepSizeOf(sizeOf, new ReentrantReadWriteLock()), "deepSizeOf(new ReentrantReadWriteLock())"); if (!sizeOfFailures.isEmpty()) { StringBuilder sb = new StringBuilder(); for (AssertionError e : sizeOfFailures) { sb.append(e.toString()).append('\n'); } Assert.fail(sb.toString()); } List<Object> list1 = new ArrayList<Object>(); List<Object> list2 = new ArrayList<Object>(); Object someInstance = new Object(); list1.add(someInstance); list2.add(someInstance); Assert.assertThat(deepSizeOf(sizeOf, list1), is(deepSizeOf(sizeOf, list2))); Assert.assertThat(deepSizeOf(sizeOf, list1, list2) < (deepSizeOf(sizeOf, list1) + deepSizeOf(sizeOf, list2)), is(true)); list2.add(new Object()); Assert.assertThat(deepSizeOf(sizeOf, list2) > deepSizeOf(sizeOf, list1), is(true)); }
public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); }
SizeOf { public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); } }
SizeOf { public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); } SizeOf(SizeOfFilter fieldFilter, boolean caching); }
SizeOf { public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); } SizeOf(SizeOfFilter fieldFilter, boolean caching); abstract long sizeOf(Object obj); Size deepSizeOf(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... obj); }
SizeOf { public SizeOf(SizeOfFilter fieldFilter, boolean caching) { ObjectGraphWalker.Visitor visitor; if (caching) { visitor = new CachingSizeOfVisitor(); } else { visitor = new SizeOfVisitor(); } this.walker = new ObjectGraphWalker(visitor, fieldFilter); } SizeOf(SizeOfFilter fieldFilter, boolean caching); abstract long sizeOf(Object obj); Size deepSizeOf(int maxDepth, boolean abortWhenMaxDepthExceeded, Object... obj);  }