Android Open Source - coursera-android-pos Platform Strategy Factory






From Project

Back to project page coursera-android-pos.

License

The source code is released under:

MIT License

If you think the Android project coursera-android-pos listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.vuum.mocca;
//  w ww  .  j av a2 s . co  m
import java.util.HashMap;

/**
 * @class PlatformStrategyFactory
 * 
 * @brief This class is a factory that is responsible for building the
 *        designated @a PlatformStrategy implementation at runtime.
 */
public class PlatformStrategyFactory 
{
    /** 
     * This interface uses the Strategy pattern to create @a
     * PlatformStrategy implementations at runtime.
     */
    private static interface IPlatformStrategyFactoryStrategy 
    {
        public PlatformStrategy execute();
    }
  
    /**
     * Enumeration distinguishing platforms Android from plain ol' Java.
     */
    public enum PlatformType {
      ANDROID,
      PLAIN_JAVA
    }
    
    /**
     * HashMap used to map strings containing the Java platform names
     * and dispatch the execute() method of the associated @a PlatformStrategy
     * implementation.
     */
    private HashMap<PlatformType, IPlatformStrategyFactoryStrategy> mPlatformStrategyMap = 
        new HashMap<PlatformType, IPlatformStrategyFactoryStrategy>();
  
    /** 
     * Ctor that stores the objects that perform output for a
     * particular platform, such as ConsolePlatformStrategy or the
     * AndroidPlatformStrategy.
     */
    public PlatformStrategyFactory(final Object output,
                                   final Object activity) 
    {
      /** 
         * The "The Android Project" string maps to a command object
         * that creates an @a AndroidPlatformStrategy implementation.
         */
        mPlatformStrategyMap.put(PlatformType.ANDROID,
                                 new IPlatformStrategyFactoryStrategy() 
                                 {
                                     /** 
                                      * Receives the three parameters, input
                                      * (EditText), output (TextView), activity
                                      * (activity).
                                      */
                                     public PlatformStrategy execute() 
                                     {
                                         return new AndroidPlatformStrategy(output,
                                                                            activity);
                                     }
                                 });
  
      /** 
         * The "Sun Microsystems Inc." string maps to a command object
         * that creates an @a ConsolePlatformStrategy implementation.
         */
        mPlatformStrategyMap.put(PlatformType.PLAIN_JAVA,
                                 new IPlatformStrategyFactoryStrategy() 
                                 {
                                     public PlatformStrategy execute() 
                                     {
                                         return new ConsolePlatformStrategy(output);
                                     }
                                 });
    }

    /** 
     * Returns the name of the platform in a string. e.g., Android or
     * a JVM.
     */
    public static String platformName() 
    {
        return System.getProperty("java.specification.vendor");
    }
    
    /** 
     * Returns the type of the platformm e.g. Android or
     * a JVM.
     */
    public static PlatformType platformType() {
      if(platformName().indexOf("Android") >= 0) 
            return PlatformType.ANDROID;
      else
            return PlatformType.PLAIN_JAVA;
    }

    /** 
     * Create a new @a PlatformStrategy object based on underlying Java
     * platform.
     */
    public PlatformStrategy makePlatformStrategy() 
    {
        PlatformType type = platformType();

        return mPlatformStrategyMap.get(type).execute();
    }
}




Java Source Code List

.BuggyLongTest.java
.Main.java
.PingPongWrong.java
.SimpleAtomicLongTest.java
.SimpleAtomicLong.java
edu.vuum.mocca.AndroidPlatformStrategy.java
edu.vuum.mocca.AndroidPlatformStrategy.java
edu.vuum.mocca.AndroidPlatformStrategy.java
edu.vuum.mocca.BuggyLongTest.java
edu.vuum.mocca.BuggyLongTest.java
edu.vuum.mocca.ConsolePlatformStrategy.java
edu.vuum.mocca.ConsolePlatformStrategy.java
edu.vuum.mocca.ConsolePlatformStrategy.java
edu.vuum.mocca.DownloadActivity.java
edu.vuum.mocca.DownloadActivity.java
edu.vuum.mocca.DownloadBase.java
edu.vuum.mocca.DownloadIntentService.java
edu.vuum.mocca.DownloadService.java
edu.vuum.mocca.DownloadUtils.java
edu.vuum.mocca.Main.java
edu.vuum.mocca.Main.java
edu.vuum.mocca.Main.java
edu.vuum.mocca.Options.java
edu.vuum.mocca.Options.java
edu.vuum.mocca.Options.java
edu.vuum.mocca.PingPongActivity.java
edu.vuum.mocca.PingPongActivity.java
edu.vuum.mocca.PingPongRight.java
edu.vuum.mocca.PingPongRight.java
edu.vuum.mocca.PingPongRight.java
edu.vuum.mocca.PlatformStrategyFactory.java
edu.vuum.mocca.PlatformStrategyFactory.java
edu.vuum.mocca.PlatformStrategyFactory.java
edu.vuum.mocca.PlatformStrategy.java
edu.vuum.mocca.PlatformStrategy.java
edu.vuum.mocca.PlatformStrategy.java
edu.vuum.mocca.PlayPingPong.java
edu.vuum.mocca.PlayPingPong.java
edu.vuum.mocca.PlayPingPong.java
edu.vuum.mocca.SimpleAtomicLongMultithreadedTest.java
edu.vuum.mocca.SimpleAtomicLongMultithreadedTest.java
edu.vuum.mocca.SimpleAtomicLongMultithreadedTest.java
edu.vuum.mocca.SimpleAtomicLongSingleThreadedTest.java
edu.vuum.mocca.SimpleAtomicLongSingleThreadedTest.java
edu.vuum.mocca.SimpleAtomicLongSingleThreadedTest.java
edu.vuum.mocca.SimpleAtomicLongTests.java
edu.vuum.mocca.SimpleAtomicLongTests.java
edu.vuum.mocca.SimpleAtomicLongTests.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleAtomicLong.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.SimpleSemaphore.java
edu.vuum.mocca.ThreadPoolDownloadService.java
edu.vuum.mocca.ThreadedDownloads.java
edu.vuum.mocca.provider.MoocSchema.java
edu.vuum.mocca.storage.MoocResolver.java
edu.vuum.mocca.storage.StorageUtilities.java
edu.vuum.mocca.storage.StoryCreator.java
edu.vuum.mocca.storage.StoryData.java
edu.vuum.mocca.ui.CreateStoryActivity.java
edu.vuum.mocca.ui.EditStoryActivity.java
edu.vuum.mocca.ui.ListStoryActivity.java
edu.vuum.mocca.ui.LoginActivity.java
edu.vuum.mocca.ui.SoundRecordActivity.java
edu.vuum.mocca.ui.StoryActivityBase.java
edu.vuum.mocca.ui.StoryDataArrayAdaptor.java
edu.vuum.mocca.ui.ViewStoryActivity.java
edu.vuum.mooca.BuggyBlockingQueue.java
edu.vuum.mooca.BuggyBlockingQueue.java
edu.vuum.mooca.BuggyBlockingQueue.java
edu.vuum.mooca.SynchronizedQueueImpl.java
edu.vuum.mooca.SynchronizedQueueImpl.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueueTest.java
edu.vuum.mooca.SynchronizedQueue.java
edu.vuum.mooca.SynchronizedQueue.java
edu.vuum.mooca.SynchronizedQueue.java
edu.vuum.mooca.SynchronizedQueue.java
edu.vuum.mooca.SynchronizedQueue.java.java