DSSAT Run File Output method

@param arg0 file output path
@param results array of data holder object
774470
@Override
    public void writeFile(String arg0, ArrayList<HashMap> results) {
        writeFile(arg0, new HashMap());
    }
1122251
public void run(String[] args) {
        String DriverName = "";
	String DBUrl = "";
	String DBUser = "";
	String DBPassword = "";
	boolean initialize_dataset = false;

	for (int i = 0; i < args.length; i++) {
	    if (args[i].equals("-clients")) {
		if (i + 1 < args.length) {
		    i++;
		    n_clients = Integer.parseInt(args[i]);
		}
	    } else if (args[i].equals("-driver")) {
		if (i + 1 < args.length) {
		    i++;
		    DriverName = args[i];
		}
	    } else if (args[i].equals("-url")) {
		if (i + 1 < args.length) {
		    i++;
		    DBUrl = args[i];
		}
	    } else if (args[i].equals("-user")) {
		if (i + 1 < args.length) {
		    i++;
		    DBUser = args[i];
		}
	    } else if (args[i].equals("-password")) {
		if (i + 1 < args.length) {
		    i++;
		    DBPassword = args[i];
		}
	    } else if (args[i].equals("-tpc")) {
		if (i + 1 < args.length) {
		    i++;
		    n_txn_per_client = Integer.parseInt(args[i]);
		}
	    } else if (args[i].equals("-init")) {
		initialize_dataset = true;
	    } else if (args[i].equals("-tps")) {
		if (i + 1 < args.length) {
		    i++;
		    tps = Integer.parseInt(args[i]);
		}
	    } else if (args[i].equals("-v")) {
		verbose = true;
	    }
	}

	if (DriverName.length() == 0 || DBUrl.length() == 0) {
	    System.out.println("JDBC based benchmark program\n\n" +
			       "JRE usage:\n\njava jsqlite.BenchmarkDriver " +
			       "-url [url_to_db] \\\n    " +
			       "[-user [username]] " +
			       "[-password [password]] " +
			       "[-driver [driver_class_name]] \\\n    " +
			       "[-v] [-init] [-tpc N] [-tps N] " +
			       "[-clients N]\n");
	    System.out.println("OJEC usage:\n\ncvm jsqlite.BenchmarkDataSource " +
			       "[-user [username]] " +
			       "[-password [password]] " +
			       "[-driver [driver_class_name]] \\\n    " +
			       "[-v] [-init] [-tpc N] [-tps N] " +
			       "[-clients N]\n");
	    System.out.println();
	    System.out.println("-v          verbose mode");
	    System.out.println("-init       initialize the tables");
	    System.out.println("-tpc N      transactions per client");
	    System.out.println("-tps N      scale factor");
	    System.out.println("-clients N  number of simultaneous clients/threads");
	    System.out.println();
	    System.out.println("Default driver class is jsqlite.JDBCDriver");
	    System.out.println("in this case use an -url parameter of the form");
	    System.out.println("  jdbc:sqlite:/[path]");
	    System.exit(1);
	}

	System.out.println("Driver: " + DriverName);
	System.out.println("URL:" + DBUrl);
	System.out.println();
	System.out.println("Scale factor value: " + tps);
	System.out.println("Number of clients: " + n_clients);
	System.out.println("Number of transactions per client: " +
			   n_txn_per_client);
	System.out.println();

	try {
	    benchmark(DBUrl, DBUser, DBPassword, initialize_dataset);
	} catch (java.lang.Exception e) {
	    System.out.println(e.getMessage());
	    e.printStackTrace();
	}
    }
478577
private void listFiles(File dir, List<File> results) {
        File[] found = dir.listFiles();
        if ( found != null ) {
            for ( File f : found ) {
                if (f.isDirectory()) {
                	//do nothing
                } else {
                    results.add(f);
                }
            }
        }
    }
69472
@Override
    protected void putDumpInfoTo(Map<String, Object> result) {
        if(this.queryParametersMap.size() > 0) {
            result.put(DumpConstants.QUERY_PARAMETERS, queryParametersMap);
        }
    }
773262
public static void main(String[] args) {
        if (args.length != 2) {
            System.err.println("Please specify dir or filename | output file location");
            return;
        }

        StopwordsGenerator stopwordsGenerator = new StopwordsGenerator();

        File file = new File(args[0]);

        if (file.isFile()) {
            WikiSingleWordCount.generateFromFile(file, stopwordsGenerator);
        } else {
            File[] files = file.listFiles();
            Arrays.stream(files).parallel()
                    .filter(File::isFile)
                    .forEach(f -> WikiSingleWordCount.generateFromFile(f, stopwordsGenerator));
        }

        stopwordsGenerator.normalize();
        List<Map.Entry<String, Double>> result = stopwordsGenerator.getProbability()
                .entrySet().stream()
                .sorted((o1, o2) -> o2.getValue().compareTo(o1.getValue()))
                .collect(Collectors.toList());
        stopwordsGenerator.writeFile(args[1], result);
    }
870026
public void setResult(T result) {
        lock.lock();
        try {
            if(Objects.equals(expected_result, result))
                super.setResult(result);
        }
        finally {
            lock.unlock();
        }
    }
693109
private void reduceResults(final List<AnalysisResultFuture> results,
            final Map<ComponentJob, AnalyzerResult> resultMap,
            final List<AnalysisResultReductionException> reductionErrors) {

        if (_hasRun.get()) {
            // already reduced
            return;
        }
        
        _hasRun.set(true);

        for (AnalysisResultFuture result : results) {
            if (result.isErrornous()) {
                logger.error("Encountered errorneous slave result. Result reduction will stop. Result={}", result);
                final List<Throwable> errors = result.getErrors();
                if (!errors.isEmpty()) {
                    final Throwable firstError = errors.get(0);
                    logger.error(
                            "Encountered error before reducing results (showing stack trace of invoking the reducer): "
                                    + firstError.getMessage(), new Throwable());
                    _analysisListener.errorUknown(_masterJob, firstError);
                }

                // error occurred!
                return;
            }
        }

        final Collection<AnalyzerJob> analyzerJobs = _masterJob.getAnalyzerJobs();
        for (AnalyzerJob masterAnalyzerJob : analyzerJobs) {
            final Collection<AnalyzerResult> slaveResults = new ArrayList<AnalyzerResult>();
            logger.info("Reducing {} slave results for component: {}", results.size(), masterAnalyzerJob);
            for (AnalysisResultFuture result : results) {

                final Map<ComponentJob, AnalyzerResult> slaveResultMap = result.getResultMap();
                final List<AnalyzerJob> slaveAnalyzerJobs = CollectionUtils2.filterOnClass(slaveResultMap.keySet(),
                        AnalyzerJob.class);
                final AnalyzerJobHelper analyzerJobHelper = new AnalyzerJobHelper(slaveAnalyzerJobs);
                final AnalyzerJob slaveAnalyzerJob = analyzerJobHelper.getAnalyzerJob(masterAnalyzerJob);
                if (slaveAnalyzerJob == null) {
                    throw new IllegalStateException("Could not resolve slave component matching [" + masterAnalyzerJob
                            + "] in slave result: " + result);
                }

                final AnalyzerResult analyzerResult = result.getResult(slaveAnalyzerJob);
                slaveResults.add(analyzerResult);
            }

            reduce(masterAnalyzerJob, slaveResults, resultMap, reductionErrors);
        }
    }
19590
public void generateReport (String arg1, InvocationService.ResultListener arg2)
    {
        InvocationMarshaller.ResultMarshaller listener2 = new InvocationMarshaller.ResultMarshaller();
        listener2.listener = arg2;
        sendRequest(GENERATE_REPORT, new Object[] {
            arg1, listener2
        });
    }
