package jcircus.complexcomms; import java.math.BigInteger; import java.util.Vector; import javax.swing.JOptionPane; import jcircus.complementaryenvs.TypeSizeEnv; import jcircus.environment.Environment; import jcircus.newfrontendmethod.FrontEndAnn; import org.jcsp.lang.Alternative; import org.jcsp.lang.Guard; import net.sourceforge.czt.util.Visitor; import net.sourceforge.czt.z.ast.Expr; import net.sourceforge.czt.z.ast.NumExpr; import net.sourceforge.czt.z.ast.ProdExpr; import net.sourceforge.czt.z.ast.RefExpr; import net.sourceforge.czt.z.ast.SetExpr; import net.sourceforge.czt.z.ast.ZExprList; import net.sourceforge.czt.z.ast.ZNameList; import net.sourceforge.czt.circus.ast.ChannelDecl; import net.sourceforge.czt.circus.ast.Communication; import net.sourceforge.czt.circus.ast.CircusFieldList; import net.sourceforge.czt.circus.ast.DotField; import net.sourceforge.czt.circus.ast.Field; import net.sourceforge.czt.circus.ast.InputField; public class CCUtil { //int [] values = new int [10 /*cfl.size()*/]; //Object [] commValues = new Object [10 /*cfl.size()*/]; //boolean [] inputDecoration /*cfl.getCircusFieldList()*/ = new boolean [10 /*cfl.size()*/]; //String str = ""; public static int [] makeArrayOf (int x, Communication c) { CircusFieldList cfl = c.getCircusFieldList(); int [] xis = new int [cfl.size()]; for (int i = 0; i < cfl.size(); i++) { xis [i] = x; } return xis; } public static boolean [] initInputDecoration (int size) { //Inits the decoration sequence of the communication. For example, if it is chan.5?x?y, then the inputDecoration will be inited as {false, false, false} boolean [] in = new boolean [size]; for (int i = 0; i < size; i++) { in [i] = false; } return in; } public static Object [] initCommValues (int size) { //Inits the values communicated. //when inputDecoration [i] = false, the content of commValues [i] doesn't matter. Object [] c = new Object [size]; for (int i = 0; i < size; i++) { c [i] = null; } return c; } private int [] max (int [] values) { int [] max = new int [values.length]; for (int i = 0; i < max.length; i++) { max [i] = 9; } return max; } private static boolean equalsToMax (int [] values) { boolean aux = true; for (int i = 0; i < values.length; i++) { if (values [i] != 9) { aux = false; } } return aux; } public static boolean reachedMax (int [] values, Vector > valuesSet/*int max*/) { //Auxiliar function int size = valuesSet.size()/*values.length*/; boolean aux = true; for (int i = 0; i < size; i++) { int size2 = valuesSet.elementAt(i).size(); int index = valuesSet.elementAt(i).indexOf(new BigInteger ("" + values [i] + "")); if (valuesSet.elementAt(i).indexOf(new BigInteger ("" + values [i] + "")) < size2 - 1/*max*/) aux = false; } return aux; } public static int [] minFromNowOn (int from, int [] values, boolean [] inputDecoration, int [] min) { int size = values.length; for (int i = from; i < size; i++) { if (inputDecoration [i]) values [i] = min [i]; } return values; } public static int nextOne (int i, int [] values, Vector > valuesSet) { //Este m�todo sup�e que o conjunto de valores j� est� em ordem crescente, e sem repeti��o de valores int size = valuesSet.elementAt(i).size(); boolean contains = valuesSet.elementAt(i).contains(new BigInteger ("" + values [i] + "")); BigInteger currentValue = new BigInteger ("" + values [i] + ""); int next = valuesSet.elementAt(i).indexOf(currentValue) + 1; int returnedValue = valuesSet.elementAt(i).elementAt(next).intValue(); return valuesSet.elementAt(i).elementAt(next).intValue(); } public static Vector > createTheASet (int order, int [] min, int [] max) { Vector > set = new Vector > (); Vector subSet = new Vector (); for (int i = 0; i < order; i++) { for (int j = min [i]; j <= max [i]; j++) { subSet.addElement (new BigInteger ("" + j + "")); } set.addElement(subSet); subSet = new Vector (); } return set; } public static String setExprCode (Vector v/*SetExpr setExpr*/) { //TODO testar String str = ""; str = str + " subSet = new Vector ();\n"; int setSize = v.size(); for (int k = 0; k < setSize; k++) { BigInteger expr = v.elementAt(k); str = str + " subSet.addElement (new BigInteger (\"" + expr + "\"));\n"; } return str; } public static String theATypeCode () { //TODO testar String str = " subSet = new Vector ();\n"; for (int i = -9; i <= 9; i++) { //TODO Limites que impomos ao tipo inteiro, de 0 at� 9. Mas nem sempre dever� ser assim. str = str + " subSet.addElement (new BigInteger (\"" + i + "\"));\n"; } return str; } public static String chanExprCode (Vector > vv) { String str = " set = new Vector > ();\n"; if (vv == null) { System.out.print(""); } int prodSize = (vv == null || vv.isEmpty())? 0 : vv.size(); for (int i = 0; i < prodSize; i++) { Vector expr = vv.elementAt(i); str = str + setExprCode (expr); str = str + " set.addElement (subSet);\n"; } return str; } /* public static String chanExprCode (Vector v //SetExpr setExpr * ) { //TODO testar String str = " Vector > set = new Vector ();\n"; Vector expr = v; str = str + setExprCode ((SetExpr)expr); str = str + " set.addElement (subSet);\n"; return str; } public static String chanExprCode () { //TODO testar String str = " Vector > set = new Vector ();\n"; str = str + aTypeCode (); str = str + " set.addElement (subSet);\n"; return str; } */ /* public static String makeEnvChannelsCode (String channelName, ChannelDecl channelDecl) { //TODO esse aqui testa v�rios TODO String str = " HashMap >> env_channels = new HashMap >> ();\n" + " Vector subSet;\n" + " Vector > set;\n" + " public void makeEnvChannels () {\n"; ZNameList names = channelDecl.getZChannelNameList(); Expr expr = channelDecl.getExpr(); if (expr instanceof RefExpr) { str = str + chanExprCode ((RefExpr)expr); } else if (expr instanceof SetExpr) { str = str + chanExprCode ((SetExpr)expr); } else //if (expr instanceof ProdExpr) { str = str + chanExprCode ((ProdExpr)expr); } String [] chanNames = new String [names.size()]; for (int i = 0; i < chanNames.length; i++) { chanNames [i] = names.get(i).toString(); str = str + " env_channels.put (\"" + chanNames [i] + "\", " + "set" + ");\n"; } return str + " }\n"; } */ public static String makeEnvChannelsCode (String [] channelNames, Channel2TypeEnvironment env) { String str = " public HashMap >> env_channels = new HashMap >> ();\n" + " Vector subSet;\n" + " Vector > set;\n"; for (int i = 0; i < channelNames.length; i++) { str = str + " public void makeEnvChannels" + i + " () {\n" + chanExprCode (env.get(channelNames [i])) + " env_channels.put (\"" + channelNames [i] + "\", " + "set" + ");\n" + " }\n"; } return str; } public static String makeEnvChannelsCode (String channelName1, Vector > vv/*ChanTypeEnv4CC env*/) { String str = " public HashMap >> env_channels = new HashMap >> ();\n" + " Vector subSet;\n" + " Vector > set;\n" + " public void makeEnvChannels () {\n"; str = str + chanExprCode (vv); str = str + " env_channels.put (\"" + channelName1 + "\", " + "set" + ");\n" + " /*}*/\n"; return str + " }\n";//}\n"; } public static Vector > toVVBigInteger (Expr ccExpr, int minComm, int maxComm, Environment env, TypeSizeEnv tse) { if (ccExpr instanceof RefExpr) { if (!((RefExpr)ccExpr).getName().toString().equals("$$SYNCH")) { Vector > set = new Vector > (); Vector subSet = new Vector (); RefExpr refExpr = (RefExpr)ccExpr; if (tse.getMap().keySet().contains(refExpr.getZName().toString())) { int x = 0; int y = tse.get(refExpr.getZName().toString()); for (int j = x; j < y; j++) { subSet.addElement (new BigInteger ("" + j + "")); } set.addElement (subSet); //subSet = new Vector (); return set; } else { //if (o tipo for inteiro, então) { //TODO faça com que minComm receba -maxComm/2, e itere até maxComm/2 //} for (int j = minComm; j <= maxComm; j++) { subSet.addElement (new BigInteger ("" + j + "")); } set.addElement (subSet); subSet = new Vector (); return set; } } else { return new Vector > (); } } else if (ccExpr instanceof SetExpr) { Vector > set = new Vector > (); Vector subSet = new Vector (); ZExprList setExprList = ((SetExpr) ccExpr).getZExprList(); int setSize = setExprList.size(); for (int k = 0; k < setSize; k++) { Expr expr2 = setExprList.get(k); if (expr2 instanceof NumExpr) { //Aqui estamos admitindo que NumExpr sera um numero, e nao uma expressao numerica. //Sendo uma expressao numerica com operadores, variaveis, e etc, nao garanto que aqui vai funcionar subSet.addElement (((NumExpr)expr2).getValue());//Integer.parseInt(((NumExpr)expr2).getValue()); } } set.addElement (subSet); subSet = new Vector (); return set; } else if (ccExpr instanceof ProdExpr) { Vector > set = new Vector > (); Vector subSet = new Vector (); ZExprList prodExprList = ((ProdExpr)ccExpr).getZExprList(); int prodSize = prodExprList.size(); for (int i = 0; i < prodSize; i++) { Expr expr = prodExprList.get(i); //set.addElement(obj); set.addAll(toVVBigInteger (expr, minComm, maxComm, env, tse)); } return set; } else /*if (any other condition?)*/{ return new Vector > (); } } public static void printValues (int [] values) { for (int i = 0; i < values.length; i++) { System.out.print ("values [" + i + "] = " + values [i] + "; "); } System.out.println (); } public static int [] increment (int [] values, boolean [] inputDecoration, int [] min, int [] max, Vector > valuesSet) { int size = values.length; boolean incremented = false; for (int i = size - 1; i >= 0; i--) { if (values [i] < max [i] && !incremented && inputDecoration [i]) { values [i] = nextOne (i, values, valuesSet); incremented = true; minFromNowOn (i + 1, values, inputDecoration, min); } } return values; } public int getCommValue (int index, int [] values) { return values [index]; } public static int [] getInitArrayOfValues (boolean [] inputDecoration, Vector > vvb/*int min, int max*/) { int [] values = new int [inputDecoration.length]; int size = values.length; for (int i = 0; i < size; i++) { if (inputDecoration [i]) { values [i] = /*min*/ vvb.elementAt(i).elementAt(0).intValue(); } else values [i] = /*max*/ vvb.elementAt(i).elementAt(vvb.elementAt(i).size() - 1).intValue(); } return values; } public static String bracketized (Object value) { return "[" + value + "]"; } public static String bracketizeds (int x, Object value) { String str = ""; for (int i = 0; i < x; i++) { str = str + bracketized (value); } return str; } public static String bracketizeds (String chanName, int [] values, Object [] commValues, boolean [] inputDecoration, int label) { String str = chanName + " "; int size = values.length; for (int i = 0; i < size; i++) { if (inputDecoration [i]) str = str + bracketized ("abs_" + chanName + ".abs (" + "\"" + chanName + "\", " + i + ", new BigInteger (\"" + values [i] + "\"))"); else str = str + bracketized ("abs_" + chanName/*+ label*/ + ".abs (" + "\"" + chanName + "\", " + i + ", " + "new BigInteger (\"\" + (" + commValues [i] + ").getValue()/*toString()*/ + \"\")" + ")"); /*str = str + bracketized ("ccMaps.env_channels.get (" + "\"" + chanName + "\").elementAt (" + i + ").indexOf (new BigInteger (\"" + values [i] + "\"))"); else str = str + bracketized ("ccMaps.env_channels.get (" + "\"" + chanName + "\").elementAt (" + i + ").indexOf (" + "(new BigInteger ((" + commValues [i] + ").toString())" + "))");*/ } return str; } public static String [] varNames (Communication c) { //Testada CircusFieldList cfl = c.getCircusFieldList(); String [] names = new String [cfl.size()]; for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { names [i] = ((InputField)cfl.get(i)).getVariableZName().toString(); } else { names [i] = "none"; } } return names; } public static boolean [] toInputDecoration (Communication communication) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; } } return inputDecoration; } public static int [] boundsAType (Communication c, int min) { int size = c.getCircusFieldList().size(); int [] mins = new int [size]; for (int i = 0; i < size; i++) { mins [i] = min; } return mins; } public static Object [] toCommValues (Communication communication, Visitor c) { //TODO n�o testada. A fun��o guardsCode que inclui a assinatura com Communication pode ser simplificada com o uso de toCommValues e toInputDecoration CircusFieldList cfl = communication.getCircusFieldList(); Object [] commValues = initCommValues (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { commValues [i] = -1; } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); } } return commValues; } public static String makeSyncOnOtherEndsButFirstCode (String chanName, Communication communication, int [] min, int [] max, Visitor c, Vector > valuesSet, int label, Channel2TypeEnvironment cte4cc) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); Object [] commValues = initCommValues (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); } } printNames (varNames (communication)); return makeSyncOnOtherEndsButFirstCode (chanName, communication, inputDecoration, commValues, min, max, valuesSet, label, cte4cc); } public static String getTypeInstantiation (String typeName, String valueName) { if (typeName.equals ("CircusInteger")) { return valueName; } else return "new CircusInteger ((new " + typeName + " (" + typeName + "." + valueName + ")).getValue ())"; } public static String complementarCommParams (boolean isDecl, Communication c, Channel2TypeEnvironment cte4cc) { String channelName = c.getChannelExpr().getZName().toString(); CircusFieldList cfl = c.getCircusFieldList(); String str = cfl.size() > 0? "" : ""; for (int i = 0; i < cfl.size(); i++) { Field field = cfl.get(i); if (field instanceof DotField) { Expr expr = ((DotField)field).getExpr(); if (expr instanceof RefExpr) { String strexpr = ((RefExpr)expr).getName().toString(); str = str + ", "; if (isDecl) { str = str + "CircusInteger " + strexpr; } else { str = str + getTypeInstantiation (cte4cc.getFreeType(channelName, i), strexpr); } //str = str + ((RefExpr)expr).getName().toString(); } } } return str; } protected static String indexesbutfirstcode () { return " private static int [] endindexesbutfirst (int [] endindexes) {\n" + " int [] indexesbutfirst = new int [endindexes.length - 1];\n" + " for (int i = 1; i < endindexes.length; i++) {\n" + " indexesbutfirst [i - 1] = endindexes [i];\n" + " }\n" + " return indexesbutfirst;\n"+ " }\n"; } public static String makeSyncOnOtherEndsButFirstCode (String chanName, Communication communication, boolean [] inputDecoration, Object [] commValues, int [] min, int [] max, Vector > valuesSet, int label, Channel2TypeEnvironment cte4cc) { int counter = 0; String str = ""; //str = str + indexesbutfirstcode (); str = str + " public static void syncOnOtherEndsButFirst_" + chanName + " (final GeneralChannel " + bracketizeds (commValues.length, "") + chanName + ", final Abs_" + chanName + " abs_" + chanName + "" + complementarCommParams (true, communication, cte4cc) + ", int [] endindexes) {\n"; if (!isCCSyncType (valuesSet)) { /*str = str + " switch (select) {\n";*/ str = str + " int [] indexesbutfirst = endindexesbutfirst (endindexes);\n"; str = str + " if (indexesbutfirst.length == 0) {\n" + " //Nothing to do\n" + " }\n" + " else {\n" + " int select = (new org.jcsp.lang.Alternative (\n" + " new org.jcsp.lang.Guard [] {\n"; int [] values = getInitArrayOfValues (inputDecoration, valuesSet); while (!reachedMax (values, valuesSet)) { str = str + " " + bracketizeds (chanName, values, commValues, inputDecoration, label) + ".getFirstEnd (indexesbutfirst),\n"; increment (values, inputDecoration, min, max, valuesSet); counter++; } str = str + " }\n"; str = str + " )).select ();\n"; str = str + " syncOnOtherEndsButFirst_" + chanName + " " +"(" + chanName + ", abs_" + chanName + complementarCommParams (false, communication, cte4cc) + ", indexesbutfirst" + ");\n" ; str = str + " }\n" + " }\n"; return str; } else { FrontEndAnn fea = FrontEndAnn.getFrontEndAnn(communication); str = str + " " + chanName + ".syncOnOtherEndsButFirst (" + FrontEndAnn.getFrontEndAnn(communication).toString() + ");\n"; } str = str + " }"; return str; } public static int countGuards (String chanName, Communication communication, boolean [] inputDecoration, Object [] commValues, int [] min, int [] max, Vector > valuesSet, int label) { int counter = 1; if (!isCCSyncType (valuesSet)) { int [] values = getInitArrayOfValues (inputDecoration, valuesSet); String str = ""; while (!reachedMax (values, valuesSet)) { increment (values, inputDecoration, min, max, valuesSet); counter++; } return counter; } else { return 1; } } public static String guardsCode (String chanName, Communication communication, boolean [] inputDecoration, Object [] commValues, int [] min, int [] max, Vector > valuesSet, int label) { if (!isCCSyncType (valuesSet)) { int [] values = getInitArrayOfValues (inputDecoration, valuesSet); String str = ""; while (!reachedMax (values, valuesSet)) { str = str + "\n" + bracketizeds (chanName, values, commValues, inputDecoration, label) + ".getFirstEnd(" + FrontEndAnn.getFrontEndAnn(communication).toString() + "),"; increment (values, inputDecoration, min, max, valuesSet); } str = str + "\n" + bracketizeds (chanName, values, commValues, inputDecoration, label) + ".getFirstEnd(" + FrontEndAnn.getFrontEndAnn(communication).toString() + "), "; return str; } else { return chanName + ".getFirstEnd(" + FrontEndAnn.getFrontEndAnn(communication).toString() + "), "; } } private static boolean isCCSyncType (Vector > valuesSet) { if (valuesSet.isEmpty()) { return true; } else { int size = valuesSet.size(); if (size == 0) return true; else if (size == 1) { if (valuesSet.elementAt(0).isEmpty()) { return true; } } return false; } } public static StringAndCounter envsCode (Object [] commValues, boolean [] inputDecoration, String [] names, int [] min, int [] max, int indexOfChosenComm, int initCounterSelect, boolean extChoice, Vector > valuesSet) { //int [] values = getInitArrayOfValues (inputDecoration, min, max); StringAndCounter sac = new StringAndCounter(); if (!isCCSyncType (valuesSet)){ int [] values = getInitArrayOfValues (inputDecoration, valuesSet); String str = ""; int counter = 0/*initCounterSelect*/; while (!reachedMax (values, valuesSet/*max*/)) { boolean reached = reachedMax (values, valuesSet); str = str + " HashMap select_" + (counter + initCounterSelect) + " = new HashMap ();\n"; for (int i = 0; i < names.length; i++) { if (inputDecoration [i]/*!names [i].equals ("none")*/) { str = str + " select_" + (counter + initCounterSelect) + ".put (\"" + names [i] + "\", new Integer (" + values [i] + "));\n"; } } str = str + " mapFromSelectToVarEnv.put (new Integer (" + (counter + initCounterSelect) + "), " + "select_" + (counter + initCounterSelect) + ");\n"; if (extChoice) str = str + " mapLeftOrRight.put (" + (counter + initCounterSelect) + ", " + "new Integer (" + indexOfChosenComm + "));\n"; //System.out.println ("LOOP INFINITO??"); if (!reachedMax (values, valuesSet)) increment (values, inputDecoration, min, max, valuesSet); counter++; } str = str + " HashMap select_" + (counter + initCounterSelect) + " = new HashMap ();"; for (int i = 0; i < names.length; i++) { if (inputDecoration [i]) { str = str + " select_" + (counter + initCounterSelect) + ".put (\"" + names [i] + "\", new Integer (" + values [i] + "));\n"; } } str = str + " mapFromSelectToVarEnv.put (new Integer (" + (counter + initCounterSelect) + "), " + "select_" + (counter + initCounterSelect) + ");\n"; if (extChoice) { str = str + " mapLeftOrRight.put (" + (counter + initCounterSelect) + ", " + "new Integer (" + indexOfChosenComm + "));\n"; System.out.print (""); } if (!reachedMax (values, valuesSet)) increment (values, inputDecoration, min, max, valuesSet); counter++; //initCounterSelect = counter; sac.str = str; sac.counter = counter; return sac; } else { String str = ""; int counter = 0;/*initCounterSelect;*/ str = str + " mapLeftOrRight.put (" + (counter + initCounterSelect) + ", " + "new Integer (" + indexOfChosenComm + "));\n"; counter++; sac.str = str; sac.counter = counter; //initCounterSelect = counter; return sac; } } public static StringAndCounter envsCode (String chanName, Communication communication, int [] min, int [] max, Visitor c, int indexOfChosenComm, int initCounterSelect, boolean extChoice, Vector > valuesSet) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); Object [] commValues = initCommValues (cfl.size()); String [] names = new String [cfl.size()]; for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; names [i] = ((InputField)cfl.get(i)).getVariableZName().toString(); } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); names [i] = "none"; } } printNames (varNames (communication)); //if (inputDecoration.length >0) return envsCode (commValues, inputDecoration, names, min, max, indexOfChosenComm, initCounterSelect, extChoice, valuesSet); //else return new StringAndCounter (); } public static int countGuards (String chanName, Communication communication, int [] min, int [] max, Visitor c, Vector > valuesSet, int label) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); Object [] commValues = initCommValues (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); } } //printNames (varNames (communication)); return countGuards (chanName, communication, inputDecoration, commValues, min, max, valuesSet, label); } public static String guardsCode (String chanName, Communication communication, int [] min, int [] max, Visitor c, Vector > valuesSet, int label) { CircusFieldList cfl = communication.getCircusFieldList(); boolean [] inputDecoration = initInputDecoration (cfl.size()); Object [] commValues = initCommValues (cfl.size()); for (int i = 0; i < cfl.size(); i++) { if (cfl.get(i) instanceof InputField) { inputDecoration [i] = true; } else { commValues [i] = ((DotField)cfl.get(i)).getExpr().accept(c); } } printNames (varNames (communication)); return guardsCode (chanName, communication, inputDecoration, commValues, min, max, valuesSet, label); } public static void printNames (String [] names) { //METODO TEMPORARIO. Depois que a funcao varNames for verificada e estiver correta, esta aqui eh dispensavel String str = ""; for (int i = 0; i < names.length; i++) { str = str + names [i] + " "; } //JOptionPane.showMessageDialog (null, str); } public static int potInt (int b, int e) { ////Servir� para a gera��o do m�todo getProcessSyncEnds na vers�o estendida int aux = 1; for (int i = 1; i <= e; i++) { aux = aux * b; } return aux; } public static int valueOfCommInputPart (int line, int pos, int numOfInputs, int minValue, int maxValue) { return (line / (potInt (maxValue - minValue + 1, numOfInputs - pos))) % (maxValue - minValue + 1); } public static int indexOfInputPart (int pos, boolean [] inputDecoration) { int n = 0; if (!inputDecoration [pos]) { return -1; } else { for (int i = pos; i < inputDecoration.length; i++) { if (inputDecoration [i]) n++; } } return n; } public static int numOfInputs (boolean [] inputDecoration) { int x = 0; for (int i = 0; i < inputDecoration.length; i++) { if (inputDecoration [i]) x++; } return x; } public static int numOfGuards (boolean [] inputDecoration, Vector > v) { int m = v.size(); int aux = 0; for (int i = 0; i < m; i++) { if (inputDecoration [i]) { for (int j = 0; j < v.elementAt(i).size(); j++) { aux++; } } else aux++; } return aux; } public static void main (String args []) { //System.out.println (guardsCode ("chan", new boolean [] {true, false, true, true}, new Object [] {-1, 5, -1, -1}, new int [] {0, 0, 0, 0}, new int [] {9, 9, 9, 9})); //System.out.print (calculateCommValue (0, 837, new boolean [] {true, false, true, true}, new int [] {-1, 5, -1, -1}, 0, 9) + " "); //System.out.print (calculateCommValue (1, 837, new boolean [] {true, false, true, true}, new int [] {-1, 5, -1, -1}, 0, 9) + " "); //System.out.print (calculateCommValue (2, 837, new boolean [] {true, false, true, true}, new int [] {-1, 5, -1, -1}, 0, 9) + " "); //System.out.print (calculateCommValue (3, 837, new boolean [] {true, false, true, true}, new int [] {-1, 5, -1, -1}, 0, 9) + "\n"); } }