@Test public void testEnsureBestWrapper() throws Exception { Item alreadyFacade = getFacade(mock(Node.class)); assertSame("same if already facade", alreadyFacade, ItemFacade.ensureBestWrapper(alreadyFacade, sessionFacade)); Item versionHistory = mock(VersionHistory.class); assertTrue("is VersionHistory", ItemFacade.ensureBestWrapper(versionHistory, sessionFacade) instanceof VersionHistoryFacade); Item version = mock(Version.class); assertTrue("is Version", ItemFacade.ensureBestWrapper(version, sessionFacade) instanceof VersionFacade); Item justNode = mock(Node.class); assertTrue("is Node", ItemFacade.ensureBestWrapper(justNode, sessionFacade) instanceof NodeFacade); Item justProperty = mock(Property.class); assertTrue("is Property", ItemFacade.ensureBestWrapper(justProperty, sessionFacade) instanceof PropertyFacade); Item justItem = mock(Item.class); assertTrue("is Item", ItemFacade.ensureBestWrapper(justItem, sessionFacade) instanceof ItemFacade); }
@SuppressWarnings("WeakerAccess") public static @NotNull Item ensureBestWrapper(final @NotNull Item primaryItem, final @NotNull SessionFacade<?> session) { if (primaryItem instanceof ItemFacade) { return primaryItem; } else if (primaryItem instanceof Node) { return NodeFacade.wrap((Node) primaryItem, session); } else if (primaryItem instanceof Property) { return new PropertyFacade<>((Property) primaryItem, session); } else { return new ItemFacade<>(primaryItem, session); } }
ItemFacade implements Item { @SuppressWarnings("WeakerAccess") public static @NotNull Item ensureBestWrapper(final @NotNull Item primaryItem, final @NotNull SessionFacade<?> session) { if (primaryItem instanceof ItemFacade) { return primaryItem; } else if (primaryItem instanceof Node) { return NodeFacade.wrap((Node) primaryItem, session); } else if (primaryItem instanceof Property) { return new PropertyFacade<>((Property) primaryItem, session); } else { return new ItemFacade<>(primaryItem, session); } } }
ItemFacade implements Item { @SuppressWarnings("WeakerAccess") public static @NotNull Item ensureBestWrapper(final @NotNull Item primaryItem, final @NotNull SessionFacade<?> session) { if (primaryItem instanceof ItemFacade) { return primaryItem; } else if (primaryItem instanceof Node) { return NodeFacade.wrap((Node) primaryItem, session); } else if (primaryItem instanceof Property) { return new PropertyFacade<>((Property) primaryItem, session); } else { return new ItemFacade<>(primaryItem, session); } } @SuppressWarnings("WeakerAccess")  ItemFacade(final @NotNull J delegate, final @NotNull SessionFacade<S> session); }
ItemFacade implements Item { @SuppressWarnings("WeakerAccess") public static @NotNull Item ensureBestWrapper(final @NotNull Item primaryItem, final @NotNull SessionFacade<?> session) { if (primaryItem instanceof ItemFacade) { return primaryItem; } else if (primaryItem instanceof Node) { return NodeFacade.wrap((Node) primaryItem, session); } else if (primaryItem instanceof Property) { return new PropertyFacade<>((Property) primaryItem, session); } else { return new ItemFacade<>(primaryItem, session); } } @SuppressWarnings("WeakerAccess")  ItemFacade(final @NotNull J delegate, final @NotNull SessionFacade<S> session); @SuppressWarnings("WeakerAccess") static @NotNull Item ensureBestWrapper(final @NotNull Item primaryItem, final @NotNull SessionFacade<?> session); @Override final String getPath(); @Override final String getName(); @Override final Item getAncestor(int depth); @Override final Node getParent(); @Override final int getDepth(); @Override final Session getSession(); @Override final boolean isNode(); @Override final boolean isNew(); @Override final boolean isModified(); @Override final boolean isSame(Item otherItem); @Override final void accept(ItemVisitor visitor); @Override final void refresh(boolean keepChanges); @Override final void save(); @Override final void remove(); }
ItemFacade implements Item { @SuppressWarnings("WeakerAccess") public static @NotNull Item ensureBestWrapper(final @NotNull Item primaryItem, final @NotNull SessionFacade<?> session) { if (primaryItem instanceof ItemFacade) { return primaryItem; } else if (primaryItem instanceof Node) { return NodeFacade.wrap((Node) primaryItem, session); } else if (primaryItem instanceof Property) { return new PropertyFacade<>((Property) primaryItem, session); } else { return new ItemFacade<>(primaryItem, session); } } @SuppressWarnings("WeakerAccess")  ItemFacade(final @NotNull J delegate, final @NotNull SessionFacade<S> session); @SuppressWarnings("WeakerAccess") static @NotNull Item ensureBestWrapper(final @NotNull Item primaryItem, final @NotNull SessionFacade<?> session); @Override final String getPath(); @Override final String getName(); @Override final Item getAncestor(int depth); @Override final Node getParent(); @Override final int getDepth(); @Override final Session getSession(); @Override final boolean isNode(); @Override final boolean isNew(); @Override final boolean isModified(); @Override final boolean isSame(Item otherItem); @Override final void accept(ItemVisitor visitor); @Override final void refresh(boolean keepChanges); @Override final void save(); @Override final void remove();  }