35310
@Override
    public void writeFile(String arg0, Map result) {

        // Initial variables
//        ArrayList soilSites;                            // Soil site data array
        HashMap soilSite;                       // Data holder for one site of soil data
        ArrayList<Map> soilSistes;
        ArrayList<HashMap> soilRecords;                          // Soil layer data array
        BufferedWriter bwS;                             // output object
        StringBuilder sbTitle = new StringBuilder();
        StringBuilder sbSites = new StringBuilder();
        StringBuilder sbData;                           // construct the data info in the output
        StringBuilder sbLyrP2 = new StringBuilder();    // output string for second part of layer data
        boolean p2Flg;
        String[] p2Ids = {"slpx", "slpt", "slpo", "caco3", "slal", "slfe", "slmn", "slbs", "slpa", "slpb", "slke", "slmg", "slna", "slsu", "slec", "slca"};
        String layerKey = "soilLayer";  // P.S. the key name might change

        try {

            // Set default value for missing data
            setDefVal();

            soilSistes = getObjectOr(result, "soils", new ArrayList());
            if (soilSistes.isEmpty()) {
                soilSistes.add(result);
            }

            soilSite = (HashMap) getObjectOr(soilSistes.get(0), "soil", new HashMap());
            if (soilSite.isEmpty()) {
                return;
            }
//            decompressData(soilSites);

            // Initial BufferedWriter
            // Get File name
            String soilId = getObjectOr(soilSite, "soil_id", "");
            String fileName;
            if (soilId.equals("")) {
                fileName = "soil.SOL";
            } else {
                try {
                    fileName = soilId.substring(0, 2) + ".SOL";
                } catch (Exception e) {
                    fileName = "soil.SOL";
                }

            }
            arg0 = revisePath(arg0);
            outputFile = new File(arg0 + fileName);
//                boolean existFlg = outputFile.exists();
            bwS = new BufferedWriter(new FileWriter(outputFile));

            // Description info for output by translator
            sbTitle.append("!This soil file is created by DSSAT translator tool on ").append(Calendar.getInstance().getTime()).append(".\r\n");
            sbTitle.append("*SOILS: ");

            for (Map expData : soilSistes) {

                soilSite = (HashMap) getObjectOr(expData, "soil", new HashMap());
                sbError = new StringBuilder();
                sbData = new StringBuilder();

                // Output Soil File
                // Titel Section
                String sl_notes = getObjectOr((HashMap) soilSite, "sl_notes", defValBlank);
                if (!sl_notes.equals(defValBlank)) {
                    sbTitle.append(sl_notes).append("; ");
                }
                sbData.append("!The ACE ID is ").append(getValueOr(expData, "id", "N/A")).append(".\r\n");
                sbData.append("!This soil data is used for the experiment of ").append(getValueOr(expData, "exname", "N/A")).append(".\r\n!\r\n");

                // Site Info Section
                String soil_id = getSoilID(soilSite);
                if (soil_id.equals("")) {
                    sbError.append("! Warning: Incompleted record because missing data : [soil_id]\r\n");
                } else if (soil_id.length() > 10) {
                    sbError.append("! Warning: Oversized data : [soil_id] ").append(soil_id).append("\r\n");
                }
                sbData.append(String.format("*%1$-10s  %2$-11s %3$-5s %4$5s %5$s\r\n",
                        soil_id,
                        formatStr(11, soilSite, "sl_source", defValC),
                        formatStr(5, transSltx(getValueOr(soilSite, "sltx", defValC)), "sltx"),
                        formatNumStr(5, soilSite, "sldp", defValR),
                        getObjectOr(soilSite, "soil_name", defValC)));
                sbData.append("@SITE        COUNTRY          LAT     LONG SCS FAMILY\r\n");
                sbData.append(String.format(" %1$-11s %2$-11s %3$9s%4$8s %5$s\r\n",
                        formatStr(11, soilSite, "sl_loc_3", defValC),
                        formatStr(11, soilSite, "sl_loc_1", defValC),
                        formatNumStr(8, soilSite, "soil_lat", defValR), // P.S. Definition changed 9 -> 10 (06/24)
                        formatNumStr(8, soilSite, "soil_long", defValR), // P.S. Definition changed 9 -> 8  (06/24)
                        getObjectOr(soilSite, "classification", defValC)));
                sbData.append("@ SCOM  SALB  SLU1  SLDR  SLRO  SLNF  SLPF  SMHB  SMPX  SMKE\r\n");
//                if (getObjectOr(soilSite, "slnf", "").equals("")) {
//                    sbError.append("! Warning: missing data : [slnf], and will automatically use default value '1'\r\n");
//                }
//                if (getObjectOr(soilSite, "slpf", "").equals("")) {
//                    sbError.append("! Warning: missing data : [slpf], and will automatically use default value '0.92'\r\n");
//                }
                sbData.append(String.format(" %1$5s %2$5s %3$5s %4$5s %5$5s %6$5s %7$5s %8$5s %9$5s %10$5s\r\n",
                        getObjectOr(soilSite, "sscol", defValC),
                        formatNumStr(5, soilSite, "salb", defValR),
                        formatNumStr(5, soilSite, "slu1", defValR),
                        formatNumStr(5, soilSite, "sldr", defValR),
                        formatNumStr(5, soilSite, "slro", defValR),
                        formatNumStr(5, soilSite, "slnf", defValR), // P.S. Remove default value as '1'
                        formatNumStr(5, soilSite, "slpf", defValR), // P.S. Remove default value as '0.92'
                        getObjectOr(soilSite, "smhb", defValC),
                        getObjectOr(soilSite, "smpx", defValC),
                        getObjectOr(soilSite, "smke", defValC)));

                // Soil Layer data section
                soilRecords = (ArrayList) getObjectOr(soilSite, layerKey, new ArrayList());

                // part one
                sbData.append("@  SLB  SLMH  SLLL  SDUL  SSAT  SRGF  SSKS  SBDM  SLOC  SLCL  SLSI  SLCF  SLNI  SLHW  SLHB  SCEC  SADC\r\n");
                // part two
                sbLyrP2.append("@  SLB  SLPX  SLPT  SLPO CACO3  SLAL  SLFE  SLMN  SLBS  SLPA  SLPB  SLKE  SLMG  SLNA  SLSU  SLEC  SLCA\r\n");
                p2Flg = false;

                // Loop for laryer data
                for (HashMap soilRecord : soilRecords) {

                    // part one
                    sbData.append(String.format(" %1$5s %2$5s %3$5s %4$5s %5$5s %6$5s %7$5s %8$5s %9$5s %10$5s %11$5s %12$5s %13$5s %14$5s %15$5s %16$5s %17$5s\r\n",
                            formatNumStr(5, soilRecord, "sllb", defValR),
                            getObjectOr(soilRecord, "slmh", defValC),
                            formatNumStr(5, soilRecord, "slll", defValR),
                            formatNumStr(5, soilRecord, "sldul", defValR),
                            formatNumStr(5, soilRecord, "slsat", defValR),
                            formatNumStr(5, soilRecord, "slrgf", defValR),
                            formatNumStr(5, soilRecord, "sksat", defValR),
                            formatNumStr(5, soilRecord, "slbdm", defValR),
                            formatNumStr(5, soilRecord, "sloc", defValR),
                            formatNumStr(5, soilRecord, "slcly", defValR),
                            formatNumStr(5, soilRecord, "slsil", defValR),
                            formatNumStr(5, soilRecord, "slcf", defValR),
                            formatNumStr(5, soilRecord, "slni", defValR),
                            formatNumStr(5, soilRecord, "slphw", defValR),
                            formatNumStr(5, soilRecord, "slphb", defValR),
                            formatNumStr(5, soilRecord, "slcec", defValR),
                            formatNumStr(5, soilRecord, "sladc", defValR)));
                    // part two
                    sbLyrP2.append(String.format(" %1$5s %2$5s %3$5s %4$5s %5$5s %6$5s %7$5s %8$5s %9$5s %10$5s %11$5s %12$5s %13$5s %14$5s %15$5s %16$5s %17$5s\r\n",
                            formatNumStr(5, soilRecord, "sllb", defValR),
                            formatNumStr(5, soilRecord, "slpx", defValR),
                            formatNumStr(5, soilRecord, "slpt", defValR),
                            formatNumStr(5, soilRecord, "slpo", defValR),
                            formatNumStr(5, soilRecord, "caco3", defValR), // P.S. Different with document (DSSAT vol2.pdf)
                            formatNumStr(5, soilRecord, "slal", defValR),
                            formatNumStr(5, soilRecord, "slfe", defValR),
                            formatNumStr(5, soilRecord, "slmn", defValR),
                            formatNumStr(5, soilRecord, "slbs", defValR),
                            formatNumStr(5, soilRecord, "slpa", defValR),
                            formatNumStr(5, soilRecord, "slpb", defValR),
                            formatNumStr(5, soilRecord, "slke", defValR),
                            formatNumStr(5, soilRecord, "slmg", defValR),
                            formatNumStr(5, soilRecord, "slna", defValR),
                            formatNumStr(5, soilRecord, "slsu", defValR),
                            formatNumStr(5, soilRecord, "slec", defValR),
                            formatNumStr(5, soilRecord, "slca", defValR)));
                    // Check if there is 2nd part of layer data for output
                    if (!p2Flg) {
                        for (String p2Id : p2Ids) {
                            if (!getValueOr(soilRecord, p2Id, "").equals("")) {
                                p2Flg = true;
                                break;
                            }
                        }
                    }
                }

                // Add part two
                if (p2Flg) {
                    sbData.append(sbLyrP2.toString()).append("\r\n");
                    sbLyrP2 = new StringBuilder();
                } else {
                    sbData.append("\r\n");
                }

                // Finish one site
                sbSites.append(sbError.toString());
                sbSites.append(sbData.toString());
            }

            // Output finish
            sbTitle.append("\r\n\r\n");
            bwS.write(sbTitle.toString());
            bwS.write(sbSites.toString());
            bwS.close();

        } catch (IOException e) {
            LOG.error(DssatCommonOutput.getStackTrace(e));
        }
    }
