@Test public void testAdaptablesOtherThanResourceYieldNull() { assertThat(this.testee.getAdapter(new Object(), Object.class)).isNull(); }
@Override @SuppressWarnings("unchecked") public <T> T getAdapter(@Nonnull Object adaptable, @Nonnull Class<T> target) { Resource resource = null; if (adaptable instanceof Resource) { resource = (Resource) adaptable; } if (adaptable instanceof SlingHttpServletRequest) { resource = ((SlingHttpServletRequest) adaptable).getResource(); } if (resource == null) { return null; } final Key key = key(target); Optional<T> cachedModel = this.cache.get(resource, key); if (cachedModel == null) { Collection<ResolvedModelSource<?>> models = this.registry.lookupMostSpecificModels(resource, target); if (models == null || models.isEmpty()) { this.cache.put(resource, key, null); return null; } if (models.size() != 1) { throw new AmbiguousModelAssociationException("There is more than one model that maps " + resource.getPath() + " to " + target.getName() + ": " + join(models, ", ") + "."); } T model = (T) this.mapper.map(resource, models.iterator().next()); this.cache.put(resource, key, model); return model; } return cachedModel.orElse(null); }
ResourceToModelAdapter implements AdapterFactory { @Override @SuppressWarnings("unchecked") public <T> T getAdapter(@Nonnull Object adaptable, @Nonnull Class<T> target) { Resource resource = null; if (adaptable instanceof Resource) { resource = (Resource) adaptable; } if (adaptable instanceof SlingHttpServletRequest) { resource = ((SlingHttpServletRequest) adaptable).getResource(); } if (resource == null) { return null; } final Key key = key(target); Optional<T> cachedModel = this.cache.get(resource, key); if (cachedModel == null) { Collection<ResolvedModelSource<?>> models = this.registry.lookupMostSpecificModels(resource, target); if (models == null || models.isEmpty()) { this.cache.put(resource, key, null); return null; } if (models.size() != 1) { throw new AmbiguousModelAssociationException("There is more than one model that maps " + resource.getPath() + " to " + target.getName() + ": " + join(models, ", ") + "."); } T model = (T) this.mapper.map(resource, models.iterator().next()); this.cache.put(resource, key, model); return model; } return cachedModel.orElse(null); } }
ResourceToModelAdapter implements AdapterFactory { @Override @SuppressWarnings("unchecked") public <T> T getAdapter(@Nonnull Object adaptable, @Nonnull Class<T> target) { Resource resource = null; if (adaptable instanceof Resource) { resource = (Resource) adaptable; } if (adaptable instanceof SlingHttpServletRequest) { resource = ((SlingHttpServletRequest) adaptable).getResource(); } if (resource == null) { return null; } final Key key = key(target); Optional<T> cachedModel = this.cache.get(resource, key); if (cachedModel == null) { Collection<ResolvedModelSource<?>> models = this.registry.lookupMostSpecificModels(resource, target); if (models == null || models.isEmpty()) { this.cache.put(resource, key, null); return null; } if (models.size() != 1) { throw new AmbiguousModelAssociationException("There is more than one model that maps " + resource.getPath() + " to " + target.getName() + ": " + join(models, ", ") + "."); } T model = (T) this.mapper.map(resource, models.iterator().next()); this.cache.put(resource, key, model); return model; } return cachedModel.orElse(null); }  }
ResourceToModelAdapter implements AdapterFactory { @Override @SuppressWarnings("unchecked") public <T> T getAdapter(@Nonnull Object adaptable, @Nonnull Class<T> target) { Resource resource = null; if (adaptable instanceof Resource) { resource = (Resource) adaptable; } if (adaptable instanceof SlingHttpServletRequest) { resource = ((SlingHttpServletRequest) adaptable).getResource(); } if (resource == null) { return null; } final Key key = key(target); Optional<T> cachedModel = this.cache.get(resource, key); if (cachedModel == null) { Collection<ResolvedModelSource<?>> models = this.registry.lookupMostSpecificModels(resource, target); if (models == null || models.isEmpty()) { this.cache.put(resource, key, null); return null; } if (models.size() != 1) { throw new AmbiguousModelAssociationException("There is more than one model that maps " + resource.getPath() + " to " + target.getName() + ": " + join(models, ", ") + "."); } T model = (T) this.mapper.map(resource, models.iterator().next()); this.cache.put(resource, key, model); return model; } return cachedModel.orElse(null); }  @Override @SuppressWarnings("unchecked") T getAdapter(@Nonnull Object adaptable, @Nonnull Class<T> target); }
ResourceToModelAdapter implements AdapterFactory { @Override @SuppressWarnings("unchecked") public <T> T getAdapter(@Nonnull Object adaptable, @Nonnull Class<T> target) { Resource resource = null; if (adaptable instanceof Resource) { resource = (Resource) adaptable; } if (adaptable instanceof SlingHttpServletRequest) { resource = ((SlingHttpServletRequest) adaptable).getResource(); } if (resource == null) { return null; } final Key key = key(target); Optional<T> cachedModel = this.cache.get(resource, key); if (cachedModel == null) { Collection<ResolvedModelSource<?>> models = this.registry.lookupMostSpecificModels(resource, target); if (models == null || models.isEmpty()) { this.cache.put(resource, key, null); return null; } if (models.size() != 1) { throw new AmbiguousModelAssociationException("There is more than one model that maps " + resource.getPath() + " to " + target.getName() + ": " + join(models, ", ") + "."); } T model = (T) this.mapper.map(resource, models.iterator().next()); this.cache.put(resource, key, model); return model; } return cachedModel.orElse(null); }  @Override @SuppressWarnings("unchecked") T getAdapter(@Nonnull Object adaptable, @Nonnull Class<T> target);  }