Package com.stata.sfi
Class Macro
- java.lang.Object
-
- com.stata.sfi.Macro
-
public final class Macro extends Object
This class provides access to Stata macros.Example:
Local macros are a convenient tool for passing command options to Java.
public static int getOptions(String[] args) { // options filename and level are passed through local macros String fileName = Macro.getLocal("filename"); if (fileName == null) { return (198); } int level = 95; try { level = Integer.parseInt(Macro.getLocalSafe("level")); } catch (NumberFormatException e) {} SFIToolkit.displayln("filename: " + fileName); SFIToolkit.displayln("level: " + level); return 0; }
-
-
Field Summary
Fields Modifier and Type Field Description static int
TYPE_AUTOMATIC
static int
TYPE_CRETURN
static int
TYPE_ERETURN
static int
TYPE_GLOBAL
static int
TYPE_RETURN
static int
TYPE_RRETURN
static int
TYPE_SRETURN
static int
VTYPE_HIDDEN
static int
VTYPE_HISTORICAL
static int
VTYPE_VISIBLE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getGlobal(String name)
Get the contents of a global macro.static String
getGlobal(String name, int type)
Get the contents of a global macro.static String
getGlobalSafe(String name)
Get the contents of a global macro without returning null.static String
getGlobalSafe(String name, int type)
Get the contents of a global macro without returning null.static String
getLocal(String name)
Get the contents of a local macro.static String
getLocalSafe(String name)
Get the contents of a local macro without returning null.static int
setGlobal(String name, String value)
Set the value of a global macro.static int
setGlobal(String name, String value, int type)
Set the value of a global macro.static int
setGlobal(String name, String value, int type, int vtype)
Set the value of a global macro.static int
setGlobal(String name, String value, int type, String version)
Set the value of a global macro.static int
setLocal(String name, String value)
Set the value of a local macro.
-
-
-
Field Detail
-
TYPE_AUTOMATIC
public static final int TYPE_AUTOMATIC
- See Also:
- Constant Field Values
-
TYPE_CRETURN
public static final int TYPE_CRETURN
- See Also:
- Constant Field Values
-
TYPE_ERETURN
public static final int TYPE_ERETURN
- See Also:
- Constant Field Values
-
TYPE_GLOBAL
public static final int TYPE_GLOBAL
- See Also:
- Constant Field Values
-
TYPE_RETURN
public static final int TYPE_RETURN
- See Also:
- Constant Field Values
-
TYPE_RRETURN
public static final int TYPE_RRETURN
- See Also:
- Constant Field Values
-
TYPE_SRETURN
public static final int TYPE_SRETURN
- See Also:
- Constant Field Values
-
VTYPE_HIDDEN
public static final int VTYPE_HIDDEN
- See Also:
- Constant Field Values
-
VTYPE_HISTORICAL
public static final int VTYPE_HISTORICAL
- See Also:
- Constant Field Values
-
VTYPE_VISIBLE
public static final int VTYPE_VISIBLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getGlobal
@Synchronized public static String getGlobal(String name)
Get the contents of a global macro.- Parameters:
name
- Name of the macro.- Returns:
- Value of the macro. Returns null if the macro is not found.
-
getGlobal
@Synchronized public static String getGlobal(String name, int type)
Get the contents of a global macro.- Parameters:
name
- Name of the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
,TYPE_CRETURN
, orTYPE_SRETURN
.- Returns:
- Value of the macro. Returns null if the macro is not found.
-
getGlobalSafe
@Synchronized public static String getGlobalSafe(String name)
Get the contents of a global macro without returning null.- Parameters:
name
- Name of the macro.- Returns:
- Value of the macro. Returns an empty string if the macro is not found.
-
getGlobalSafe
@Synchronized public static String getGlobalSafe(String name, int type)
Get the contents of a global macro without returning null.- Parameters:
name
- Name of the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
,TYPE_CRETURN
, orTYPE_SRETURN
.- Returns:
- Value of the macro. Returns an empty string if the macro is not found.
-
getLocal
@Synchronized public static String getLocal(String name)
Get the contents of a local macro.- Parameters:
name
- Name of the macro.- Returns:
- Value of the macro. Returns null if the macro is not found.
-
getLocalSafe
@Synchronized public static String getLocalSafe(String name)
Get the contents of a local macro without returning null.- Parameters:
name
- Name of the macro.- Returns:
- Value of the macro. Returns an empty string if the macro is not found.
-
setGlobal
@Synchronized public static int setGlobal(String name, String value)
Set the value of a global macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.- Returns:
- Return code from Stata; 0 if successful.
-
setGlobal
@Synchronized public static int setGlobal(String name, String value, int type)
Set the value of a global macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
, orTYPE_SRETURN
.- Returns:
- Return code from Stata; 0 if successful.
-
setGlobal
@Synchronized public static int setGlobal(String name, String value, int type, int vtype)
Set the value of a global macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
, orTYPE_SRETURN
.vtype
- If the macro is a type of return value, sets whether the return value isVTYPE_VISIBLE
,VTYPE_HIDDEN
, orVTYPE_HISTORICAL
. This parameter is ignored withTYPE_GLOBAL
andTYPE_SRETURN
.- Returns:
- Return code from Stata; 0 if successful.
-
setGlobal
@Synchronized public static int setGlobal(String name, String value, int type, String version)
Set the value of a global macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.type
- Type of the macro; may beTYPE_AUTOMATIC
,TYPE_GLOBAL
,TYPE_RETURN
,TYPE_RRETURN
,TYPE_ERETURN
, orTYPE_SRETURN
.version
- If the macro is a type of return value, sets the release number in the form #[#][.[#[#]]] for a return result. This parameter is ignored withTYPE_GLOBAL
andTYPE_SRETURN
.- Returns:
- Return code from Stata; 0 if successful.
-
setLocal
@Synchronized public static int setLocal(String name, String value)
Set the value of a local macro. If necessary, the macro will be created.- Parameters:
name
- Name of the macro.value
- Value to store in the macro.- Returns:
- Return code from Stata; 0 if successful.
-
-