@Override public <T> T getSnapshotter(Class<? extends T> type) { FileCollectionSnapshotter snapshotter = snapshotters.get(type); if (snapshotter == null) { throw new IllegalStateException(String.format("No snapshotter registered with type '%s'", type.getName())); } return uncheckedCast(snapshotter); } }
public void applyImperative(@Nullable String pluginId, Plugin<?> plugin) { // TODO validate that the plugin accepts this kind of argument Plugin<T> cast = uncheckedCast(plugin); cast.apply(target); }
@Override ImmutableActionSet<T> doAdd(Action<? super T> action) { if (action.equals(singleAction)) { return this; } ImmutableSet<Action<? super T>> of = Cast.uncheckedCast(ImmutableSet.of(singleAction, action)); return new CompositeSet<T>(of); }
@Override protected List<T> toMutationSafe(Collection<?> backingCollection) { return new ListBackedCollection<T>(Cast.<List<T>>uncheckedCast(backingCollection), state, elementType); } }
@Override protected Set<T> toMutationSafe(Collection<?> backingCollection) { return new SetBackedCollection<T>(Cast.<Set<T>>uncheckedCast(backingCollection), state, elementType); } }
<U extends T> void copyFactory(DefaultPolymorphicNamedEntityInstantiator<T> source, Class<U> type) { NamedDomainObjectFactory<U> factory = uncheckedCast(source.factories.get(type)); registerFactory(type, factory); } }
public static <T> Collection<? extends T> checkedCast(Class<T> type, Collection<?> input) { for (Object o : input) { cast(type, o); } return Cast.uncheckedCast(input); }
@Override public FileWatcherEvent transform(WatchEvent<?> event) { WatchEvent.Kind kind = event.kind(); File file = null; if (kind.type() == Path.class) { WatchEvent<Path> ev = Cast.uncheckedCast(event); file = watchedPath.resolve(ev.context()).toFile(); } return toEvent(kind, file); } };
public <S extends T> CollectionEventRegister<S> filtered(CollectionFilter<S> filter) { CollectionEventRegister<S> cast = Cast.uncheckedCast(this); return new FilteringCollectionEventRegister<S>(filter, cast); } }
private <T> StructSchema<T> getStructSchema(ModelType<T> type) { ModelSchema<T> schema = schemaStore.getSchema(type); if (!(schema instanceof StructSchema)) { throw new IllegalArgumentException(String.format("Type '%s' is not a struct.", type.getDisplayName())); } return Cast.uncheckedCast(schema); }
/** * Returns a spec that selects the intersection of those items selected by the given specs. Returns a spec that selects everything when no specs provided. */ public static <T> Spec<T> intersect(Spec<? super T>... specs) { if (specs.length == 0) { return satisfyAll(); } if (specs.length == 1) { return Cast.uncheckedCast(specs[0]); } return doIntersect(Arrays.asList(specs)); }
@Override public <T> T getAttribute(Attribute<T> key) { if (key.equals(attribute)) { return Cast.uncheckedCast(value); } if (parent != null) { return parent.getAttribute(key); } return null; }
@Override public <T> ModelView<? extends T> asMutable(ModelType<T> type, MutableModelNode modelNode, ModelRuleDescriptor ruleDescriptor) { if (canBeViewedAs(type)) { return Cast.uncheckedCast(toView(modelNode, ruleDescriptor, true)); } else { return null; } }
private TypeOf<Object> preferredPublicTypeOf(Object extension, Class<?> defaultType) { if (extension instanceof HasPublicType) { return uncheckedCast(((HasPublicType) extension).getPublicType()); } return TypeOf.<Object>typeOf(defaultType); }
public <T> PluginImplementation<T> inspect(Class<T> clazz) { PluginImplementation<T> implementation = maybeInspect(clazz); if (implementation != null) { return implementation; } // Unknown type - just inspect ourselves. Should instead share this with all registries return Cast.uncheckedCast(uncheckedGet(classMappings, clazz)); }
private Plugin<?> producePluginInstance(Class<?> pluginClass) { // This insanity is needed for the case where someone calls pluginContainer.add(new SomePlugin()) // That is, the plugin container has the instance that we want, but we don't think (we can't know) it has been applied Object instance = findInstance(pluginClass, pluginContainer); if (instance == null) { instance = instantiatePlugin(pluginClass); } return Cast.uncheckedCast(instance); }
@Override public Object create(MutableModelNode modelNode) { ImplementationFactory<PUBLIC, Object> implementationFactory = Cast.uncheckedCast(implementationRegistration.factory); return implementationFactory.create(publicType, implementationRegistration.implementationType, modelNode.getPath().getName(), modelNode); }
public <T> PotentialPlugin<T> inspect(Class<T> type) { boolean implementsInterface = Plugin.class.isAssignableFrom(type); boolean hasRules = this.modelRuleSourceDetector.hasRules(type); if (implementsInterface) { @SuppressWarnings("unchecked") Class<? extends Plugin<?>> cast = (Class<? extends Plugin<?>>) type; return Cast.uncheckedCast(toImperative(cast, hasRules)); } else if (hasRules) { return new PotentialPureRuleSourceClassPlugin<T>(type); } else { return new PotentialUnknownTypePlugin<T>(type); } }
@SuppressWarnings("unused") public static void collectTaskValidationProblems(Class<?> task, Map<String, Boolean> problems) { TaskClassInfoStore infoStore = new DefaultTaskClassInfoStore(new DefaultTaskClassValidatorExtractor(new ClasspathPropertyAnnotationHandler(), new CompileClasspathPropertyAnnotationHandler())); TaskClassInfo info = infoStore.getTaskClassInfo(Cast.<Class<? extends Task>>uncheckedCast(task)); for (TaskClassValidationMessage validationMessage : info.getValidator().getValidationMessages()) { problems.put(String.format("Task type '%s': %s.", task.getName(), validationMessage), Boolean.FALSE); } } }
public static <T extends TaskFilePropertySpec> SortedSet<ResolvedTaskOutputFilePropertySpec> resolveFileProperties(ImmutableSortedSet<T> properties) { ImmutableSortedSet.Builder<ResolvedTaskOutputFilePropertySpec> builder = ImmutableSortedSet.naturalOrder(); for (T property : properties) { CacheableTaskOutputFilePropertySpec cacheableProperty = Cast.uncheckedCast(property); builder.add(new ResolvedTaskOutputFilePropertySpec(cacheableProperty.getPropertyName(), cacheableProperty.getOutputType(), cacheableProperty.getOutputFile())); } return builder.build(); } }