001/******************************************************************************* 002 * Copyright (c) 2017 Pablo Pavon Marino and others. 003 * All rights reserved. This program and the accompanying materials 004 * are made available under the terms of the 2-clause BSD License 005 * which accompanies this distribution, and is available at 006 * https://opensource.org/licenses/BSD-2-Clause 007 * 008 * Contributors: 009 * Pablo Pavon Marino and others - initial API and implementation 010 *******************************************************************************/ 011package com.net2plan.examples.ocnbook.offline; 012 013import com.net2plan.interfaces.networkDesign.IAlgorithm; 014import com.net2plan.interfaces.networkDesign.NetPlan; 015import com.net2plan.utils.InputParameter; 016import com.net2plan.utils.Triple; 017 018import java.util.List; 019import java.util.Map; 020 021/** 022 * @author Jorge San Emeterio 023 */ 024public class Offline_Example_Algorithm implements IAlgorithm 025{ 026 private InputParameter simpleParameter = new InputParameter("simpleParameter", "Default value", "The user may enter the desired value in a string format."); 027 private InputParameter booleanParameter = new InputParameter("booleanParameter", "#boolean# true", "Represents a true/false parameter through the use of a checkbox."); 028 private InputParameter selectParameter = new InputParameter("selectParameter", "#select# First Second Third", "Allows the user to choose from a given array of choices."); 029 private InputParameter pathParameter = new InputParameter("pathParameter", "#path# Sample text", "Brings up a file selector in order to choose a directory"); 030 private InputParameter fileChooserParameter = new InputParameter("fileChooserParameter", "#file# Sample text", "Brings up a file selector in order to choose a file"); 031 private InputParameter multipleFilesChooserParameter = new InputParameter("multipleFilesParameter", "#files# Sample text", "Brings up a file selector in order to choose multiple files." + 032 " The files' paths are separated with the string '>'."); 033 034 @Override 035 public String executeAlgorithm(NetPlan netPlan, Map<String, String> algorithmParameters, Map<String, String> net2planParameters) 036 { 037 InputParameter.initializeAllInputParameterFieldsOfObject(this, algorithmParameters); 038 039 System.out.printf("Simple parameter: " + simpleParameter.getString()); 040 System.out.println("Boolean parameter: " + Boolean.parseBoolean(booleanParameter.getString())); 041 System.out.println("Select parameter: " + selectParameter.getString()); 042 System.out.println("Path chooser parameter: " + pathParameter.getString()); 043 System.out.println("File chooser parameter: " + fileChooserParameter.getString()); 044 045 final String[] multipleFilesPath = multipleFilesChooserParameter.getString().split(">"); 046 for(String path : multipleFilesPath) System.out.println("Multiple file chooser parameter: " + path); 047 048 return "Ok"; 049 } 050 051 @Override 052 public String getDescription() 053 { 054 return "Example of different parameter types."; 055 } 056 057 @Override 058 public List<Triple<String, String, String>> getParameters() 059 { 060 return InputParameter.getInformationAllInputParameterFieldsOfObject(this); 061 } 062}