com.github.siwenyan.potluck.GuestList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of potluck Show documentation
Show all versions of potluck Show documentation
Si Wenyan potluck framework
The newest version!
package com.github.siwenyan.potluck;
import com.github.siwenyan.common.*;
import com.github.siwenyan.dish_parser.IDish;
import com.github.siwenyan.dish_parser.Constants;
import com.github.siwenyan.dish_parser.SyntaxSimple;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class GuestList extends AbstractSimpleGuest {
private static final String KEYWORD_ADD_TO_LIST = "addToList";
private static final String KEYWORD_ADD_TO_LIST_FROM_FILE = "addToListFromFile";
private static final String KEYWORD_CLEAR_LIST = "clearList";
private static final String KEYWORD_COUNT_LIST = "countList";
private static final String KEYWORD_GET_LIST_ITEM = "getListItem";
private static final String KEYWORD_INDEX_OF = "indexOf";
private static final String KEYWORD_REMOVE_LIST_ITEM = "removeListItem";
private static final String DEFAULT_SPLITTER = ":";
private static final String ITEMS_KEY = "items";
private static final String ITEM_KEY = "item";
private static final String INTO_KEY = "into";
private static final String INDEX_KEY = "index";
private static final String SPLITTER_KEY = "splitter";
private static final String NO_DUPLICATE_KEY = "noDuplicate";
private static final String MAX_KEY = "max";
@Override
public String help(String flavor) {
String help = "";
if (flavor.equals(KEYWORD_ADD_TO_LIST)) {
help += Constants.OUTPUT_INDENT + KEYWORD_ADD_TO_LIST + Constants.OUTPUT_FLAVOR_SEPARATOR + "yourListName"
+ Constants.OUTPUT_PARAM_SEPARATOR + ITEMS_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR
+ "itemsWithSplitter" + Constants.OUTPUT_PARAM_SEPARATOR + SPLITTER_KEY
+ Constants.OUTPUT_PARAMNAME_SEPARATOR + "yourSplitter" + Constants.OUTPUT_PARAM_SEPARATOR
+ NO_DUPLICATE_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR + "[False]|True"
+ Constants.OUTPUT_PARAM_SEPARATOR + MAX_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR
+ "maxNumberOfItems" + Constants.OUTPUT_LINE_SEPARATOR + "\r\n";
help += Constants.OUTPUT_INDENT + KEYWORD_ADD_TO_LIST + Constants.OUTPUT_FLAVOR_SEPARATOR + "yourListName"
+ Constants.OUTPUT_PARAM_SEPARATOR + ITEMS_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR + "item1"
+ DEFAULT_SPLITTER + "item2" + DEFAULT_SPLITTER + "..." + Constants.OUTPUT_PARAM_SEPARATOR
+ MAX_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR + "maxNumberOfItems"
+ Constants.OUTPUT_LINE_SEPARATOR + "\r\n";
}
if (flavor.equals(KEYWORD_ADD_TO_LIST_FROM_FILE)) {
help += Constants.OUTPUT_INDENT + KEYWORD_ADD_TO_LIST_FROM_FILE + Constants.OUTPUT_FLAVOR_SEPARATOR
+ "yourListName" + Constants.OUTPUT_PARAM_SEPARATOR + ITEMS_KEY
+ Constants.OUTPUT_PARAMNAME_SEPARATOR + "yourFileName" + Constants.OUTPUT_PARAM_SEPARATOR
+ SPLITTER_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR + "yourSplitter"
+ Constants.OUTPUT_PARAM_SEPARATOR + NO_DUPLICATE_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR
+ "[False]|True" + Constants.OUTPUT_PARAM_SEPARATOR + MAX_KEY
+ Constants.OUTPUT_PARAMNAME_SEPARATOR + "maxNumberOfItems" + Constants.OUTPUT_LINE_SEPARATOR
+ "\r\n";
}
if (flavor.equals(KEYWORD_CLEAR_LIST)) {
help += Constants.OUTPUT_INDENT + KEYWORD_CLEAR_LIST + Constants.OUTPUT_FLAVOR_SEPARATOR + "yourListName"
+ Constants.OUTPUT_LINE_SEPARATOR + "\r\n";
}
if (flavor.equals(KEYWORD_COUNT_LIST)) {
help += Constants.OUTPUT_INDENT + KEYWORD_COUNT_LIST + Constants.OUTPUT_FLAVOR_SEPARATOR + "yourListName"
+ Constants.OUTPUT_PARAM_SEPARATOR + INTO_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR
+ "yourVariableName" + Constants.OUTPUT_LINE_SEPARATOR + "\r\n";
}
if (flavor.equals(KEYWORD_GET_LIST_ITEM)) {
help += Constants.OUTPUT_INDENT + KEYWORD_GET_LIST_ITEM + Constants.OUTPUT_FLAVOR_SEPARATOR
+ "yourListName" + Constants.OUTPUT_PARAM_SEPARATOR + INDEX_KEY
+ Constants.OUTPUT_PARAMNAME_SEPARATOR + "indexOfItem(start from 0)"
+ Constants.OUTPUT_PARAM_SEPARATOR + INTO_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR
+ "yourVariableName" + Constants.OUTPUT_LINE_SEPARATOR + "\r\n";
}
if (flavor.equals(KEYWORD_INDEX_OF)) {
help += Constants.OUTPUT_INDENT + KEYWORD_INDEX_OF + Constants.OUTPUT_FLAVOR_SEPARATOR + "yourListName"
+ Constants.OUTPUT_PARAM_SEPARATOR + ITEM_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR
+ "lookupItem" + Constants.OUTPUT_PARAM_SEPARATOR + INTO_KEY
+ Constants.OUTPUT_PARAMNAME_SEPARATOR + "yourVariableName (start from 0, -1 when not found)"
+ Constants.OUTPUT_LINE_SEPARATOR + "\r\n";
}
if (flavor.equals(KEYWORD_REMOVE_LIST_ITEM)) {
help += Constants.OUTPUT_INDENT + KEYWORD_REMOVE_LIST_ITEM + Constants.OUTPUT_FLAVOR_SEPARATOR
+ "yourListName" + Constants.OUTPUT_PARAM_SEPARATOR + INDEX_KEY
+ Constants.OUTPUT_PARAMNAME_SEPARATOR + "indexOfItem(start from 0)"
+ Constants.OUTPUT_PARAM_SEPARATOR + INTO_KEY + Constants.OUTPUT_PARAMNAME_SEPARATOR
+ "yourVariableName" + Constants.OUTPUT_LINE_SEPARATOR + "\r\n";
}
return help;
}
@Override
public Feedback have(IDish dish) {
try {
String flavor = dish.getFlavor().getFlavorName();
String listName = this.dynamic(dish.getStringElement(Constants.DEFAULT_KEY));
if (listName == null) {
return new Feedback(Feedback.EStatus.FAIL, "List name not specified.");
}
MyEnvironment myEnvironment = myTable.getMyEnvironment();
@SuppressWarnings("unchecked")
List