花瓣 v4.6.12版本的 MD5 值为:6a3515d4d16d98931f1b3d25a91b257e

以下内容为反编译后的 RealmConfiguration.java 源代码,内容仅作参考


package io.realm;

import android.content.Context;
import android.text.TextUtils;
import io.realm.Realm;
import io.realm.annotations.RealmModule;
import io.realm.exceptions.RealmException;
import io.realm.internal.RealmCore;
import io.realm.internal.RealmProxyMediator;
import io.realm.internal.SharedGroup;
import io.realm.internal.modules.CompositeMediator;
import io.realm.internal.modules.FilterableMediator;
import io.realm.rx.RealmObservableFactory;
import io.realm.rx.RxObservableFactory;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public final class RealmConfiguration {
    private static final Object DEFAULT_MODULE;
    private static final RealmProxyMediator DEFAULT_MODULE_MEDIATOR;
    public static final String DEFAULT_REALM_NAME = "default.realm";
    public static final int KEY_LENGTH = 64;
    private static Boolean rxJavaAvailable;
    private final String assetFilePath;
    private final String canonicalPath;
    private final WeakReference<Context> contextWeakRef;
    private final boolean deleteRealmIfMigrationNeeded;
    private final SharedGroup.Durability durability;
    private final Realm.Transaction initialDataTransaction;
    private final byte[] key;
    private final RealmMigration migration;
    private final String realmFileName;
    private final File realmFolder;
    private final RxObservableFactory rxObservableFactory;
    private final RealmProxyMediator schemaMediator;
    private final long schemaVersion;

    static {
        Object defaultModule = Realm.getDefaultModule();
        DEFAULT_MODULE = defaultModule;
        if (defaultModule != null) {
            RealmProxyMediator moduleMediator = getModuleMediator(defaultModule.getClass().getCanonicalName());
            if (moduleMediator.transformerApplied()) {
                DEFAULT_MODULE_MEDIATOR = moduleMediator;
                return;
            }
            throw new ExceptionInInitializerError("RealmTransformer doesn't seem to be applied. Please update the project configuration to use the Realm Gradle plugin. See https://realm.io/news/android-installation-change/");
        }
        DEFAULT_MODULE_MEDIATOR = null;
    }

    static boolean access$1500() {
        return isRxJavaAvailable();
    }

    private RealmProxyMediator createSchemaMediator(Builder builder) {
        HashSet<Object> hashSet = builder.modules;
        HashSet hashSet2 = builder.debugSchema;
        if (hashSet2.size() > 0) {
            return new FilterableMediator(DEFAULT_MODULE_MEDIATOR, hashSet2);
        }
        if (hashSet.size() == 1) {
            return getModuleMediator(hashSet.iterator().next().getClass().getCanonicalName());
        }
        RealmProxyMediator[] realmProxyMediatorArr = new RealmProxyMediator[hashSet.size()];
        int i2 = 0;
        for (Object obj : hashSet) {
            realmProxyMediatorArr[i2] = getModuleMediator(obj.getClass().getCanonicalName());
            i2++;
        }
        return new CompositeMediator(realmProxyMediatorArr);
    }

    private static RealmProxyMediator getModuleMediator(String str) {
        String[] split = str.split("\\.");
        String format = String.format("io.realm.%s%s", split[split.length - 1], "Mediator");
        try {
            Constructor<?> constructor = Class.forName(format).getDeclaredConstructors()[0];
            constructor.setAccessible(true);
            return (RealmProxyMediator) constructor.newInstance(new Object[0]);
        } catch (ClassNotFoundException e2) {
            throw new RealmException("Could not find " + format, e2);
        } catch (IllegalAccessException e3) {
            throw new RealmException("Could not create an instance of " + format, e3);
        } catch (InstantiationException e4) {
            throw new RealmException("Could not create an instance of " + format, e4);
        } catch (InvocationTargetException e5) {
            throw new RealmException("Could not create an instance of " + format, e5);
        }
    }

    private static synchronized boolean isRxJavaAvailable() {
        boolean booleanValue;
        synchronized (RealmConfiguration.class) {
            if (rxJavaAvailable == null) {
                try {
                    Class.forName("i.g");
                    rxJavaAvailable = Boolean.TRUE;
                } catch (ClassNotFoundException unused) {
                    rxJavaAvailable = Boolean.FALSE;
                }
            }
            booleanValue = rxJavaAvailable.booleanValue();
        }
        return booleanValue;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || RealmConfiguration.class != obj.getClass()) {
            return false;
        }
        RealmConfiguration realmConfiguration = (RealmConfiguration) obj;
        if (this.schemaVersion == realmConfiguration.schemaVersion && this.deleteRealmIfMigrationNeeded == realmConfiguration.deleteRealmIfMigrationNeeded && this.realmFolder.equals(realmConfiguration.realmFolder) && this.realmFileName.equals(realmConfiguration.realmFileName) && this.canonicalPath.equals(realmConfiguration.canonicalPath) && Arrays.equals(this.key, realmConfiguration.key) && this.durability.equals(realmConfiguration.durability)) {
            RealmMigration realmMigration = this.migration;
            if (realmMigration == null ? realmConfiguration.migration == null : realmMigration.equals(realmConfiguration.migration)) {
                RxObservableFactory rxObservableFactory = this.rxObservableFactory;
                if (rxObservableFactory == null ? realmConfiguration.rxObservableFactory == null : rxObservableFactory.equals(realmConfiguration.rxObservableFactory)) {
                    Realm.Transaction transaction = this.initialDataTransaction;
                    if (transaction == null ? realmConfiguration.initialDataTransaction == null : transaction.equals(realmConfiguration.initialDataTransaction)) {
                        return this.schemaMediator.equals(realmConfiguration.schemaMediator);
                    }
                    return false;
                }
                return false;
            }
            return false;
        }
        return false;
    }

    public InputStream getAssetFile() throws IOException {
        Context context = this.contextWeakRef.get();
        if (context != null) {
            return context.getAssets().open(this.assetFilePath);
        }
        throw new IllegalArgumentException("Context should not be null. Use Application Context instead of Activity Context.");
    }

    public SharedGroup.Durability getDurability() {
        return this.durability;
    }

    public byte[] getEncryptionKey() {
        byte[] bArr = this.key;
        if (bArr == null) {
            return null;
        }
        return Arrays.copyOf(bArr, bArr.length);
    }

    public Realm.Transaction getInitialDataTransaction() {
        return this.initialDataTransaction;
    }

    public RealmMigration getMigration() {
        return this.migration;
    }

    public String getPath() {
        return this.canonicalPath;
    }

    public String getRealmFileName() {
        return this.realmFileName;
    }

    public File getRealmFolder() {
        return this.realmFolder;
    }

    public Set<Class<? extends RealmModel>> getRealmObjectClasses() {
        return this.schemaMediator.getModelClasses();
    }

    public RxObservableFactory getRxFactory() {
        RxObservableFactory rxObservableFactory = this.rxObservableFactory;
        if (rxObservableFactory != null) {
            return rxObservableFactory;
        }
        throw new UnsupportedOperationException("RxJava seems to be missing from the classpath. Remember to add it as a compile dependency. See https://realm.io/docs/java/latest/#rxjava for more details.");
    }

    public RealmProxyMediator getSchemaMediator() {
        return this.schemaMediator;
    }

    public long getSchemaVersion() {
        return this.schemaVersion;
    }

    public boolean hasAssetFile() {
        return !TextUtils.isEmpty(this.assetFilePath);
    }

    public int hashCode() {
        int hashCode = ((((this.realmFolder.hashCode() * 31) + this.realmFileName.hashCode()) * 31) + this.canonicalPath.hashCode()) * 31;
        byte[] bArr = this.key;
        int hashCode2 = (((hashCode + (bArr != null ? Arrays.hashCode(bArr) : 0)) * 31) + ((int) this.schemaVersion)) * 31;
        RealmMigration realmMigration = this.migration;
        int hashCode3 = (((((((hashCode2 + (realmMigration != null ? realmMigration.hashCode() : 0)) * 31) + (this.deleteRealmIfMigrationNeeded ? 1 : 0)) * 31) + this.schemaMediator.hashCode()) * 31) + this.durability.hashCode()) * 31;
        RxObservableFactory rxObservableFactory = this.rxObservableFactory;
        int hashCode4 = (hashCode3 + (rxObservableFactory != null ? rxObservableFactory.hashCode() : 0)) * 31;
        Realm.Transaction transaction = this.initialDataTransaction;
        return hashCode4 + (transaction != null ? transaction.hashCode() : 0);
    }

    public boolean shouldDeleteRealmIfMigrationNeeded() {
        return this.deleteRealmIfMigrationNeeded;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("realmFolder: ");
        sb.append(this.realmFolder.toString());
        sb.append("\n");
        sb.append("realmFileName : ");
        sb.append(this.realmFileName);
        sb.append("\n");
        sb.append("canonicalPath: ");
        sb.append(this.canonicalPath);
        sb.append("\n");
        sb.append("key: ");
        sb.append("[length: ");
        sb.append(this.key == null ? 0 : 64);
        sb.append("]");
        sb.append("\n");
        sb.append("schemaVersion: ");
        sb.append(Long.toString(this.schemaVersion));
        sb.append("\n");
        sb.append("migration: ");
        sb.append(this.migration);
        sb.append("\n");
        sb.append("deleteRealmIfMigrationNeeded: ");
        sb.append(this.deleteRealmIfMigrationNeeded);
        sb.append("\n");
        sb.append("durability: ");
        sb.append(this.durability);
        sb.append("\n");
        sb.append("schemaMediator: ");
        sb.append(this.schemaMediator);
        return sb.toString();
    }

    private RealmConfiguration(Builder builder) {
        this.realmFolder = builder.folder;
        this.realmFileName = builder.fileName;
        this.canonicalPath = Realm.getCanonicalPath(new File(this.realmFolder, this.realmFileName));
        this.assetFilePath = builder.assetFilePath;
        this.key = builder.key;
        this.schemaVersion = builder.schemaVersion;
        this.deleteRealmIfMigrationNeeded = builder.deleteRealmIfMigrationNeeded;
        this.migration = builder.migration;
        this.durability = builder.durability;
        this.schemaMediator = createSchemaMediator(builder);
        this.rxObservableFactory = builder.rxFactory;
        this.initialDataTransaction = builder.initialDataTransaction;
        this.contextWeakRef = builder.contextWeakRef;
    }

    public static final class Builder {
        private String assetFilePath;
        private WeakReference<Context> contextWeakRef;
        private boolean deleteRealmIfMigrationNeeded;
        private SharedGroup.Durability durability;
        private String fileName;
        private File folder;
        private Realm.Transaction initialDataTransaction;
        private byte[] key;
        private RealmMigration migration;
        private RxObservableFactory rxFactory;
        private long schemaVersion;
        private HashSet<Object> modules = new HashSet<>();
        private HashSet<Class<? extends RealmModel>> debugSchema = new HashSet<>();

        @Deprecated
        public Builder(File file) {
            RealmCore.loadLibrary();
            initializeBuilder(file);
        }

        private void addModule(Object obj) {
            if (obj != null) {
                checkModule(obj);
                this.modules.add(obj);
            }
        }

        private void checkModule(Object obj) {
            if (obj.getClass().isAnnotationPresent(RealmModule.class)) {
                return;
            }
            throw new IllegalArgumentException(obj.getClass().getCanonicalName() + " is not a RealmModule. Add @RealmModule to the class definition.");
        }

        private void initializeBuilder(File file) {
            if (file != null && file.isDirectory()) {
                if (file.canWrite()) {
                    this.folder = file;
                    this.fileName = "default.realm";
                    this.key = null;
                    this.schemaVersion = 0L;
                    this.migration = null;
                    this.deleteRealmIfMigrationNeeded = false;
                    this.durability = SharedGroup.Durability.FULL;
                    if (RealmConfiguration.DEFAULT_MODULE != null) {
                        this.modules.add(RealmConfiguration.DEFAULT_MODULE);
                        return;
                    }
                    return;
                }
                throw new IllegalArgumentException("Folder is not writable: " + file.getAbsolutePath());
            }
            StringBuilder sb = new StringBuilder();
            sb.append("An existing folder must be provided. Yours was ");
            sb.append(file != null ? file.getAbsolutePath() : "null");
            throw new IllegalArgumentException(sb.toString());
        }

        public Builder assetFile(Context context, String str) {
            if (context != null) {
                if (!TextUtils.isEmpty(str)) {
                    if (this.durability != SharedGroup.Durability.MEM_ONLY) {
                        if (!this.deleteRealmIfMigrationNeeded) {
                            this.contextWeakRef = new WeakReference<>(context);
                            this.assetFilePath = str;
                            return this;
                        }
                        throw new IllegalStateException("Realm cannot use an asset file when previously configured to clear its schema in migration by calling deleteRealmIfMigrationNeeded().");
                    }
                    throw new RealmException("Realm can not use in-memory configuration if asset file is present.");
                }
                throw new IllegalArgumentException("A non-empty asset file path must be provided");
            }
            throw new IllegalArgumentException("A non-null Context must be provided");
        }

        public RealmConfiguration build() {
            if (this.rxFactory == null && RealmConfiguration.access$1500()) {
                this.rxFactory = new RealmObservableFactory();
            }
            return new RealmConfiguration(this);
        }

        public Builder deleteRealmIfMigrationNeeded() {
            String str = this.assetFilePath;
            if (str != null && str.length() != 0) {
                throw new IllegalStateException("Realm cannot clear its schema when previously configured to use an asset file by calling assetFile().");
            }
            this.deleteRealmIfMigrationNeeded = true;
            return this;
        }

        public Builder encryptionKey(byte[] bArr) {
            if (bArr != null) {
                if (bArr.length == 64) {
                    this.key = Arrays.copyOf(bArr, bArr.length);
                    return this;
                }
                throw new IllegalArgumentException(String.format("The provided key must be %s bytes. Yours was: %s", 64, Integer.valueOf(bArr.length)));
            }
            throw new IllegalArgumentException("A non-null key must be provided");
        }

        public Builder inMemory() {
            if (TextUtils.isEmpty(this.assetFilePath)) {
                this.durability = SharedGroup.Durability.MEM_ONLY;
                return this;
            }
            throw new RealmException("Realm can not use in-memory configuration if asset file is present.");
        }

        public Builder initialData(Realm.Transaction transaction) {
            this.initialDataTransaction = transaction;
            return this;
        }

        public Builder migration(RealmMigration realmMigration) {
            if (realmMigration != null) {
                this.migration = realmMigration;
                return this;
            }
            throw new IllegalArgumentException("A non-null migration must be provided");
        }

        public Builder modules(Object obj, Object... objArr) {
            this.modules.clear();
            addModule(obj);
            if (objArr != null) {
                for (Object obj2 : objArr) {
                    addModule(obj2);
                }
            }
            return this;
        }

        public Builder name(String str) {
            if (str != null && !str.isEmpty()) {
                this.fileName = str;
                return this;
            }
            throw new IllegalArgumentException("A non-empty filename must be provided");
        }

        public Builder rxFactory(RxObservableFactory rxObservableFactory) {
            this.rxFactory = rxObservableFactory;
            return this;
        }

        Builder schema(Class<? extends RealmModel> cls, Class<? extends RealmModel>... clsArr) {
            if (cls != null) {
                this.modules.clear();
                this.modules.add(RealmConfiguration.DEFAULT_MODULE_MEDIATOR);
                this.debugSchema.add(cls);
                if (clsArr != null) {
                    Collections.addAll(this.debugSchema, clsArr);
                }
                return this;
            }
            throw new IllegalArgumentException("A non-null class must be provided");
        }

        public Builder schemaVersion(long j) {
            if (j >= 0) {
                this.schemaVersion = j;
                return this;
            }
            throw new IllegalArgumentException("Realm schema version numbers must be 0 (zero) or higher. Yours was: " + j);
        }

        public Builder(Context context) {
            if (context != null) {
                RealmCore.loadLibrary(context);
                initializeBuilder(context.getFilesDir());
                return;
            }
            throw new IllegalArgumentException("A non-null Context must be provided");
        }

        public Builder(Context context, File file) {
            if (context != null) {
                RealmCore.loadLibrary(context);
                initializeBuilder(file);
                return;
            }
            throw new IllegalArgumentException("A non-null Context must be provided");
        }
    }
}