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;
/*www.java2s.com*/import java.io.File;
import java.nio.*;
import java.util.*;
/**
* @class Options
*
* @brief This class implements the Singleton pattern to handle
* command-line option processing.
*/publicclass Options
{
/** The singleton @a Options instance. */privatestatic Options mUniqueInstance = null;
/** Maximum number of iterations to run the program (defaults to 10). */privateint mMaxIterations = 10;
/** Maximum number of iterations per "turn" (defaults to 1). */privateint mMaxTurns = 1;
/**
* Which synchronization to use, e.g., "SEMA" vs. "COND".
* Defaults to "SEMA".
*/private String mSyncMechanism = "SEMA";
/** Method to return the one and only singleton uniqueInstance. */publicstatic Options instance()
{
if (mUniqueInstance == null)
mUniqueInstance = new Options();
return mUniqueInstance;
}
/** Number of iterations to run the program. */publicint maxIterations()
{
return mMaxIterations;
}
/** Number of iterations to run the program. */publicint maxTurns()
{
return mMaxTurns;
}
/**
* Which synchronization to use, e.g., "SEMA" vs. "COND".
* Defaults to "SEMA".
*/public String syncMechanism()
{
return mSyncMechanism;
}
/**
* Parse command-line arguments and set the appropriate values.
*/publicboolean parseArgs(String argv[])
{
for (int argc = 0; argc < argv.length; argc += 2)
if (argv[argc].equals("-i"))
mMaxIterations = Integer.parseInt(argv[argc + 1]);
elseif (argv[argc].equals("-s"))
mSyncMechanism = argv[argc + 1];
elseif (argv[argc].equals("-t"))
mMaxTurns = Integer.parseInt(argv[argc + 1]);
else
{
printUsage();
return false;
}
return true;
}
/** Print out usage and default values. */publicvoid printUsage()
{
PlatformStrategy platform = PlatformStrategy.instance();
platform.errorLog("Options", "\nHelp Invoked on ");
platform.errorLog("Options", "[-hist] ");
platform.errorLog("", "");
platform.errorLog("", "");
platform.errorLog("Options", "Usage: ");
platform.errorLog("Options", "-h: invoke help ");
platform.errorLog("Options", "-i max-number-of-iterations ");
platform.errorLog("Options", "-s sync-mechanism (e.g., \"SEMA\" or \"COND\"");
platform.errorLog("Options", "-t max-number-of-turns");
}
/**
* Make the constructor private for a singleton.
*/private Options()
{
}
}