All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cryptomator.cryptofs.attr.AttributeViewModule Maven / Gradle / Ivy

There is a newer version: 2.7.1-beta1
Show newest version
package org.cryptomator.cryptofs.attr;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ClassKey;
import dagger.multibindings.IntoMap;

import javax.inject.Provider;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.FileAttributeView;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.nio.file.attribute.PosixFileAttributeView;
import java.util.Map;
import java.util.Optional;

@Module
abstract class AttributeViewModule {

	@Binds
	@IntoMap
	@ClassKey(BasicFileAttributeView.class)
	@AttributeViewScoped
	public abstract FileAttributeView provideBasicFileAttributeView(CryptoBasicFileAttributeView view);

	@Binds
	@IntoMap
	@ClassKey(PosixFileAttributeView.class)
	@AttributeViewScoped
	public abstract FileAttributeView providePosixFileAttributeView(CryptoPosixFileAttributeView view);

	@Binds
	@IntoMap
	@ClassKey(DosFileAttributeView.class)
	@AttributeViewScoped
	public abstract FileAttributeView provideDosFileAttributeView(CryptoDosFileAttributeView view);

	@Binds
	@IntoMap
	@ClassKey(FileOwnerAttributeView.class)
	@AttributeViewScoped
	public abstract FileAttributeView provideFileOwnerAttributeView(CryptoFileOwnerAttributeView view);

	@Provides
	@AttributeViewScoped
	public static Optional provideAttributeView(Map, Provider> providers, Class requestedType) {
		Provider provider = providers.get(requestedType);
		if (provider == null) {
			return Optional.empty();
		} else {
			return Optional.of(provider.get());
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy