List of usage examples for java.io PrintStream print
public void print(Object obj)
From source file:com.hpe.application.automation.tools.srf.run.RunFromSrfBuilder.java
public static JSONObject getSrfConnectionData(AbstractBuild<?, ?> build, PrintStream logger) { try {/*w w w . j a v a 2 s . c o m*/ CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); // Create all-trusting host name verifier HostnameVerifier allHostsValid = new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; } }; HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); String path = build.getProject().getParent().getRootDir().toString(); path = path.concat("/com.hpe.application.automation.tools.settings.SrfServerSettingsBuilder.xml"); File file = new File(path); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(file); // This also shows how you can consult the global configuration of the builder JSONObject connectionData = new JSONObject(); String app = document.getElementsByTagName("srfAppName").item(0).getTextContent(); String tenant = app.substring(1, app.indexOf('_')); String secret = document.getElementsByTagName("srfSecretName").item(0).getTextContent(); String server = document.getElementsByTagName("srfServerName").item(0).getTextContent(); boolean https = true; if (!server.startsWith("https://")) { if (!server.startsWith("http://")) { String tmp = server; server = "https://"; server = server.concat(tmp); } else https = false; } URL urlTmp = new URL(server); if (urlTmp.getPort() == -1) { if (https) server = server.concat(":443"); else server = server.concat(":80"); } String srfProxy = ""; String srfTunnel = ""; try { srfProxy = document.getElementsByTagName("srfProxyName").item(0).getTextContent().trim(); srfTunnel = document.getElementsByTagName("srfTunnelPath").item(0).getTextContent(); } catch (Exception e) { throw e; } connectionData.put("app", app); connectionData.put("tunnel", srfTunnel); connectionData.put("secret", secret); connectionData.put("server", server); connectionData.put("https", (https) ? "True" : "False"); connectionData.put("proxy", srfProxy); connectionData.put("tenant", tenant); return connectionData; } catch (ParserConfigurationException e) { logger.print(e.getMessage()); logger.print("\n\r"); } catch (SAXException | IOException e) { logger.print(e.getMessage()); } return null; }
From source file:org.apache.hadoop.hive.ql.MultiDriver.java
private void printHeader(MultiDriver qp, PrintStream out) { List<FieldSchema> fieldSchemas = qp.getSchema().getFieldSchemas(); if (HiveConf.getBoolVar(conf, HiveConf.ConfVars.HIVE_CLI_PRINT_HEADER) && fieldSchemas != null) { // Print the column names boolean first_col = true; for (FieldSchema fs : fieldSchemas) { if (!first_col) { out.print('\t'); }/*from w ww. j av a2 s.co m*/ out.print(fs.getName()); first_col = false; } out.println(); } }
From source file:org.apache.geode.internal.cache.DiskInitFile.java
public void dumpRegionInfo(PrintStream printStream, String regName) { printStream.println("Regions in the disk store:"); for (Map.Entry<String, List<PlaceHolderDiskRegion>> regionEntry : getRegionsToDump(regName).entrySet()) { printStream.print(" "); List<PlaceHolderDiskRegion> regions = regionEntry.getValue(); if (logger.isTraceEnabled(LogMarker.PERSIST_RECOVERY)) { for (PlaceHolderDiskRegion region : regions) { region.dump(printStream); }/*ww w . ja va 2 s .c o m*/ } else { // NOTE, regions will always have at least 1 item. regions.get(0).dump(printStream); } } }
From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java
@Override protected InputStream handleExportViewComponent(Integer viewComponentId) throws Exception { File fle = File.createTempFile("view_component_export", ".xml.gz"); FileOutputStream fout = new FileOutputStream(fle); GZIPOutputStream gzoudt = new GZIPOutputStream(fout); PrintStream out = new PrintStream(gzoudt, true, "UTF-8"); out.print("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); out.print("<site>\n"); out.print("<hostUrl>" + Constants.URL_HOST + "</hostUrl>\n"); ViewComponentHbm viewComponent = getViewComponentHbmDao().load(viewComponentId); // TODO: depth 0 or 1 ??? getViewComponentHbmDao().toXml(viewComponent, null, true, true, true, true, 0, true, false, out); ContentHbm content = getContentHbmDao().load(Integer.parseInt(viewComponent.getReference())); ContentVersionHbm contentVersion = content.getLastContentVersion(); String contentVersionText = contentVersion.getText(); if (contentVersionText != null) { Document doc = XercesHelper.string2Dom(contentVersionText); getMediaXML(doc, out, "picture", "description"); getMediaXML(doc, out, "document", "src"); getAggregationXML(doc, out);/*from ww w .ja v a2 s . c o m*/ } out.print("</site>"); out.flush(); out.close(); out = null; return new FileInputStream(fle); }
From source file:de.juwimm.cms.remote.ViewServiceSpringImpl.java
@Override protected String handleGetViewComponentXmlComplete(Integer viewComponentId, String hostUrl, boolean withMedia) throws Exception { String retVal = ""; ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); PrintStream out = new PrintStream(byteOut, true, "UTF-8"); out.print("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); out.print("<site>\n"); out.print("<hostUrl>" + hostUrl + "</hostUrl>\n"); ViewComponentHbm viewComponent = getViewComponentHbmDao().load(viewComponentId); // TODO: depth 0 or 1 ??? getViewComponentHbmDao().toXml(viewComponent, null, true, true, true, true, 0, true, false, out); // getViewComponentHbmDao().toXmlComplete(viewComponentId, true, null, true, 1, true, false, out); if (withMedia) { ContentHbm content = getContentHbmDao().load(Integer.parseInt(viewComponent.getReference())); ContentVersionHbm contentVersion = content.getLastContentVersion(); String contentVersionText = contentVersion.getText(); if (contentVersionText != null) { Document doc = XercesHelper.string2Dom(contentVersionText); getMediaXML(doc, out, "picture", "description"); getMediaXML(doc, out, "document", "src"); }//ww w. j a v a 2 s .com } out.print("</site>"); retVal = byteOut.toString("UTF-8"); return retVal; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.sensitivity.SimpleStatistics.java
@Override public void run(CommandLine commandLine) throws Exception { String mode = null;//from w w w . j a v a 2 s .com PrintStream out = null; List<double[][]> entries = new ArrayList<double[][]>(); SummaryStatistics statistics = new SummaryStatistics(); OptionCompleter completer = new OptionCompleter("minimum", "maximum", "average", "stdev", "count"); //load data from all input files for (String filename : commandLine.getArgs()) { entries.add(load(new File(filename))); } //validate the inputs if (entries.isEmpty()) { throw new IllegalArgumentException("requires at least one file"); } int numberOfRows = -1; int numberOfColumns = -1; for (int i = 0; i < entries.size(); i++) { if (numberOfRows == -1) { numberOfRows = entries.get(i).length; if (numberOfRows == 0) { throw new IllegalArgumentException("empty file: " + commandLine.getArgs()[i]); } } else if (numberOfRows != entries.get(i).length) { throw new IllegalArgumentException("unbalanced rows: " + commandLine.getArgs()[i]); } if (numberOfColumns == -1) { numberOfColumns = entries.get(i)[0].length; } else if (numberOfColumns != entries.get(i)[0].length) { throw new IllegalArgumentException("unbalanced columns: " + commandLine.getArgs()[i]); } } //setup the mode if (commandLine.hasOption("mode")) { mode = completer.lookup(commandLine.getOptionValue("mode")); if (mode == null) { throw new IllegalArgumentException("invalid mode"); } } else { mode = "average"; } try { //instantiate the writer if (commandLine.hasOption("output")) { out = new PrintStream(commandLine.getOptionValue("output")); } else { out = System.out; } //compute the statistics for (int i = 0; i < numberOfRows; i++) { for (int j = 0; j < numberOfColumns; j++) { statistics.clear(); for (int k = 0; k < entries.size(); k++) { double value = entries.get(k)[i][j]; if (Double.isInfinite(value) && commandLine.hasOption("maximum")) { value = Double.parseDouble(commandLine.getOptionValue("maximum")); } if ((Double.isInfinite(value) || Double.isNaN(value)) && commandLine.hasOption("ignore")) { // ignore infinity or NaN values } else { statistics.addValue(value); } } if (j > 0) { out.print(' '); } if (mode.equals("minimum")) { out.print(statistics.getMin()); } else if (mode.equals("maximum")) { out.print(statistics.getMax()); } else if (mode.equals("average")) { out.print(statistics.getMean()); } else if (mode.equals("stdev")) { out.print(statistics.getStandardDeviation()); } else if (mode.equals("count")) { out.print(statistics.getN()); } else { throw new IllegalArgumentException("unknown mode: " + mode); } } out.println(); } } finally { if ((out != null) && (out != System.out)) { out.close(); } } }
From source file:com.buildml.main.CliUtils.java
/** * Helper method for displaying a path and all it's children, called exclusively by * printFileSet().//from ww w . ja v a2 s .c o m * * @param outStream The PrintStream on which to display paths. * @param pathSoFar This path's parent path as a string, complete with trailing "/". * @param buildStore The BuildStore in which these paths belong. * @param thisPathId The path to display (assuming it's in the filesToShow FileSet). * @param resultFileSet The set of files to be displayed (if null, show them all). * @param filterFileSet If not-null, used to filter which paths from resultFileSet * should be displayed (set to null to display everything). * @param showRoots Whether to show path roots. * @param showPkgs Whether to show the package names. */ private static void printFileSetHelper(PrintStream outStream, StringBuffer pathSoFar, IBuildStore buildStore, int thisPathId, FileSet resultFileSet, FileSet filterFileSet, boolean showRoots, boolean showPkgs) { IFileMgr fileMgr = buildStore.getFileMgr(); IPackageMgr pkgMgr = buildStore.getPackageMgr(); IPackageMemberMgr pkgMemberMgr = buildStore.getPackageMemberMgr(); IPackageRootMgr pkgRootMgr = buildStore.getPackageRootMgr(); /* StringBuilders for forming the package name and the root names */ StringBuilder pkgString = null; StringBuilder rootString = null; /* should this path be displayed? */ if (!shouldBeDisplayed(thisPathId, resultFileSet, filterFileSet)) { return; } /* fetch this path's name */ String baseName = fileMgr.getBaseName(thisPathId); /* get this path's list of children */ Integer children[] = fileMgr.getChildPaths(thisPathId); /* * Figure out whether this path has attached roots. */ String rootNames[] = null; if (showRoots) { rootNames = pkgRootMgr.getRootsAtPath(thisPathId); } /* * If we've been asked to display file packages, prepare the string to be printed. */ if (showPkgs) { pkgString = new StringBuilder(); /* fetch the file's package and scope */ PackageDesc pkgAndScopeId = pkgMemberMgr.getPackageOfMember(IPackageMemberMgr.TYPE_FILE, thisPathId); if (pkgAndScopeId == null) { pkgString.append("Invalid file"); } /* if valid, fetch the human-readable names */ else { String pkgName = pkgMgr.getName(pkgAndScopeId.pkgId); String scopeName = pkgMemberMgr.getScopeName(pkgAndScopeId.pkgScopeId); /* if we can't fetch the text name of the package or scope... */ if (pkgName == null || scopeName == null) { pkgString.append("Invalid package"); } /* else, both names are valid, append them to the string */ else { pkgString.append(pkgName); pkgString.append(" - "); pkgString.append(scopeName); } } } /* * Does this path have a root (and we were asked to show roots)? * If so, prepare the string to be printed. */ if ((rootNames != null) && (rootNames.length > 0)) { rootString = new StringBuilder(); /* display a root name, or comma-separated root names */ rootString.append(" ("); for (int i = 0; i < rootNames.length; i++) { if (i != 0) { rootString.append(' '); } rootString.append('@'); rootString.append(rootNames[i]); } rootString.append(')'); } /* show packages, if requested. Truncate to a fixed column width. */ if (pkgString != null) { if (pkgString.length() > PACKAGE_NAME_WIDTH - 1) { pkgString.setLength(PACKAGE_NAME_WIDTH - 1); } outStream.print(pkgString); PrintUtils.indent(outStream, PACKAGE_NAME_WIDTH - pkgString.length()); } /* Display this path, prefixed by the absolute pathSoFar */ outStream.print(pathSoFar); outStream.print(baseName); /* show roots, if requested */ if (rootString != null) { outStream.print(rootString); } outStream.println(); /* if there are children, call ourselves recursively to display them */ if (children.length != 0) { /* append this path onto the pathSoFar, since it'll become the pathSoFar for each child */ int pathSoFarLen = pathSoFar.length(); pathSoFar.append(baseName); if (baseName.charAt(0) != '/') { pathSoFar.append('/'); } /* display each of the children */ for (int i = 0; i < children.length; i++) { printFileSetHelper(outStream, pathSoFar, buildStore, children[i], resultFileSet, filterFileSet, showRoots, showPkgs); } /* remove our base name from the pathSoFar, so our caller sees the correct value again */ pathSoFar.setLength(pathSoFarLen); } }
From source file:gov.nasa.ensemble.dictionary.nddl.ParseInterpreter.java
/** * Function that writes out the initial state file specified by the given * output stream and based on a given Activity Dictionary that has already * been parsed//from w w w . ja v a2 s. c o m * * @param shortName * of oStrm */ public void writeInitialState(OutputStream oStrm, String modelFileName) { PrintStream out = new PrintStream(oStrm); // output common header lines out.printf("#include \"%s\"\n\n" + "PlannerConfig plannerConfiguration = new PlannerConfig(-10, +100000000, 10000, 10000);\n\n" + "ContainerObj Containers = new ContainerObj();\n" + "\tContainerObj.close();\n" + "InitialConds Incons = new InitialConds();\n" + "\tInitialConds.close();\n" + "Misc MiscClass = new Misc();\n" + "\tMisc.close();\n\n", modelFileName); if (CPUwindow != null) { out.printf("CPU_Windows Windows = new CPU_Windows();\n", modelFileName); out.print("\tCPU_Windows.close();\n"); } // instantiate subsystems objects for (String subsys : subsystemActivitiesMap.keySet()) { out.printf("%s Sys_%s = new %s();\n", subsys, subsys, subsys); out.printf("\t%s.close();\n", subsys); } out.println(); // initialize state resources (Enum and Threshold) // this needs to be coordinated with how Incon Activity is defined // for now, make everything is set to 0.0 // hence, they all must be set in the incon or there will be violations for (String state : stateNames) { List<String> stateValues = stateValuesMap.get(state); if (stateValues != null) { for (String val : stateValues) { String stateVal = NDDLUtil.escape(state + "_" + val); out.printf("%s SC_%s = new %s(0.0);\n", stateVal, stateVal, stateVal); out.printf("\t%s.close();\n", stateVal); } } // handle the negated state values Set<String> stateNotValues = stateNotValuesMap.get(state); if (stateNotValues != null) { for (String val : stateNotValues) { String stateVal = NDDLUtil.escape("not_" + state + "_" + val); out.printf("%s SC_%s = new %s(0.0);\n", stateVal, stateVal, stateVal); out.printf("\t%s.close();\n", stateVal); } } } out.println(); // initialize claimable resources // MODIFICATION: everything is now initialized to zero // so that the icon must specify the resource's value, not a delta for (String claim : claimNames) { String claimName = NDDLUtil.escape(claim); out.printf("%s UCR_%s = new %s(0.0);\n", claimName, claimName, claimName); out.printf("\t%s.close();\n", claimName); } out.println(); // MODIFICATION: everything is now initialized to zero // so that the icon must specify the resource's value, not a delta for (ESharableResourceDef share : allShares) { String shareName = NDDLUtil.escape(share.getName()); out.printf("%s MCR_%s = new %s(0.0, %f);\n", shareName, shareName, shareName, share.getCapacity().floatValue()); out.printf("\t%s.close();\n", shareName); } out.println(); // instantiate claim enforcement timelines for (String claim : claimNames) { String claimName = NDDLUtil.escape(claim); out.printf("Active_%s TL_%s = new Active_%s();\n", claimName, claimName, claimName); out.printf("\tActive_%s.close();\n", claimName); } out.println(); // instantiate Enum state mutex enforcement timelines // PHM 12/07/2011 Empty for Resource Solving for (String mutex : exclusiveActsStatesMap.keySet()) { String mutexString = NDDLUtil.escape(mutex); out.printf("Active_%s TL_%s = new Active_%s();\n", mutexString, mutexString, mutexString); out.printf("\tActive_%s.close();\n", mutexString); } // for (String mutex : exclusiveActsStatesMap2.keySet()) { // out.printf("Active_%s TL_%s = new Active_%s();\n", mutex, mutex, // mutex); // } // instantiate Threshold enforcement timelines for (EStateResourceDef state : allStates) { String stateTypeName = NDDLUtil.escape(state.getName()); if (stateTypesMap.containsKey(stateTypeName) && stateTypesMap.get(stateTypeName).equals("Threshold")) { for (String val : stateValuesMap.get(stateTypeName)) { String stateName = NDDLUtil.escape(state.getName() + "_" + val); out.printf("Active_%s TL_%s = new Active_%s();\n", stateName, stateName, stateName); out.printf("\tActive_%s.close();\n", stateName); } } } for (ADTranslator translator : adTranslators) translator.writeInitialState(out); // The entire DB is no longer closed; instead, each class is closed except Active_Enforcer // out.print("close();\n"); }
From source file:gov.nasa.ensemble.dictionary.nddl.ParseInterpreter.java
/** * Function that writes out the active compatibilities into the model file * specified by the given output stream and based on a given Activity * Dictionary that has already been parsed * //from w ww .j a v a2 s . com * @param shortName * of oStrm */ public void writeActiveResourceCompats(OutputStream oStrm) { PrintStream out = new PrintStream(oStrm); String actName; String startVar; String endVar; String qVar; String stateName; String state; String atStartValue; String atEndValue; @SuppressWarnings("unused") String objrefName; String shareName; List<String> allowedValues; // first handle the incon activity, then all others out.print("InitialConds::incon {\n" + " if (scheduled == true) {\n" + " if (Enable_Active_Enforcement == true) {\n" + " if (subSolved == true) {\n" + " if (enforced == true) {\n"); // PHM 04/17/2013 Prevent fixViolations from moving activity to before the INCON out.print(" \neq(inconStart, reftime);\n"); // PHM 05/10/2011 Declare the negated states as locals if they exist for (String stat : stateNames) { Set<String> stateNotValues = stateNotValuesMap.get(stat); if (stateNotValues != null && stateNotValues.size() > 0) { for (String val : stateNotValues) { out.printf(" float \t _not_%s_%s;\n", NDDLUtil.escape(stat), NDDLUtil.escape(val)); } } } // PHM 05/10/2011 Set the negated state values for (String stat : stateNames) { Set<String> stateNotValues = stateNotValuesMap.get(stat); if (stateNotValues != null && stateNotValues.size() > 0) { for (String val : stateNotValues) { out.printf(" sum(_not_%s_%s, _%s_%s, STATE_COND_TRUE);\n", NDDLUtil.escape(stat), NDDLUtil.escape(val), NDDLUtil.escape(stat), NDDLUtil.escape(val)); } } } for (String share : shareNames) { startVar = NDDLUtil.escape("i" + varN++); shareName = NDDLUtil.escape(share); out.printf("\n" + "\t starts(%s.produce %s);\n" + "\t eq(%s.quantity, _%s);\n", shareName, startVar, startVar, shareName); } // note that we use state-value pairs // for each state, one and only one value should be TRUE for (String resource : stateNames) { List<String> stateValues = stateValuesMap.get(resource); if (stateValues != null && stateValues.size() > 0) { for (String val : stateValues) { String resourceName = NDDLUtil.escape(resource + "_" + val); startVar = NDDLUtil.escape("i" + varN++); out.printf("\n" + "\t starts(%s.produce %s);\n" + "\t eq(%s.quantity, _%s);\n", resourceName, startVar, startVar, resourceName); } } // add in the negated values if they exist Set<String> stateNotValues = stateNotValuesMap.get(resource); if (stateNotValues != null && stateNotValues.size() > 0) { for (String val : stateNotValues) { String resourceName = NDDLUtil.escape("not_" + resource + "_" + val); startVar = NDDLUtil.escape("i" + varN++); out.printf("\n" + "\t starts(%s.produce %s);\n" + "\t eq(%s.quantity, _%s);\n", resourceName, startVar, startVar, resourceName); } } } out.print(" }\n }\n}\n}\n}\n\n"); // Due to the afterIncon check, have to handle the start transitions and end // transitions separately for (EActivityDef activityDef : activityDefs) { actName = NDDLUtil.escape(activityDef.getName()); if (!activityDef.getSharedEffects().isEmpty() || !activityDef.getStateRequirements().isEmpty() || !activityDef.getStateEffects().isEmpty()) { out.printf( "%s::%s {\n" + " if (scheduled == true) {\n" + " if (Enable_Active_Enforcement == true) {\n" + " if (subSolved == true) {\n" + " if (enforced == true) {\n\n", activitySubsystemMap.get(NDDLUtil.escape(activityDef.getName())), NDDLUtil.escape(activityDef.getName())); // handle shared reservations for (ESharableResourceEffect share : activityDef.getSharedEffects()) { shareName = NDDLUtil.escape(share.getName()); if (shareNames.contains(shareName)) { startVar = "r" + varN++; qVar = "q" + varN++; endVar = "r" + varN++; int reservations = share.getReservations(); if (reservations > 0) { out.printf( " if (Enforce_sx_%s == true) {\n" + " if (myEnforce.Enforce_sx_%s == true) {\n", shareName, shareName); out.printf("\n" + " condleq(afterIncon, inconStart, start);\n" + " float %s;\n" + " product(%s, %d, afterIncon);\n" + " starts(%s.consume %s);\n" + " eq(%s.quantity, %s);\n", qVar, qVar, reservations, shareName, startVar, startVar, qVar); out.printf("\n\t\tends(%s.produce %s);\n" + "\t\teq(%s.quantity, %d);\n", NDDLUtil.escape(shareName), NDDLUtil.escape(endVar), NDDLUtil.escape(endVar), reservations); out.printf("\n }\n }\n\n"); } } else { System.err.print("\n* Undefined share " + shareName + " in activity " + NDDLUtil.escape(activityDef.getName()) + " *\n\n"); } } // handle state requirements for (EStateRequirement stateReq : activityDef.getStateRequirements()) { // period = 0 means RequiresThroughout; period = 1 means // RequiresBeforeStart // we only handle RequiresThroughout state = NDDLUtil.escape(stateReq.getName()); if (stateNames.contains(state)) { if (stateReq.getPeriod() == Period.REQUIRES_THROUGHOUT) { // For requirements, Enum and Threshold states are no longer // handled identically due to negation and disjunction if (stateTypesMap.get(state).equals("Enum")) { // PHM 12/02/2011 Replace mutex guards per John Bresina suggestion // Keep _mx_ substring used to identify state flight rules. out.printf( " if (Enforce_mx_%s__%s == true) {\n" + " if (myEnforce.Enforce_mx_%s__%s == true) {\n", actName, state, actName, state); if (stateReq.getRequiredState() != null) { stateName = NDDLUtil.escape(state + "_" + stateReq.getRequiredState()); startVar = "r" + varN++; qVar = "q" + varN++; out.printf( "\n" + " condleq(afterIncon, inconStart, start);\n" + " float %s;\n" + " eq(%s, afterIncon);\n" + " starts(%s.consume %s);\n" + " eq(%s.quantity, %s);\n", qVar, qVar, stateName, startVar, startVar, qVar); endVar = NDDLUtil.escape("r" + varN++); out.printf("\n\t\tends(%s.produce %s);\n" + "\t\teq(%s.quantity, 1.0);\n", NDDLUtil.escape(stateName), endVar, endVar); } else if (stateReq.getDisallowedState() != null) { stateName = NDDLUtil .escape("not_" + state + "_" + stateReq.getDisallowedState()); startVar = "r" + varN++; qVar = "q" + varN++; out.printf( "\n" + " condleq(afterIncon, inconStart, start);\n" + " float %s;\n" + " eq(%s, afterIncon);\n" + " starts(%s.consume %s);\n" + " eq(%s.quantity, %s);\n", qVar, qVar, stateName, startVar, startVar, qVar); endVar = NDDLUtil.escape("r" + varN++); out.printf("\n\t\tends(%s.produce %s);\n" + "\t\teq(%s.quantity, 1.0);\n", NDDLUtil.escape(stateName), endVar, endVar); } else if (stateReq.getAllowedStates() != null && stateReq.getAllowedStates().size() > 0) { allowedValues = stateReq.getAllowedStates(); for (String val : stateValuesMap.get(state)) { if (!allowedValues.contains(val)) { stateName = NDDLUtil.escape("not_" + state + "_" + val); startVar = "r" + varN++; qVar = "q" + varN++; out.printf("\n" + " condleq(afterIncon, inconStart, start);\n" + " float %s;\n" + " eq(%s, afterIncon);\n" + " starts(%s.consume %s);\n" + " eq(%s.quantity, %s);\n", qVar, qVar, stateName, startVar, startVar, qVar); endVar = NDDLUtil.escape("r" + varN++); out.printf( "\n\t\tends(%s.produce %s);\n" + "\t\teq(%s.quantity, 1.0);\n", NDDLUtil.escape(stateName), endVar, endVar); } } } else { System.err.print( "*Required resource " + state + " did not have a value specified*\n\n"); } out.printf("\n }\n }\n\n"); } else if (stateTypesMap.get(state).equals("Threshold")) { // PHM 12/02/2011 Keep existing threshold guards out.printf(" if (Enforce_%s == true) {\n" + " if (myEnforce.Enforce_%s == true) {\n", state, state); stateName = NDDLUtil.escape(state + "_" + stateReq.getRequiredState()); startVar = "r" + varN++; qVar = "q" + varN++; out.printf( "\n" + " condleq(afterIncon, inconStart, start);\n" + " float %s;\n" + " eq(%s, afterIncon);\n" + " starts(%s.consume %s);\n" + " eq(%s.quantity, %s);\n", qVar, qVar, stateName, startVar, startVar, qVar); endVar = NDDLUtil.escape("r" + varN++); out.printf("\n\t\tends(%s.produce %s);\n" + "\t\teq(%s.quantity, 1.0);\n", NDDLUtil.escape(stateName), endVar, endVar); out.printf("\n }\n }\n\n"); } else { System.err.print("*Required resource " + state + " is not of type Enum nor ThresholdEnum*\n\n"); } } } else { System.err.print("\n* Undefined state " + state + " in activity " + NDDLUtil.escape(activityDef.getName()) + " *\n\n"); } } // handle start state effects for (EStateResourceEffect<?> effect : activityDef.getStateEffects()) { state = NDDLUtil.escape(effect.getName()); atStartValue = effect.getStartEffect(); // for effects, Enum and Threshold states are handled // differently String stateTypeName = stateTypesMap.get(state); if (stateTypeName != null && stateTypeName.equals("Enum")) { if (atStartValue != null) { // PHM 12/02/2011 Replace mutex guards per John Bresina suggestion // Keep _mx_ substring used to identify state flight rules. out.printf( " if (Enforce_mx_%s__%s == true) {\n" + " if (myEnforce.Enforce_mx_%s__%s == true) {\n", actName, state, actName, state); writeEnumStateEffectSection(out, state, atStartValue, "starts"); out.printf("\n }\n }\n\n"); } } else if (stateTypeName != null && stateTypeName.equals("Threshold")) { // PHM 12/02/2011 Keep existing threshold guards out.printf( " if (Enforce_%s == true) {\n" + " if (myEnforce.Enforce_%s == true) {\n", state, state); // we assume that there is an atStart value // and that atEnd we retract the effect // make all LOWER values False at start and True at // end for (String val : stateValuesMap.get(state)) { if (val.equals(atStartValue)) { break; } stateName = state + "_" + val; startVar = "s" + varN++; qVar = "q" + varN++; out.printf("\n" + " condleq(afterIncon, inconStart, start);\n" + " float %s;\n" + " product(%s, STATE_COND_FALSE, afterIncon);\n" + " starts(%s.consume %s);\n" + " eq(%s.quantity, %s);\n", qVar, qVar, stateName, startVar, startVar, qVar); out.println(); } out.printf("\n }\n }\n\n"); } } // handle end state effects for (EStateResourceEffect<?> effect : activityDef.getStateEffects()) { state = NDDLUtil.escape(effect.getName()); atEndValue = effect.getEndEffect(); // for effects, Enum and Threshold states are handled // differently String stateTypeName = stateTypesMap.get(state); if (stateTypeName != null && stateTypeName.equals("Enum")) { if (atEndValue != null) { // PHM 12/02/2011 Replace mutex guards per John Bresina suggestion // Keep _mx_ substring used to identify state flight rules. out.printf( " if (Enforce_mx_%s__%s == true) {\n" + " if (myEnforce.Enforce_mx_%s__%s == true) {\n", actName, state, actName, state); writeEnumStateEffectSection(out, state, atEndValue, "ends"); out.printf("\n }\n }\n\n"); } } else if (stateTypeName != null && stateTypeName.equals("Threshold")) { // PHM 12/02/2011 Keep existing threshold guards out.printf( " if (Enforce_%s == true) {\n" + " if (myEnforce.Enforce_%s == true) {\n", state, state); // we assume that there is an atStart value // and that atEnd we retract the effect // make all LOWER values False at start and True at // end for (String val : stateValuesMap.get(state)) { if (val.equals(atEndValue)) { break; } stateName = NDDLUtil.escape(state + "_" + val); endVar = NDDLUtil.escape("e" + varN++); out.printf("\t\tends(%s.produce %s);\n\t\teq(%s.quantity, STATE_COND_TRUE);\n", stateName, endVar, endVar); out.println(); } out.printf("\n }\n }\n\n"); } } out.print("\n }\n }\n}\n}\n}\n\n"); } } }