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 intTYPE_AUTOMATICstatic intTYPE_CRETURNstatic intTYPE_ERETURNstatic intTYPE_GLOBALstatic intTYPE_RETURNstatic intTYPE_RRETURNstatic intTYPE_SRETURNstatic intVTYPE_HIDDENstatic intVTYPE_HISTORICALstatic intVTYPE_VISIBLE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetGlobal(String name)Get the contents of a global macro.static StringgetGlobal(String name, int type)Get the contents of a global macro.static StringgetGlobalSafe(String name)Get the contents of a global macro without returning null.static StringgetGlobalSafe(String name, int type)Get the contents of a global macro without returning null.static StringgetLocal(String name)Get the contents of a local macro.static StringgetLocalSafe(String name)Get the contents of a local macro without returning null.static intsetGlobal(String name, String value)Set the value of a global macro.static intsetGlobal(String name, String value, int type)Set the value of a global macro.static intsetGlobal(String name, String value, int type, int vtype)Set the value of a global macro.static intsetGlobal(String name, String value, int type, String version)Set the value of a global macro.static intsetLocal(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_GLOBALandTYPE_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_GLOBALandTYPE_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.
-
-