372734
void run(List<String> arguments, @Nullable Path workingDirectory)
      throws ProcessHandlerException, CloudSdkNotFoundException, CloudSdkOutOfDateException,
          CloudSdkVersionFileException, IOException {

    sdk.validateCloudSdk();

    List<String> command = new ArrayList<>();
    command.add(sdk.getGCloudPath().toAbsolutePath().toString());

    command.addAll(arguments);
    if (outputFormat != null) {
      command.addAll(GcloudArgs.get("format", outputFormat));
    }

    if (credentialFile != null) {
      command.addAll(GcloudArgs.get("credential-file-override", credentialFile));
    }

    logger.info("submitting command: " + Joiner.on(" ").join(command));

    ProcessBuilder processBuilder = processBuilderFactory.newProcessBuilder();
    processBuilder.command(command);
    if (workingDirectory != null) {
      processBuilder.directory(workingDirectory.toFile());
    }
    processBuilder.environment().putAll(getGcloudCommandEnvironment());
    Process process = processBuilder.start();
    processHandler.handleProcess(process);
  }
155675
public void setEvaluationResults(java.util.Collection<EvaluationResult> evaluationResults) {
        if (evaluationResults == null) {
            this.evaluationResults = null;
            return;
        }

        this.evaluationResults = new java.util.ArrayList<EvaluationResult>(evaluationResults);
    }
