package com.joshuaavalon.wsdeckeditor;

import android.app.Application;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.joshuaavalon.wsdeckeditor.config.PreferenceRepository;
import com.joshuaavalon.wsdeckeditor.sdk.card.CardFacade;
import com.joshuaavalon.wsdeckeditor.sdk.card.ICardRepository;
import com.joshuaavalon.wsdeckeditor.sdk.deck.DeckFacade;
import com.joshuaavalon.wsdeckeditor.sdk.deck.IDeckRepository;

import timber.log.Timber;

public class WsApplication extends Application {
    @Nullable
    private ICardRepository cardRepository;
    @Nullable
    private IDeckRepository deckRepository;
    @Nullable
    private PreferenceRepository preference;

    @Override
    public void onCreate() {
        super.onCreate();
        if (BuildConfig.DEBUG)
            Timber.plant(new Timber.DebugTree());
    }

    @NonNull
    public ICardRepository getCardRepository() {
        if (cardRepository == null)
            cardRepository = CardFacade.Repository(this);
        return cardRepository;
    }

    @NonNull
    public IDeckRepository getDeckRepository() {
        if (deckRepository == null)
            deckRepository = DeckFacade.Repository(this, getCardRepository());
        return deckRepository;
    }

    @NonNull
    public PreferenceRepository getPreference() {
        if (preference == null)
            preference = PreferenceRepository.fromDefault(this);
        return preference;
    }
}

@@ -895,16 +895,29 @@
  public 
+synchronized 
 ICardRep
@@ -938,32 +938,32 @@
 dRepository() %7B%0A
-
         if (card
@@ -1102,16 +1102,29 @@
  public 
+synchronized 
 IDeckRep
@@ -1311,32 +1311,32 @@
 %7D%0A%0A    @NonNull%0A
-
     public Prefe
@@ -1330,16 +1330,29 @@
  public 
+synchronized 
 Preferen

Fix potential race conditions