@Override public JSAPResult parse(String[] args) { JSAPResult config; config = super.parse(args); try { /* parameter checking */ this.messagePrinted = super.messagePrinted(); boolean existsEnabledRatingAlgorithm = config.contains(OPTION_DYNAMIC_LINEAR_REGRESSION) || config.contains(OPTION_CONSTANT_LINEAR_REGRESSION) || config.getBoolean(OPTION_DIRECT_SCORES); /* ****************** ADD NEW RATING SYSTEMS HERE ****************** */ if (!existsEnabledRatingAlgorithm) { messagePrinted = true; if (!config.getBoolean(OPTION_HELP)) { System.err.println("Error: At least one rating algorithm must be enabled."); } } boolean existsEnabledOutputAlgorithm = config.getBoolean(OPTION_CSV_OUTPUT) || config.getBoolean(OPTION_GNUPLOT_OUTPUT) || config.getBoolean(OPTION_HTML_OUTPUT); /* ****************** ADD NEW OUTPUT METHODS HERE ****************** */ if (!existsEnabledOutputAlgorithm) { messagePrinted = true; if (!config.getBoolean(OPTION_HELP)) { System.err.println("Error: At least one output algorithm must be enabled."); } } if (messagePrinted) { // if user hasn't asked for help, "beat him with a clue stick", as the JSAP manual says if (!config.getBoolean(OPTION_HELP)) { System.err.println(); System.err.println("Type " + APPLICATION_CALL + " --" + OPTION_HELP + " for help."); } config.addException(null, new JSAPException("Help message printed.")); } } catch (UnspecifiedParameterException e) { if (!config.getBoolean(OPTION_HELP)) { System.err.println(); System.err.println("Type " + APPLICATION_CALL + " --" + OPTION_HELP + " for help."); } throw e; } return config; }
private static void applyParameters(JSAPResult args, Object o, Class<?> clazz) throws ReflectiveOperationException { for (Field field : clazz.getFields()) { if (Modifier.isPublic(field.getModifiers())) { String fieldName = field.getName().toLowerCase(); if (args.contains(fieldName)) { Object parameterValue = args.getObject(fieldName); ReflectionUtils.setFieldFromObject(o, field, parameterValue); LOGGER.info("Setting " + fieldName + " to '" + parameterValue + "'."); } else { LOGGER.warn("The field " + fieldName + " has not been set by command line arguments."); } } } }
public Object execute(List<String> argList) throws TclShellException { JSAPResult argv = parse(argList); if (argv == null) { return false; } if (argv.getBoolean(SmOptionPM.LIST_ATTR_OPTION)) { for (PWR_SRC_ATTR e : PWR_SRC_ATTR.values()) System.out.println( " => " + e.arg + " :\n " + e.help + (e.allowed == null ? "" : " = " + StringUtilities.join(", ", e.allowed) + ")")); return true; } String modelID = argv.getString(SmOption.MODEL_OPTION); ModelDB model = (modelID != null) ? ToolsDesign.getModel(modelID) : UnwCore.getDBProject().model(); if (model == null) { Logger.error(ErrorList.DB3.errorName(), ErrorList.DB3.getMessage(modelID)); throw new TclShellException(""); } PMConfig cfg = PMResourceManager.instance.getPmconfig(model, null); String pwrsrcName = argv.getString(SmOptionPM.PWRSRC_OPTION); PowerSourceInstance powerSource = PMFindVDomainTools.findPowerSource(cfg, pwrsrcName); if (powerSource == null) { Logger.error( ErrorListPM.PM22.errorName(), ErrorListPM.PM22.getMessage(pwrsrcName + "in model " + model.getModelName())); throw new TclShellException(""); } if (!argv.contains(SmOption.NAME_VALUE_OPTION)) { Logger.error("TCL", "no attribute specified"); throw new TclShellException(""); } String[] tokens = argv.getStringArray(SmOption.NAME_VALUE_OPTION); if (tokens.length % 2 != 0) { Logger.error(ErrorListPM.PM_TCL1.errorName(), ErrorListPM.PM_TCL1.getMessage()); throw new TclShellException(""); } String attrName; String attrValue; boolean error = false; for (int i = 0; i < tokens.length; i += 2) { attrName = tokens[i]; attrValue = tokens[i + 1]; PWR_SRC_ATTR id = PWR_SRC_ATTR.findAttr(attrName); if (id == null) { Logger.error(ErrorListPM.PM_TCL3.errorName(), ErrorListPM.PM_TCL3.getMessage(attrName)); throw new TclShellException(""); } else { CONNECT_DIRECTIVE direct = null; switch (id) { case CONNECT_IVOLT: try { direct = CONNECT_DIRECTIVE.valueOf(attrValue); powerSource.setConnectInputVoltage(direct); } catch (Exception e) { error = true; } break; case CONNECT_CTRL: try { direct = CONNECT_DIRECTIVE.valueOf(attrValue); powerSource.setConnectControl(direct); } catch (Exception e) { error = true; } break; case NAME: if (FormatValidation.isAlphaNumeric(attrValue, false)) { powerSource.setName(attrValue); } else error = true; default: break; } if (error) { Logger.error( ErrorListPM.PM_TCL2.errorName(), ErrorListPM.PM_TCL2.getMessage(attrValue + " for attribute " + attrName)); throw new TclShellException(""); } } } return true; }
public Object execute(List<String> argList) throws TclShellException { JSAPResult argv = parse(argList); if (argv == null) { return false; } InstanceDB inst; boolean hasError = false; String modelID = argv.getString(SmOption.MODEL_OPTION); ModelDB model = SmOption.getModel(modelID); if (model == null) throw new TclShellException(""); boolean createPort = argv.getBoolean(SmOption.CREATE_PORT_OPTION); /* * Set Parameters */ String[] instances = argv.getStringArray(SmOption.INSTANCE_OPTION); Collection<InstanceDB> instToConnect = new ArrayList<InstanceDB>(); if (instances == null || instances.length == 0) instToConnect = model.instances(); for (String instName : instances) { inst = model.instance(instName); if (inst == null) { Logger.error( ErrorList.DB15.errorName(), ErrorList.DB15.getMessage(instName + " in model " + model.getModelName())); hasError = true; continue; } instToConnect.add(inst); } DBJobParam param = new DBJobParam(); param.setSrcData( ConnectByNameDBJob.CONNECT_INSTANCES, instToConnect.toArray(new InstanceDB[instToConnect.size()])); param.setSrcData(ConnectByNameDBJob.CREATE_PORT, createPort); param.setSrcData(ConnectByNameDBJob.LEAKAGE_PORT, argv.getBoolean(SmOption.LEAKAGE_OPTION)); param.setSrcData( ConnectByNameDBJob.PROPAGATE_UP, SmOption.UP_OPTION.equals(argv.getString(SmOption.PROPAGATE_OPTION))); if (argv.contains(SmOption.DIRECTION_OPTION)) { String dir = argv.getString(SmOption.DIRECTION_OPTION); if ("in".equals(dir)) param.setSrcData(ConnectByNameDBJob.DIRECTION, PortInDB.class); else if ("out".equals(dir)) param.setSrcData(ConnectByNameDBJob.DIRECTION, PortOutDB.class); } if (argv.getBoolean(SmOption.HIER_OPTION)) param.setSrcData(ConnectByNameDBJob.HIER_OPTION, true); param.setSrcData(ConnectByNameDBJob.KEEPCONNECTION, !argv.getBoolean(SmOption.FORCE_OPTION)); DBJob job = new ConnectByNameDBJob(param); job.launch(); if (hasError || !job.isSuccessful()) throw new TclShellException("error with " + getCommandText()); return null; }
@SuppressWarnings("unchecked") private static void writeConditions( final String conditionsFilename, final JSAP jsap, final JSAPResult jsapResult, final Map<String, String> additionalConditionsMap, final Set<String> skipJsapConditions) throws IOException { PrintWriter modelConditionsWriter = null; try { modelConditionsWriter = new PrintWriter(new FileWriter(conditionsFilename, true)); boolean firstItem = true; // Write the additional conditions for (final String conditionKey : additionalConditionsMap.keySet()) { final String value = additionalConditionsMap.get(conditionKey); if (firstItem) { firstItem = false; } else { modelConditionsWriter.print("\t"); } modelConditionsWriter.printf("%s=%s", conditionKey, value); } // Write the JSAP configuration, as configured for ExecuteSplitsMode for (final String id : new IteratorIterable<String>(jsap.getIDMap().idIterator())) { if (skipJsapConditions.contains(id)) { // Skip some of the conditions continue; } final Parameter paramObj = jsap.getByID(id); if (paramObj instanceof Switch) { if (jsapResult.getBoolean(id)) { if (firstItem) { firstItem = false; } else { modelConditionsWriter.print("\t"); } modelConditionsWriter.printf("%s=enabled", id); } } else if (paramObj instanceof FlaggedOption) { // A flag switch exists. Pass it along. final FlaggedOption flagOpt = (FlaggedOption) paramObj; if (jsapResult.contains(id)) { if (firstItem) { firstItem = false; } else { modelConditionsWriter.print("\t"); } final String stringVal = SequenceMode.jsapOptionToConcatenatedString(jsapResult, flagOpt, ','); modelConditionsWriter.printf("%s=%s", id, stringVal); } } } modelConditionsWriter.println(); } finally { IOUtils.closeQuietly(modelConditionsWriter); modelConditionsWriter = null; } }
public static void main(String[] args) throws JSAPException, IOException, RatingException { CommandLineInterface commandLineInterface = new CommandLineInterface(); JSAPResult jsap = commandLineInterface.parse(args); if (!jsap.success()) { throw new JSAPException("Command line parsing failed."); } ////////////////////////////////////////////////////// // now configure everything // ////////////////////////////////////////////////////// Configuration configuration = new Configuration(); /* configure debug level */ String debugLevel = jsap.getString(OPTION_DEBUG_LEVEL).toUpperCase(); Level level = Level.parse(debugLevel); configuration.setDebugLevel(level); /* configure input dir */ MatchSetReader matchSetReader = new FileMatchSetReader(jsap.getFile(OPTION_INPUT_DIR), configuration); configuration.setMatchReader(matchSetReader); /* configure output dir */ Configuration.setOutputDir(jsap.getFile(OPTION_OUTPUT_DIR)); /* configure previous ratings file */ configuration.setPreviousRatings(jsap.getFile(OPTION_PREVIOUS_RATINGS)); /* configure rating algorithms */ if (jsap.contains(OPTION_DYNAMIC_LINEAR_REGRESSION)) { int maxMatchSets = jsap.getInt(OPTION_DYNAMIC_LINEAR_REGRESSION); configuration.addRatingSystem(new DynamicLinearRegressionStrategy(maxMatchSets)); } if (jsap.contains(OPTION_CONSTANT_LINEAR_REGRESSION)) { double learningRate = jsap.getDouble(OPTION_CONSTANT_LINEAR_REGRESSION); configuration.addRatingSystem(new ConstantLinearRegressionStrategy(learningRate)); } if (jsap.getBoolean(OPTION_DIRECT_SCORES)) { configuration.addRatingSystem(new DirectScoresStrategy()); } /* ****************** ADD NEW RATING SYSTEMS HERE ****************** */ /* make ignore list */ Set<Player> ignorePlayers = new IgnorePlayerSet(jsap.getFile(OPTION_INPUT_DIR), configuration.getPlayerSet()); /* configure output methods */ for (RatingSystemType type : configuration.getEnabledRatingSystems()) { if (jsap.getBoolean(OPTION_CSV_OUTPUT)) { configuration.addCSVOutputBuilder(type, ignorePlayers); } if (jsap.getBoolean(OPTION_GNUPLOT_OUTPUT)) { configuration.addGnuplotOutputBuilder(type, ignorePlayers); } if (jsap.getBoolean(OPTION_HTML_OUTPUT)) { configuration.addHtmlOutputBuilder(type, ignorePlayers); } /* ****************** ADD NEW OUTPUT METHODS HERE ****************** */ } configuration.run(); }