@Test public void given_copy_on_read_when_copyElementForWriteIfNeeded_with_Element_then_returns_same() { CopyStrategyHandler copyStrategyHandler = new CopyStrategyHandler(true, false, copyStrategy, loader); Element element = new Element("key", "value"); assertThat(copyStrategyHandler.copyElementForWriteIfNeeded(element), sameInstance(element)); }
Element copyElementForWriteIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element, loader); } else if (copyOnWrite) { return copyStrategy.copyForRead(copyStrategy.copyForWrite(element, loader), loader); } else { return element; } }
CopyStrategyHandler { Element copyElementForWriteIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element, loader); } else if (copyOnWrite) { return copyStrategy.copyForRead(copyStrategy.copyForWrite(element, loader), loader); } else { return element; } } }
CopyStrategyHandler { Element copyElementForWriteIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element, loader); } else if (copyOnWrite) { return copyStrategy.copyForRead(copyStrategy.copyForWrite(element, loader), loader); } else { return element; } } CopyStrategyHandler(boolean copyOnRead, boolean copyOnWrite, ReadWriteCopyStrategy<Element> copyStrategy, ClassLoader loader); }
CopyStrategyHandler { Element copyElementForWriteIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element, loader); } else if (copyOnWrite) { return copyStrategy.copyForRead(copyStrategy.copyForWrite(element, loader), loader); } else { return element; } } CopyStrategyHandler(boolean copyOnRead, boolean copyOnWrite, ReadWriteCopyStrategy<Element> copyStrategy, ClassLoader loader); Element copyElementForReadIfNeeded(Element element); }
CopyStrategyHandler { Element copyElementForWriteIfNeeded(Element element) { if (element == null) { return null; } if (copyOnRead && copyOnWrite) { return copyStrategy.copyForWrite(element, loader); } else if (copyOnWrite) { return copyStrategy.copyForRead(copyStrategy.copyForWrite(element, loader), loader); } else { return element; } } CopyStrategyHandler(boolean copyOnRead, boolean copyOnWrite, ReadWriteCopyStrategy<Element> copyStrategy, ClassLoader loader); Element copyElementForReadIfNeeded(Element element);  }