1003514
@Override
    public void call(Result result, String prefix) {
        path(result, prefix, "java.class.path");
        path(result, prefix, "sun.boot.class.path");
        dirs(result, prefix, "java.ext.dirs");
    }
900343
public function setResults($results = null, bool $stopPropagation = false) {
        $this->result = $results;
        if ($stopPropagation) {
            $this->stopPropagation();
        }
    }
142527
public static List<List<Object>> buildResults(Result result,
			GeoPackageDataType[] dataTypes, Integer limit) {

		List<List<Object>> results = new ArrayList<>();
		try {
			int columns = result.getColumnCount();
			while (result.moveToNext()) {
				List<Object> row = new ArrayList<>();
				for (int i = 0; i < columns; i++) {
					row.add(result.getValue(i, dataTypes != null ? dataTypes[i]
							: null));
				}
				results.add(row);
				if (limit != null && results.size() >= limit) {
					break;
				}
			}
		} finally {
			result.close();
		}

		return results;
	}
212036
private void throwResult(final Result result) {
		this.executor.execute(new Runnable() {
			
			@Override
			public void run() {
				QConnectorAsyncImpl.this.listener.resultReceived("", result);
			}
		});
	}
1305524
public static void main(final String[] args) {
        final Set<String> paths = new HashSet<String>();
        final String propertyFile = System.getProperty("file");
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(propertyFile));
        } catch (IOException e) {
            e.printStackTrace();
        }

        for (String pr : properties.stringPropertyNames()) {
            System.out.println(pr + " : " + properties.getProperty(pr));
        }

        listAllFiles(paths, properties.getProperty(INPUT));

        runLenskitRecommenders(paths, properties);
        runMahoutRecommenders(paths, properties);
        runRanksysRecommenders(paths, properties);
    }
1253923
protected boolean setResult(Object result) {
        for (; ; ) {
            Object currentState = this.state;

            if (isDoneState(currentState)) {
                return false;
            }

            if (STATE.compareAndSet(this, currentState, result)) {
                done();
                notifyThreadsWaitingOnGet();
                runAsynchronous((ExecutionCallbackNode) currentState, result);
                break;
            }
        }
        return true;
    }