FlatFileBufferLinkedList implements NodeStateEntryList { public void add(@NotNull NodeStateEntry item) { Preconditions.checkArgument(item != null, "Can't add null to the list"); long incomingSize = item.estimatedMemUsage(); long memUsage = estimatedMemoryUsage(); Preconditions.checkState(memUsage + incomingSize <= memLimit, String.format( "Adding item (%s) estimated with %s bytes would increase mem usage beyond upper limit (%s)." + " Current estimated mem usage is %s bytes", item.getPath(), incomingSize, memLimit, memUsage)); tail.next = new ListNode(item); tail = tail.next; size++; this.memUsage += incomingSize; } FlatFileBufferLinkedList();  FlatFileBufferLinkedList(long memLimit); void add(@NotNull NodeStateEntry item); NodeStateEntry remove(); @Override Iterator<NodeStateEntry> iterator(); @Override int size(); @Override boolean isEmpty(); @Override long estimatedMemoryUsage(); @Override void close();  }
@Test public void add() { try { list.add(null); fail("Adding null must throw IllegalArgumentException"); } catch (IllegalArgumentException iae) { } list.add(testNode("/")); }