From: <van...@us...> - 2007-02-13 08:29:36
|
Revision: 2136 http://svn.sourceforge.net/pcgen/?rev=2136&view=rev Author: vandaelek Date: 2007-02-13 00:28:46 -0800 (Tue, 13 Feb 2007) Log Message: ----------- Added svn:keywords and cleaned up PMD warnings. Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/gui/utils/InfoLabelTextBuilder.java Trunk/pcgen/code/src/test/pcgen/gui/utils/InfoLabelTextBuilderTest.java Property Changed: ---------------- Trunk/pcgen/code/src/java/pcgen/gui/utils/InfoLabelTextBuilder.java Trunk/pcgen/code/src/test/pcgen/gui/utils/InfoLabelTextBuilderTest.java Modified: Trunk/pcgen/code/src/java/pcgen/gui/utils/InfoLabelTextBuilder.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/utils/InfoLabelTextBuilder.java 2007-02-10 16:55:15 UTC (rev 2135) +++ Trunk/pcgen/code/src/java/pcgen/gui/utils/InfoLabelTextBuilder.java 2007-02-13 08:28:46 UTC (rev 2136) @@ -36,7 +36,7 @@ */ public class InfoLabelTextBuilder { - private StringBuilder buffer = new StringBuilder(300); + private static StringBuilder buffer = new StringBuilder(300); public InfoLabelTextBuilder() { @@ -57,7 +57,7 @@ * @param string String to add * @return InfoLabelTextBuilder */ - public InfoLabelTextBuilder append(String string) + public InfoLabelTextBuilder append(final String string) { buffer.append(string); return this; @@ -73,7 +73,7 @@ return this; } - private void appendTitleElement(String title) + private void appendTitleElement(final String title) { buffer.append("<b><font size=+1>").append(title).append("</font></b>"); } @@ -84,7 +84,7 @@ * @param value The value that belongs to the key. * @return InfoLabelTextBuilder */ - public InfoLabelTextBuilder appendElement(String key, String value) + public InfoLabelTextBuilder appendElement(final String key, final String value) { buffer.append(" <b>").append(key).append("</b>: ").append(value); return this; @@ -97,7 +97,7 @@ * @param value The value that belongs to the key. * @return InfoLabelTextBuilder */ - public InfoLabelTextBuilder appendI18nElement(String propertyKey, String value) + public InfoLabelTextBuilder appendI18nElement(final String propertyKey, final String value) { return appendElement(PropertyFactory.getString(propertyKey),value); } Property changes on: Trunk/pcgen/code/src/java/pcgen/gui/utils/InfoLabelTextBuilder.java ___________________________________________________________________ Name: svn:keywords + Date Author Revision Id Modified: Trunk/pcgen/code/src/test/pcgen/gui/utils/InfoLabelTextBuilderTest.java =================================================================== Property changes on: Trunk/pcgen/code/src/test/pcgen/gui/utils/InfoLabelTextBuilderTest.java ___________________________________________________________________ Name: svn:keywords + Date Author Revision Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-03-06 08:23:03
|
Revision: 2403 http://svn.sourceforge.net/pcgen/?rev=2403&view=rev Author: jdempsey Date: 2007-03-06 00:23:02 -0800 (Tue, 06 Mar 2007) Log Message: ----------- Restrict CATEGORY in PREABILITY to first param after # matches. Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreAbilityParser.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Modified: Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2007-03-06 05:41:31 UTC (rev 2402) +++ Trunk/pcgen/code/src/java/pcgen/gui/prop/LanguageBundle.properties 2007-03-06 08:23:02 UTC (rev 2403) @@ -3813,10 +3813,12 @@ # 2 - PObject key Errors.LstFileLoader.ModObjectNotFound={0} ({1}): PObject {2} not found; .MOD skipped. -# 0 - Category Name 1 # 1 - Category Name 2 Errors.PreAbility.MultipleCategory=Only one category may be specified in a PREABILITY entry. Found two categories: {0} and {1}. +# 0 - Category Name +Errors.PreAbility.CategoryNotFirst=Category must be the first parameter of a PREABILITY entry after the number of ability matches required. Found later category entry of: {0}. + Errors.FilterFactory.ParseError=Error in FilterFactory::parseCustomFilterList Spell.Components.Verbal=V Modified: Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreAbilityParser.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreAbilityParser.java 2007-03-06 05:41:31 UTC (rev 2402) +++ Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreAbilityParser.java 2007-03-06 08:23:02 UTC (rev 2403) @@ -27,7 +27,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.logging.Logger; import pcgen.core.prereq.Prerequisite; import pcgen.persistence.PersistenceLayerException; @@ -146,6 +145,13 @@ "Errors.PreAbility.MultipleCategory", categoryName, tempCat)); } + else if (p != prereqList.get(0)) + { + throw new PersistenceLayerException(PropertyFactory + .getFormattedString( + "Errors.PreAbility.CategoryNotFirst", + tempCat)); + } if (!tempCat.toUpperCase().trim().equals("ANY")) { Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2007-03-06 05:41:31 UTC (rev 2402) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2007-03-06 08:23:02 UTC (rev 2403) @@ -78,7 +78,7 @@ // // Examples from the PCGen documentation - note that there are two columns for each entry below // - "PREABILITY:1,Sneak Attack,CATEGORY.Special Attack", "PREABILITY:1,CHECKMULT,CATEGORY.Special Attack,Sneak Attack", + "PREABILITY:1,CATEGORY.Special Attack,Sneak Attack", "PREABILITY:1,CHECKMULT,CATEGORY.Special Attack,Sneak Attack", "PREALIGN:LG,NG,CG", "PREMULT:1,[PREALIGN:LG],[PREALIGN:NG],[PREALIGN:CG]", "PREALIGN:2,5,8", "PREMULT:1,[PREALIGN:LE],[PREALIGN:NE],[PREALIGN:CE]", "PREALIGN:LG,Deity", "PREMULT:1,[PREALIGN:LG],[PREALIGN:Deity]", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nu...@us...> - 2007-03-12 20:50:15
|
Revision: 2489 http://svn.sourceforge.net/pcgen/?rev=2489&view=rev Author: nuance Date: 2007-03-12 13:50:11 -0700 (Mon, 12 Mar 2007) Log Message: ----------- Add some classes that will eventually be used by the jep count stuff Added Paths: ----------- Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java Trunk/pcgen/code/src/test/plugin/jepcommands/ Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java Added: Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java (rev 0) +++ Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java 2007-03-12 20:50:11 UTC (rev 2489) @@ -0,0 +1,201 @@ +/* + * ParameterTree.java + * Copyright 2007 (C) Andrew Wilson <nu...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 10 March 2007 + * + * $Id$ + * + */ +package plugin.jepcommands; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.nfunk.jep.ParseException; + +public class ParameterTree +{ + String data; + ParameterTree left; + ParameterTree right; + static Pattern pat = Pattern.compile("(\\(|\\)|\\|\\||\\&\\&)"); + + + static ParameterTree makeTree (final String source) throws ParseException + { + Matcher mat = ParameterTree.pat.matcher(source); + + if (mat.find()) { + return ParameterTree.makeTree(null, source.substring(0, mat.start()), mat, source, 0); + } else { + return new ParameterTree(source); + } + } + + static ParameterTree makeTree (ParameterTree outertree, String beforeop, Matcher m, String s, int start) throws ParseException + { + ParameterTree newt = null; + + if (m.group().equalsIgnoreCase("(")) + { + if (m.start() != start) + { + throw new ParseException("found ( with no preceeding operator at char " + start + " of " + s); + } + + if (m.find()) + { + newt = makeTree(null, s.substring(start + 1, m.start()), m, s, start + 1); + + } + else + { + throw new ParseException("We should have matched a ')' to close the inner expression."); + } + } + + + ParameterTree root = outertree; + + if (beforeop.equalsIgnoreCase("")) + { + if (null == newt) + { + throw new ParseException("Apparently empty operand at char " + start + " of " + s); + } + else + { + if (root == null) { + root = newt; + } + else + { + root.setRightTree(newt); + } + } + } + else + { + if (root == null) { + root = new ParameterTree(beforeop); + } + else + { + root.setRightTree(new ParameterTree(beforeop)); + } + } + + int nextstart = 0; + + // we can't just check for ")" because that will close all recursed subtrees + // if we match the ), then we try to match again, this resets the match object + // for the calling instance of this method. This may mean that when the caller + // hits this piece of code, the match object is in an invalid state. + try + { + nextstart = m.end(); + + if (m.group().equalsIgnoreCase(")")) + { + // because this find may not work, the match object in the caller needs this try block + if (m.find()) + { + if (nextstart != m.start()) + { + throw new ParseException("a close bracket must be followed by an operator or another close bracket"); + } + } + return root; + } + } + catch (IllegalStateException e) + { + return root; + } + + final ParameterTree op = new ParameterTree(m.group()); + + op.setLeftTree(root); + root = op; + + // grab the start of the right operand incase we need it next + nextstart = m.end(); + + if (m.find()) { + + ParameterTree t1 = makeTree(root, s.substring(nextstart, m.start()), m, s, nextstart); + return t1; + + } else { + root.setRightTree(new ParameterTree(s.substring(nextstart))); + return root; + } + } + + public Double processTree (Enum e) + { + + return new Double(0.0); + } + + /** + * @param data + */ + public ParameterTree(String data) { + super(); + this.data = data; + left = null; + right = null; + } + + /** + * @return the Contents + */ + public String getContents() { + return data; + } + + + /** + * @return the left subtree + */ + public ParameterTree getLeftTree() { + return left; + } + + /** + * @param l the ParameterTree to add as the left sub tree + */ + public void setLeftTree(ParameterTree l) { + this.left = l; + } + + /** + * @return the right subtree + */ + public ParameterTree getRightTree() { + return right; + } + + /** + * @param r the ParameterTree to add as the right sub tree + */ + public void setRightTree(ParameterTree r) { + this.right = r; + } +} \ No newline at end of file Property changes on: Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java ___________________________________________________________________ Name: svn:keywords + Date Author Revision Id Name: svn:eol-style + native Added: Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java 2007-03-12 20:50:11 UTC (rev 2489) @@ -0,0 +1,405 @@ +/* + * ParameterTreeTest.java + * Copyright 2007 (C) Andrew Wilson <nu...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 10 March 2007 + * + * $Id$ + * + */ + +package plugin.jepcommands; + +import java.util.regex.Matcher; + +import org.junit.Test; +import org.nfunk.jep.ParseException; + +import pcgen.PCGenTestCase; + +/** + * <code>BioTokenTest</code> is ... + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author andrew wilson <nu...@us...> + * @version $Revision$ + */ +public class ParameterTreeTest extends PCGenTestCase +{ + + + /** + * Test method for {@link plugin.jepcommands.ParameterTree#ParameterTree(java.lang.String)}. + */ + @Test + public final void testParameterTree() + { + ParameterTree t1 = new ParameterTree("Test Node1"); + is(t1.getContents(), strEq("Test Node1"), "New ParamterTrre has correct contents"); + is(t1.getLeftTree(), eqnull(), "New ParamterTrre has null left subtree"); + is(t1.getRightTree(), eqnull(), "New ParamterTrre has null right subtree"); + + ParameterTree t2 = new ParameterTree("Test Node2"); + t2.setLeftTree(t1); + is(t2.getContents(), strEq("Test Node2"), "New ParamterTrre has correct contents"); + is(t2.getLeftTree().getContents(), strEq("Test Node1"), "New ParamterTrre has null left subtree"); + is(t1.getRightTree(), eqnull(), "New ParamterTrre has null right subtree"); + } + + @Test + public final void testMakeTree1() + { + String s = "TYPE=Foo"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq(s), "New ParamterTree has correct contents"); + } + + @Test + public final void testMakeTree2() + { + String s = "(TYPE=Foo)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct contents"); + } + + @Test + public final void testMakeTree3() + { + String s = "((TYPE=Foo))"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct contents"); + } + + @Test + public final void testMakeTree4() + { + String s = "TYPE=Foo||TYPE=Bar"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq("||"), "New ParamterTree has correct contents"); + is(t1.getLeftTree().getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct left tree contents"); + is(t1.getLeftTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); + is(t1.getLeftTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); + + is(t1.getRightTree().getContents(), strEq("TYPE=Bar"), "New ParamterTree has correct right tree contents"); + is(t1.getRightTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); + is(t1.getRightTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); + } + + + @Test + public final void testMakeTree5() + { + String s = "(TYPE=Foo||TYPE=Bar)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq("||"), "New ParamterTree has correct contents"); + is(t1.getLeftTree().getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct left tree contents"); + is(t1.getLeftTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); + is(t1.getLeftTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); + + is(t1.getRightTree().getContents(), strEq("TYPE=Bar"), "New ParamterTree has correct right tree contents"); + is(t1.getRightTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); + is(t1.getRightTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); + } + + @Test + public final void testMakeTree6() + { + String s = "(TYPE=Foo||TYPE=Bar&&String3)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t = new ParameterTree("Foo"); + try { + t = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + ParameterTree tl = t.getLeftTree(); + ParameterTree tr = t.getRightTree(); + ParameterTree tll = tl.getLeftTree(); + ParameterTree tlr = tl.getRightTree(); + + // expected branch nodes + is(t.getContents(), strEq("&&"), "t1 ParamterTree has correct contents"); + is(tl.getContents(), strEq("||"), "tl ParamterTree has correct contents"); + + // expected leaf nodes + is(tr.getContents(), strEq("String3"), "tr ParamterTree has correct contents"); + is(tll.getContents(), strEq("TYPE=Foo"), "tll ParamterTree has correct contents"); + is(tlr.getContents(), strEq("TYPE=Bar"), "tlr ParamterTree has correct contents"); + + // check that leaves really are leaves + is(tr.getLeftTree(), eqnull(), "tr left tree is null (i.e. is a leaf node)"); + is(tr.getRightTree(), eqnull(), "tr right tree is null (i.e. is a leaf node)"); + + is(tll.getLeftTree(), eqnull(), "tll left tree is null (i.e. is a leaf node)"); + is(tll.getRightTree(), eqnull(), "tll right tree is null (i.e. is a leaf node)"); + + is(tlr.getLeftTree(), eqnull(), "tlr left tree is null (i.e. is a leaf node)"); + is(tlr.getRightTree(), eqnull(), "tlr right tree is null (i.e. is a leaf node)"); + } + + @Test + public final void testMakeTree7() + { +// verbose = true; +// Logging.errorPrint("\n\n --- Start Test Make tree 7 --- \n\n"); + + String s = "TYPE=Foo||(TYPE=Bar&&String3)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t = new ParameterTree("Foo"); + try { + t = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + ParameterTree tl = t.getLeftTree(); + ParameterTree tr = t.getRightTree(); + ParameterTree trl = tr.getLeftTree(); + ParameterTree trr = tr.getRightTree(); + + // expected branch nodes + is(t, not(eqnull()), "t not null"); + is(tr, not(eqnull()), "tr not null"); + + is(t.getContents(), strEq("||"), "t has correct contents '||'"); + is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); + + // expected leaf nodes + is(tl, not(eqnull()), "tl not null"); + is(trl, not(eqnull()), "trl not null"); + is(trr, not(eqnull()), "trr not null"); + + is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); + is(trl.getContents(), strEq("TYPE=Bar"), "trl has correct contents 'TYPE=Bar'"); + is(trr.getContents(), strEq("String3"), "trr has correct contents 'String3'"); + + // check that leaves really are leaves + is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); + is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); + + is(trl.getLeftTree(), eqnull(), "trl left tree is null (i.e. is a leaf node)"); + is(trl.getRightTree(), eqnull(), "trl right tree is null (i.e. is a leaf node)"); + + is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); + is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); + } + + + @Test + public final void testMakeTree8() + { +// verbose = true; +// Logging.errorPrint("\n\n --- Start Test Make tree 8 --- \n\n"); + + String s = "TYPE=Foo||((CATEGORY=FEAT||NATURE=AUTO)&&TYPE=Bar)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t = new ParameterTree("Foo"); + try + { + t = ParameterTree.makeTree(s); + } + catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + + ParameterTree tl = t.getLeftTree(); + ParameterTree tr = t.getRightTree(); + + ParameterTree trl = tr.getLeftTree(); + ParameterTree trr = tr.getRightTree(); + + ParameterTree trll = trl.getLeftTree(); + ParameterTree trlr = trl.getRightTree(); + + + // expected branch nodes + is(t, not(eqnull()), "t not null"); + is(tr, not(eqnull()), "tr not null"); + is(trl, not(eqnull()), "trl not null"); + + is(t.getContents(), strEq("||"), "t has correct contents '||'"); + is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); + is(trl.getContents(), strEq("||"), "trl has correct contents '||'"); + + // expected leaf nodes + is(tl, not(eqnull()), "tl not null"); + is(trr, not(eqnull()), "trr not null"); + + is(trll, not(eqnull()), "trll not null"); + is(trlr, not(eqnull()), "trlr not null"); + + is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); + is(trr.getContents(), strEq("TYPE=Bar"), "trr has correct contents 'TYPE=Bar'"); + + is(trll.getContents(), strEq("CATEGORY=FEAT"), "trl has correct contents 'CATEGORY=FEAT'"); + is(trlr.getContents(), strEq("NATURE=AUTO"), "trl has correct contents 'NATURE=AUTO'"); + + // check that leaves really are leaves + is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); + is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); + + is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); + is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); + + is(trll.getLeftTree(), eqnull(), "trl left tree is null (i.e. is a leaf node)"); + is(trll.getRightTree(), eqnull(), "trl right tree is null (i.e. is a leaf node)"); + + is(trlr.getLeftTree(), eqnull(), "trll left tree is null (i.e. is a leaf node)"); + is(trlr.getRightTree(), eqnull(), "trlr right tree is null (i.e. is a leaf node)"); + } + + @Test + public final void testMakeTree9() + { +// verbose = true; +// Logging.errorPrint("\n\n --- Start Test Make tree 9 --- \n\n"); + + String s = "TYPE=Foo||((CATEGORY=FEAT||NATURE=AUTO||CATEGORY=SA)&&TYPE=Bar)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t = new ParameterTree("Foo"); + try + { + t = ParameterTree.makeTree(s); + } + catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + + ParameterTree tl = t.getLeftTree(); + ParameterTree tr = t.getRightTree(); + + ParameterTree trl = tr.getLeftTree(); + ParameterTree trr = tr.getRightTree(); + + ParameterTree trll = trl.getLeftTree(); + ParameterTree trlr = trl.getRightTree(); + + ParameterTree trlll = trll.getLeftTree(); + ParameterTree trllr = trll.getRightTree(); + + + // expected branch nodes + is(t, not(eqnull()), "t not null"); + is(tr, not(eqnull()), "tr not null"); + is(trl, not(eqnull()), "trl not null"); + is(trll, not(eqnull()), "trll not null"); + + is(t.getContents(), strEq("||"), "t has correct contents '||'"); + is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); + is(trl.getContents(), strEq("||"), "trl has correct contents '||'"); + is(trll.getContents(), strEq("||"), "trll has correct contents '||'"); + + // expected leaf nodes + is(tl, not(eqnull()), "tl not null"); + is(trr, not(eqnull()), "trr not null"); + + is(trlr, not(eqnull()), "trlr not null"); + is(trlll, not(eqnull()), "trlll not null"); + is(trllr, not(eqnull()), "trllr not null"); + + is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); + is(trr.getContents(), strEq("TYPE=Bar"), "trr has correct contents 'TYPE=Bar'"); + + is(trlr.getContents(), strEq("CATEGORY=SA"), "trlr has correct contents 'CATEGORY=SA'"); + is(trlll.getContents(), strEq("CATEGORY=FEAT"), "trlr has correct contents 'CATEGORY=FEAT'"); + is(trllr.getContents(), strEq("NATURE=AUTO"), "trlr has correct contents 'NATURE=AUTO'"); + + + // check that leaves really are leaves + is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); + is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); + + is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); + is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); + + is(trlr.getLeftTree(), eqnull(), "trll left tree is null (i.e. is a leaf node)"); + is(trlr.getRightTree(), eqnull(), "trlr right tree is null (i.e. is a leaf node)"); + + is(trlll.getLeftTree(), eqnull(), "trlll left tree is null (i.e. is a leaf node)"); + is(trlll.getRightTree(), eqnull(), "trlll right tree is null (i.e. is a leaf node)"); + + is(trllr.getLeftTree(), eqnull(), "trlll left tree is null (i.e. is a leaf node)"); + is(trllr.getRightTree(), eqnull(), "trlll right tree is null (i.e. is a leaf node)"); + } +} Property changes on: Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java ___________________________________________________________________ Name: svn:keywords + Date Author Revision Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nu...@us...> - 2007-03-12 22:11:14
|
Revision: 2490 http://svn.sourceforge.net/pcgen/?rev=2490&view=rev Author: nuance Date: 2007-03-12 15:11:13 -0700 (Mon, 12 Mar 2007) Log Message: ----------- These have been added in the wrong location, They aren't jep plugins Removed Paths: ------------- Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java Deleted: Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java 2007-03-12 20:50:11 UTC (rev 2489) +++ Trunk/pcgen/code/src/java/plugin/jepcommands/ParameterTree.java 2007-03-12 22:11:13 UTC (rev 2490) @@ -1,201 +0,0 @@ -/* - * ParameterTree.java - * Copyright 2007 (C) Andrew Wilson <nu...@us...> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Created on 10 March 2007 - * - * $Id$ - * - */ -package plugin.jepcommands; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.nfunk.jep.ParseException; - -public class ParameterTree -{ - String data; - ParameterTree left; - ParameterTree right; - static Pattern pat = Pattern.compile("(\\(|\\)|\\|\\||\\&\\&)"); - - - static ParameterTree makeTree (final String source) throws ParseException - { - Matcher mat = ParameterTree.pat.matcher(source); - - if (mat.find()) { - return ParameterTree.makeTree(null, source.substring(0, mat.start()), mat, source, 0); - } else { - return new ParameterTree(source); - } - } - - static ParameterTree makeTree (ParameterTree outertree, String beforeop, Matcher m, String s, int start) throws ParseException - { - ParameterTree newt = null; - - if (m.group().equalsIgnoreCase("(")) - { - if (m.start() != start) - { - throw new ParseException("found ( with no preceeding operator at char " + start + " of " + s); - } - - if (m.find()) - { - newt = makeTree(null, s.substring(start + 1, m.start()), m, s, start + 1); - - } - else - { - throw new ParseException("We should have matched a ')' to close the inner expression."); - } - } - - - ParameterTree root = outertree; - - if (beforeop.equalsIgnoreCase("")) - { - if (null == newt) - { - throw new ParseException("Apparently empty operand at char " + start + " of " + s); - } - else - { - if (root == null) { - root = newt; - } - else - { - root.setRightTree(newt); - } - } - } - else - { - if (root == null) { - root = new ParameterTree(beforeop); - } - else - { - root.setRightTree(new ParameterTree(beforeop)); - } - } - - int nextstart = 0; - - // we can't just check for ")" because that will close all recursed subtrees - // if we match the ), then we try to match again, this resets the match object - // for the calling instance of this method. This may mean that when the caller - // hits this piece of code, the match object is in an invalid state. - try - { - nextstart = m.end(); - - if (m.group().equalsIgnoreCase(")")) - { - // because this find may not work, the match object in the caller needs this try block - if (m.find()) - { - if (nextstart != m.start()) - { - throw new ParseException("a close bracket must be followed by an operator or another close bracket"); - } - } - return root; - } - } - catch (IllegalStateException e) - { - return root; - } - - final ParameterTree op = new ParameterTree(m.group()); - - op.setLeftTree(root); - root = op; - - // grab the start of the right operand incase we need it next - nextstart = m.end(); - - if (m.find()) { - - ParameterTree t1 = makeTree(root, s.substring(nextstart, m.start()), m, s, nextstart); - return t1; - - } else { - root.setRightTree(new ParameterTree(s.substring(nextstart))); - return root; - } - } - - public Double processTree (Enum e) - { - - return new Double(0.0); - } - - /** - * @param data - */ - public ParameterTree(String data) { - super(); - this.data = data; - left = null; - right = null; - } - - /** - * @return the Contents - */ - public String getContents() { - return data; - } - - - /** - * @return the left subtree - */ - public ParameterTree getLeftTree() { - return left; - } - - /** - * @param l the ParameterTree to add as the left sub tree - */ - public void setLeftTree(ParameterTree l) { - this.left = l; - } - - /** - * @return the right subtree - */ - public ParameterTree getRightTree() { - return right; - } - - /** - * @param r the ParameterTree to add as the right sub tree - */ - public void setRightTree(ParameterTree r) { - this.right = r; - } -} \ No newline at end of file Deleted: Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java 2007-03-12 20:50:11 UTC (rev 2489) +++ Trunk/pcgen/code/src/test/plugin/jepcommands/ParameterTreeTest.java 2007-03-12 22:11:13 UTC (rev 2490) @@ -1,405 +0,0 @@ -/* - * ParameterTreeTest.java - * Copyright 2007 (C) Andrew Wilson <nu...@us...> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Created on 10 March 2007 - * - * $Id$ - * - */ - -package plugin.jepcommands; - -import java.util.regex.Matcher; - -import org.junit.Test; -import org.nfunk.jep.ParseException; - -import pcgen.PCGenTestCase; - -/** - * <code>BioTokenTest</code> is ... - * - * Last Editor: $Author$ - * Last Edited: $Date$ - * - * @author andrew wilson <nu...@us...> - * @version $Revision$ - */ -public class ParameterTreeTest extends PCGenTestCase -{ - - - /** - * Test method for {@link plugin.jepcommands.ParameterTree#ParameterTree(java.lang.String)}. - */ - @Test - public final void testParameterTree() - { - ParameterTree t1 = new ParameterTree("Test Node1"); - is(t1.getContents(), strEq("Test Node1"), "New ParamterTrre has correct contents"); - is(t1.getLeftTree(), eqnull(), "New ParamterTrre has null left subtree"); - is(t1.getRightTree(), eqnull(), "New ParamterTrre has null right subtree"); - - ParameterTree t2 = new ParameterTree("Test Node2"); - t2.setLeftTree(t1); - is(t2.getContents(), strEq("Test Node2"), "New ParamterTrre has correct contents"); - is(t2.getLeftTree().getContents(), strEq("Test Node1"), "New ParamterTrre has null left subtree"); - is(t1.getRightTree(), eqnull(), "New ParamterTrre has null right subtree"); - } - - @Test - public final void testMakeTree1() - { - String s = "TYPE=Foo"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t1 = new ParameterTree("Foo"); - try { - t1 = ParameterTree.makeTree(s); - } catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - is(t1.getContents(), strEq(s), "New ParamterTree has correct contents"); - } - - @Test - public final void testMakeTree2() - { - String s = "(TYPE=Foo)"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t1 = new ParameterTree("Foo"); - try { - t1 = ParameterTree.makeTree(s); - } catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - is(t1.getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct contents"); - } - - @Test - public final void testMakeTree3() - { - String s = "((TYPE=Foo))"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t1 = new ParameterTree("Foo"); - try { - t1 = ParameterTree.makeTree(s); - } catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - is(t1.getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct contents"); - } - - @Test - public final void testMakeTree4() - { - String s = "TYPE=Foo||TYPE=Bar"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t1 = new ParameterTree("Foo"); - try { - t1 = ParameterTree.makeTree(s); - } catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - is(t1.getContents(), strEq("||"), "New ParamterTree has correct contents"); - is(t1.getLeftTree().getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct left tree contents"); - is(t1.getLeftTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); - is(t1.getLeftTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); - - is(t1.getRightTree().getContents(), strEq("TYPE=Bar"), "New ParamterTree has correct right tree contents"); - is(t1.getRightTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); - is(t1.getRightTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); - } - - - @Test - public final void testMakeTree5() - { - String s = "(TYPE=Foo||TYPE=Bar)"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t1 = new ParameterTree("Foo"); - try { - t1 = ParameterTree.makeTree(s); - } catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - is(t1.getContents(), strEq("||"), "New ParamterTree has correct contents"); - is(t1.getLeftTree().getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct left tree contents"); - is(t1.getLeftTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); - is(t1.getLeftTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); - - is(t1.getRightTree().getContents(), strEq("TYPE=Bar"), "New ParamterTree has correct right tree contents"); - is(t1.getRightTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); - is(t1.getRightTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); - } - - @Test - public final void testMakeTree6() - { - String s = "(TYPE=Foo||TYPE=Bar&&String3)"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t = new ParameterTree("Foo"); - try { - t = ParameterTree.makeTree(s); - } catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - ParameterTree tl = t.getLeftTree(); - ParameterTree tr = t.getRightTree(); - ParameterTree tll = tl.getLeftTree(); - ParameterTree tlr = tl.getRightTree(); - - // expected branch nodes - is(t.getContents(), strEq("&&"), "t1 ParamterTree has correct contents"); - is(tl.getContents(), strEq("||"), "tl ParamterTree has correct contents"); - - // expected leaf nodes - is(tr.getContents(), strEq("String3"), "tr ParamterTree has correct contents"); - is(tll.getContents(), strEq("TYPE=Foo"), "tll ParamterTree has correct contents"); - is(tlr.getContents(), strEq("TYPE=Bar"), "tlr ParamterTree has correct contents"); - - // check that leaves really are leaves - is(tr.getLeftTree(), eqnull(), "tr left tree is null (i.e. is a leaf node)"); - is(tr.getRightTree(), eqnull(), "tr right tree is null (i.e. is a leaf node)"); - - is(tll.getLeftTree(), eqnull(), "tll left tree is null (i.e. is a leaf node)"); - is(tll.getRightTree(), eqnull(), "tll right tree is null (i.e. is a leaf node)"); - - is(tlr.getLeftTree(), eqnull(), "tlr left tree is null (i.e. is a leaf node)"); - is(tlr.getRightTree(), eqnull(), "tlr right tree is null (i.e. is a leaf node)"); - } - - @Test - public final void testMakeTree7() - { -// verbose = true; -// Logging.errorPrint("\n\n --- Start Test Make tree 7 --- \n\n"); - - String s = "TYPE=Foo||(TYPE=Bar&&String3)"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t = new ParameterTree("Foo"); - try { - t = ParameterTree.makeTree(s); - } catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - ParameterTree tl = t.getLeftTree(); - ParameterTree tr = t.getRightTree(); - ParameterTree trl = tr.getLeftTree(); - ParameterTree trr = tr.getRightTree(); - - // expected branch nodes - is(t, not(eqnull()), "t not null"); - is(tr, not(eqnull()), "tr not null"); - - is(t.getContents(), strEq("||"), "t has correct contents '||'"); - is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); - - // expected leaf nodes - is(tl, not(eqnull()), "tl not null"); - is(trl, not(eqnull()), "trl not null"); - is(trr, not(eqnull()), "trr not null"); - - is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); - is(trl.getContents(), strEq("TYPE=Bar"), "trl has correct contents 'TYPE=Bar'"); - is(trr.getContents(), strEq("String3"), "trr has correct contents 'String3'"); - - // check that leaves really are leaves - is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); - is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); - - is(trl.getLeftTree(), eqnull(), "trl left tree is null (i.e. is a leaf node)"); - is(trl.getRightTree(), eqnull(), "trl right tree is null (i.e. is a leaf node)"); - - is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); - is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); - } - - - @Test - public final void testMakeTree8() - { -// verbose = true; -// Logging.errorPrint("\n\n --- Start Test Make tree 8 --- \n\n"); - - String s = "TYPE=Foo||((CATEGORY=FEAT||NATURE=AUTO)&&TYPE=Bar)"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t = new ParameterTree("Foo"); - try - { - t = ParameterTree.makeTree(s); - } - catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - - ParameterTree tl = t.getLeftTree(); - ParameterTree tr = t.getRightTree(); - - ParameterTree trl = tr.getLeftTree(); - ParameterTree trr = tr.getRightTree(); - - ParameterTree trll = trl.getLeftTree(); - ParameterTree trlr = trl.getRightTree(); - - - // expected branch nodes - is(t, not(eqnull()), "t not null"); - is(tr, not(eqnull()), "tr not null"); - is(trl, not(eqnull()), "trl not null"); - - is(t.getContents(), strEq("||"), "t has correct contents '||'"); - is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); - is(trl.getContents(), strEq("||"), "trl has correct contents '||'"); - - // expected leaf nodes - is(tl, not(eqnull()), "tl not null"); - is(trr, not(eqnull()), "trr not null"); - - is(trll, not(eqnull()), "trll not null"); - is(trlr, not(eqnull()), "trlr not null"); - - is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); - is(trr.getContents(), strEq("TYPE=Bar"), "trr has correct contents 'TYPE=Bar'"); - - is(trll.getContents(), strEq("CATEGORY=FEAT"), "trl has correct contents 'CATEGORY=FEAT'"); - is(trlr.getContents(), strEq("NATURE=AUTO"), "trl has correct contents 'NATURE=AUTO'"); - - // check that leaves really are leaves - is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); - is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); - - is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); - is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); - - is(trll.getLeftTree(), eqnull(), "trl left tree is null (i.e. is a leaf node)"); - is(trll.getRightTree(), eqnull(), "trl right tree is null (i.e. is a leaf node)"); - - is(trlr.getLeftTree(), eqnull(), "trll left tree is null (i.e. is a leaf node)"); - is(trlr.getRightTree(), eqnull(), "trlr right tree is null (i.e. is a leaf node)"); - } - - @Test - public final void testMakeTree9() - { -// verbose = true; -// Logging.errorPrint("\n\n --- Start Test Make tree 9 --- \n\n"); - - String s = "TYPE=Foo||((CATEGORY=FEAT||NATURE=AUTO||CATEGORY=SA)&&TYPE=Bar)"; - Matcher mat = ParameterTree.pat.matcher(s); - mat.find(); - - ParameterTree t = new ParameterTree("Foo"); - try - { - t = ParameterTree.makeTree(s); - } - catch (ParseException e) { - e.printStackTrace(); - fail("Threw a parse exception"); - } - - - ParameterTree tl = t.getLeftTree(); - ParameterTree tr = t.getRightTree(); - - ParameterTree trl = tr.getLeftTree(); - ParameterTree trr = tr.getRightTree(); - - ParameterTree trll = trl.getLeftTree(); - ParameterTree trlr = trl.getRightTree(); - - ParameterTree trlll = trll.getLeftTree(); - ParameterTree trllr = trll.getRightTree(); - - - // expected branch nodes - is(t, not(eqnull()), "t not null"); - is(tr, not(eqnull()), "tr not null"); - is(trl, not(eqnull()), "trl not null"); - is(trll, not(eqnull()), "trll not null"); - - is(t.getContents(), strEq("||"), "t has correct contents '||'"); - is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); - is(trl.getContents(), strEq("||"), "trl has correct contents '||'"); - is(trll.getContents(), strEq("||"), "trll has correct contents '||'"); - - // expected leaf nodes - is(tl, not(eqnull()), "tl not null"); - is(trr, not(eqnull()), "trr not null"); - - is(trlr, not(eqnull()), "trlr not null"); - is(trlll, not(eqnull()), "trlll not null"); - is(trllr, not(eqnull()), "trllr not null"); - - is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); - is(trr.getContents(), strEq("TYPE=Bar"), "trr has correct contents 'TYPE=Bar'"); - - is(trlr.getContents(), strEq("CATEGORY=SA"), "trlr has correct contents 'CATEGORY=SA'"); - is(trlll.getContents(), strEq("CATEGORY=FEAT"), "trlr has correct contents 'CATEGORY=FEAT'"); - is(trllr.getContents(), strEq("NATURE=AUTO"), "trlr has correct contents 'NATURE=AUTO'"); - - - // check that leaves really are leaves - is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); - is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); - - is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); - is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); - - is(trlr.getLeftTree(), eqnull(), "trll left tree is null (i.e. is a leaf node)"); - is(trlr.getRightTree(), eqnull(), "trlr right tree is null (i.e. is a leaf node)"); - - is(trlll.getLeftTree(), eqnull(), "trlll left tree is null (i.e. is a leaf node)"); - is(trlll.getRightTree(), eqnull(), "trlll right tree is null (i.e. is a leaf node)"); - - is(trllr.getLeftTree(), eqnull(), "trlll left tree is null (i.e. is a leaf node)"); - is(trllr.getRightTree(), eqnull(), "trlll right tree is null (i.e. is a leaf node)"); - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nu...@us...> - 2007-03-12 22:25:29
|
Revision: 2491 http://svn.sourceforge.net/pcgen/?rev=2491&view=rev Author: nuance Date: 2007-03-12 15:25:30 -0700 (Mon, 12 Mar 2007) Log Message: ----------- Add these back in a more sensible place. Added Paths: ----------- Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java Added: Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java (rev 0) +++ Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java 2007-03-12 22:25:30 UTC (rev 2491) @@ -0,0 +1,201 @@ +/* + * ParameterTree.java + * Copyright 2007 (C) Andrew Wilson <nu...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 10 March 2007 + * + * $Id: ParameterTree.java 2489 2007-03-12 20:50:11Z nuance $ + * + */ +package pcgen.util; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.nfunk.jep.ParseException; + +public class ParameterTree +{ + String data; + ParameterTree left; + ParameterTree right; + static Pattern pat = Pattern.compile("(\\(|\\)|\\|\\||\\&\\&)"); + + + static ParameterTree makeTree (final String source) throws ParseException + { + Matcher mat = ParameterTree.pat.matcher(source); + + if (mat.find()) { + return ParameterTree.makeTree(null, source.substring(0, mat.start()), mat, source, 0); + } else { + return new ParameterTree(source); + } + } + + static ParameterTree makeTree (ParameterTree outertree, String beforeop, Matcher m, String s, int start) throws ParseException + { + ParameterTree newt = null; + + if (m.group().equalsIgnoreCase("(")) + { + if (m.start() != start) + { + throw new ParseException("found ( with no preceeding operator at char " + start + " of " + s); + } + + if (m.find()) + { + newt = makeTree(null, s.substring(start + 1, m.start()), m, s, start + 1); + + } + else + { + throw new ParseException("We should have matched a ')' to close the inner expression."); + } + } + + + ParameterTree root = outertree; + + if (beforeop.equalsIgnoreCase("")) + { + if (null == newt) + { + throw new ParseException("Apparently empty operand at char " + start + " of " + s); + } + else + { + if (root == null) { + root = newt; + } + else + { + root.setRightTree(newt); + } + } + } + else + { + if (root == null) { + root = new ParameterTree(beforeop); + } + else + { + root.setRightTree(new ParameterTree(beforeop)); + } + } + + int nextstart = 0; + + // we can't just check for ")" because that will close all recursed subtrees + // if we match the ), then we try to match again, this resets the match object + // for the calling instance of this method. This may mean that when the caller + // hits this piece of code, the match object is in an invalid state. + try + { + nextstart = m.end(); + + if (m.group().equalsIgnoreCase(")")) + { + // because this find may not work, the match object in the caller needs this try block + if (m.find()) + { + if (nextstart != m.start()) + { + throw new ParseException("a close bracket must be followed by an operator or another close bracket"); + } + } + return root; + } + } + catch (IllegalStateException e) + { + return root; + } + + final ParameterTree op = new ParameterTree(m.group()); + + op.setLeftTree(root); + root = op; + + // grab the start of the right operand incase we need it next + nextstart = m.end(); + + if (m.find()) { + + ParameterTree t1 = makeTree(root, s.substring(nextstart, m.start()), m, s, nextstart); + return t1; + + } else { + root.setRightTree(new ParameterTree(s.substring(nextstart))); + return root; + } + } + + public Double processTree (Enum e) + { + + return new Double(0.0); + } + + /** + * @param data + */ + public ParameterTree(String data) { + super(); + this.data = data; + left = null; + right = null; + } + + /** + * @return the Contents + */ + public String getContents() { + return data; + } + + + /** + * @return the left subtree + */ + public ParameterTree getLeftTree() { + return left; + } + + /** + * @param l the ParameterTree to add as the left sub tree + */ + public void setLeftTree(ParameterTree l) { + this.left = l; + } + + /** + * @return the right subtree + */ + public ParameterTree getRightTree() { + return right; + } + + /** + * @param r the ParameterTree to add as the right sub tree + */ + public void setRightTree(ParameterTree r) { + this.right = r; + } +} \ No newline at end of file Property changes on: Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java ___________________________________________________________________ Name: svn:executable + * Added: Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java (rev 0) +++ Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java 2007-03-12 22:25:30 UTC (rev 2491) @@ -0,0 +1,406 @@ +/* + * ParameterTreeTest.java + * Copyright 2007 (C) Andrew Wilson <nu...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 10 March 2007 + * + * $Id: ParameterTreeTest.java 2489 2007-03-12 20:50:11Z nuance $ + * + */ + +package pcgen.util; + +import java.util.regex.Matcher; + +import org.junit.Test; +import org.nfunk.jep.ParseException; + +import pcgen.PCGenTestCase; +import pcgen.util.ParameterTree; + +/** + * <code>ParameterTreeTest</code> is ... + * + * Last Editor: $Author: nuance $ + * Last Edited: $Date: 2007-03-12 20:50:11 +0000 (Mon, 12 Mar 2007) $ + * + * @author andrew wilson <nu...@us...> + * @version $Revision: 2489 $ + */ +public class ParameterTreeTest extends PCGenTestCase +{ + + + /** + * Test method for {@link pcgen.util.ParameterTree#ParameterTree(java.lang.String)}. + */ + @Test + public final void testParameterTree() + { + ParameterTree t1 = new ParameterTree("Test Node1"); + is(t1.getContents(), strEq("Test Node1"), "New ParamterTrre has correct contents"); + is(t1.getLeftTree(), eqnull(), "New ParamterTrre has null left subtree"); + is(t1.getRightTree(), eqnull(), "New ParamterTrre has null right subtree"); + + ParameterTree t2 = new ParameterTree("Test Node2"); + t2.setLeftTree(t1); + is(t2.getContents(), strEq("Test Node2"), "New ParamterTrre has correct contents"); + is(t2.getLeftTree().getContents(), strEq("Test Node1"), "New ParamterTrre has null left subtree"); + is(t1.getRightTree(), eqnull(), "New ParamterTrre has null right subtree"); + } + + @Test + public final void testMakeTree1() + { + String s = "TYPE=Foo"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq(s), "New ParamterTree has correct contents"); + } + + @Test + public final void testMakeTree2() + { + String s = "(TYPE=Foo)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct contents"); + } + + @Test + public final void testMakeTree3() + { + String s = "((TYPE=Foo))"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct contents"); + } + + @Test + public final void testMakeTree4() + { + String s = "TYPE=Foo||TYPE=Bar"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq("||"), "New ParamterTree has correct contents"); + is(t1.getLeftTree().getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct left tree contents"); + is(t1.getLeftTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); + is(t1.getLeftTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); + + is(t1.getRightTree().getContents(), strEq("TYPE=Bar"), "New ParamterTree has correct right tree contents"); + is(t1.getRightTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); + is(t1.getRightTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); + } + + + @Test + public final void testMakeTree5() + { + String s = "(TYPE=Foo||TYPE=Bar)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t1 = new ParameterTree("Foo"); + try { + t1 = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + is(t1.getContents(), strEq("||"), "New ParamterTree has correct contents"); + is(t1.getLeftTree().getContents(), strEq("TYPE=Foo"), "New ParamterTree has correct left tree contents"); + is(t1.getLeftTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); + is(t1.getLeftTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); + + is(t1.getRightTree().getContents(), strEq("TYPE=Bar"), "New ParamterTree has correct right tree contents"); + is(t1.getRightTree().getLeftTree(), eqnull(), "New ParamterTree has correct left tree, left tree contents"); + is(t1.getRightTree().getRightTree(), eqnull(), "New ParamterTree has correct left tree, right tree contents"); + } + + @Test + public final void testMakeTree6() + { + String s = "(TYPE=Foo||TYPE=Bar&&String3)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t = new ParameterTree("Foo"); + try { + t = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + ParameterTree tl = t.getLeftTree(); + ParameterTree tr = t.getRightTree(); + ParameterTree tll = tl.getLeftTree(); + ParameterTree tlr = tl.getRightTree(); + + // expected branch nodes + is(t.getContents(), strEq("&&"), "t1 ParamterTree has correct contents"); + is(tl.getContents(), strEq("||"), "tl ParamterTree has correct contents"); + + // expected leaf nodes + is(tr.getContents(), strEq("String3"), "tr ParamterTree has correct contents"); + is(tll.getContents(), strEq("TYPE=Foo"), "tll ParamterTree has correct contents"); + is(tlr.getContents(), strEq("TYPE=Bar"), "tlr ParamterTree has correct contents"); + + // check that leaves really are leaves + is(tr.getLeftTree(), eqnull(), "tr left tree is null (i.e. is a leaf node)"); + is(tr.getRightTree(), eqnull(), "tr right tree is null (i.e. is a leaf node)"); + + is(tll.getLeftTree(), eqnull(), "tll left tree is null (i.e. is a leaf node)"); + is(tll.getRightTree(), eqnull(), "tll right tree is null (i.e. is a leaf node)"); + + is(tlr.getLeftTree(), eqnull(), "tlr left tree is null (i.e. is a leaf node)"); + is(tlr.getRightTree(), eqnull(), "tlr right tree is null (i.e. is a leaf node)"); + } + + @Test + public final void testMakeTree7() + { +// verbose = true; +// Logging.errorPrint("\n\n --- Start Test Make tree 7 --- \n\n"); + + String s = "TYPE=Foo||(TYPE=Bar&&String3)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t = new ParameterTree("Foo"); + try { + t = ParameterTree.makeTree(s); + } catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + ParameterTree tl = t.getLeftTree(); + ParameterTree tr = t.getRightTree(); + ParameterTree trl = tr.getLeftTree(); + ParameterTree trr = tr.getRightTree(); + + // expected branch nodes + is(t, not(eqnull()), "t not null"); + is(tr, not(eqnull()), "tr not null"); + + is(t.getContents(), strEq("||"), "t has correct contents '||'"); + is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); + + // expected leaf nodes + is(tl, not(eqnull()), "tl not null"); + is(trl, not(eqnull()), "trl not null"); + is(trr, not(eqnull()), "trr not null"); + + is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); + is(trl.getContents(), strEq("TYPE=Bar"), "trl has correct contents 'TYPE=Bar'"); + is(trr.getContents(), strEq("String3"), "trr has correct contents 'String3'"); + + // check that leaves really are leaves + is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); + is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); + + is(trl.getLeftTree(), eqnull(), "trl left tree is null (i.e. is a leaf node)"); + is(trl.getRightTree(), eqnull(), "trl right tree is null (i.e. is a leaf node)"); + + is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); + is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); + } + + + @Test + public final void testMakeTree8() + { +// verbose = true; +// Logging.errorPrint("\n\n --- Start Test Make tree 8 --- \n\n"); + + String s = "TYPE=Foo||((CATEGORY=FEAT||NATURE=AUTO)&&TYPE=Bar)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t = new ParameterTree("Foo"); + try + { + t = ParameterTree.makeTree(s); + } + catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + + ParameterTree tl = t.getLeftTree(); + ParameterTree tr = t.getRightTree(); + + ParameterTree trl = tr.getLeftTree(); + ParameterTree trr = tr.getRightTree(); + + ParameterTree trll = trl.getLeftTree(); + ParameterTree trlr = trl.getRightTree(); + + + // expected branch nodes + is(t, not(eqnull()), "t not null"); + is(tr, not(eqnull()), "tr not null"); + is(trl, not(eqnull()), "trl not null"); + + is(t.getContents(), strEq("||"), "t has correct contents '||'"); + is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); + is(trl.getContents(), strEq("||"), "trl has correct contents '||'"); + + // expected leaf nodes + is(tl, not(eqnull()), "tl not null"); + is(trr, not(eqnull()), "trr not null"); + + is(trll, not(eqnull()), "trll not null"); + is(trlr, not(eqnull()), "trlr not null"); + + is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); + is(trr.getContents(), strEq("TYPE=Bar"), "trr has correct contents 'TYPE=Bar'"); + + is(trll.getContents(), strEq("CATEGORY=FEAT"), "trl has correct contents 'CATEGORY=FEAT'"); + is(trlr.getContents(), strEq("NATURE=AUTO"), "trl has correct contents 'NATURE=AUTO'"); + + // check that leaves really are leaves + is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); + is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); + + is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); + is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); + + is(trll.getLeftTree(), eqnull(), "trl left tree is null (i.e. is a leaf node)"); + is(trll.getRightTree(), eqnull(), "trl right tree is null (i.e. is a leaf node)"); + + is(trlr.getLeftTree(), eqnull(), "trll left tree is null (i.e. is a leaf node)"); + is(trlr.getRightTree(), eqnull(), "trlr right tree is null (i.e. is a leaf node)"); + } + + @Test + public final void testMakeTree9() + { +// verbose = true; +// Logging.errorPrint("\n\n --- Start Test Make tree 9 --- \n\n"); + + String s = "TYPE=Foo||((CATEGORY=FEAT||NATURE=AUTO||CATEGORY=SA)&&TYPE=Bar)"; + Matcher mat = ParameterTree.pat.matcher(s); + mat.find(); + + ParameterTree t = new ParameterTree("Foo"); + try + { + t = ParameterTree.makeTree(s); + } + catch (ParseException e) { + e.printStackTrace(); + fail("Threw a parse exception"); + } + + + ParameterTree tl = t.getLeftTree(); + ParameterTree tr = t.getRightTree(); + + ParameterTree trl = tr.getLeftTree(); + ParameterTree trr = tr.getRightTree(); + + ParameterTree trll = trl.getLeftTree(); + ParameterTree trlr = trl.getRightTree(); + + ParameterTree trlll = trll.getLeftTree(); + ParameterTree trllr = trll.getRightTree(); + + + // expected branch nodes + is(t, not(eqnull()), "t not null"); + is(tr, not(eqnull()), "tr not null"); + is(trl, not(eqnull()), "trl not null"); + is(trll, not(eqnull()), "trll not null"); + + is(t.getContents(), strEq("||"), "t has correct contents '||'"); + is(tr.getContents(), strEq("&&"), "tr has correct contents '&&'"); + is(trl.getContents(), strEq("||"), "trl has correct contents '||'"); + is(trll.getContents(), strEq("||"), "trll has correct contents '||'"); + + // expected leaf nodes + is(tl, not(eqnull()), "tl not null"); + is(trr, not(eqnull()), "trr not null"); + + is(trlr, not(eqnull()), "trlr not null"); + is(trlll, not(eqnull()), "trlll not null"); + is(trllr, not(eqnull()), "trllr not null"); + + is(tl.getContents(), strEq("TYPE=Foo"), "tl has correct contents 'TYPE=Foo'"); + is(trr.getContents(), strEq("TYPE=Bar"), "trr has correct contents 'TYPE=Bar'"); + + is(trlr.getContents(), strEq("CATEGORY=SA"), "trlr has correct contents 'CATEGORY=SA'"); + is(trlll.getContents(), strEq("CATEGORY=FEAT"), "trlr has correct contents 'CATEGORY=FEAT'"); + is(trllr.getContents(), strEq("NATURE=AUTO"), "trlr has correct contents 'NATURE=AUTO'"); + + + // check that leaves really are leaves + is(tl.getLeftTree(), eqnull(), "tl left tree is null (i.e. is a leaf node)"); + is(tl.getRightTree(), eqnull(), "tl right tree is null (i.e. is a leaf node)"); + + is(trr.getLeftTree(), eqnull(), "trr left tree is null (i.e. is a leaf node)"); + is(trr.getRightTree(), eqnull(), "trr right tree is null (i.e. is a leaf node)"); + + is(trlr.getLeftTree(), eqnull(), "trll left tree is null (i.e. is a leaf node)"); + is(trlr.getRightTree(), eqnull(), "trlr right tree is null (i.e. is a leaf node)"); + + is(trlll.getLeftTree(), eqnull(), "trlll left tree is null (i.e. is a leaf node)"); + is(trlll.getRightTree(), eqnull(), "trlll right tree is null (i.e. is a leaf node)"); + + is(trllr.getLeftTree(), eqnull(), "trlll left tree is null (i.e. is a leaf node)"); + is(trllr.getRightTree(), eqnull(), "trlll right tree is null (i.e. is a leaf node)"); + } +} Property changes on: Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nu...@us...> - 2007-03-12 22:30:25
|
Revision: 2492 http://svn.sourceforge.net/pcgen/?rev=2492&view=rev Author: nuance Date: 2007-03-12 15:30:23 -0700 (Mon, 12 Mar 2007) Log Message: ----------- Fix the properties Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java Property Changed: ---------------- Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java Modified: Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java 2007-03-12 22:25:30 UTC (rev 2491) +++ Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java 2007-03-12 22:30:23 UTC (rev 2492) @@ -18,7 +18,7 @@ * * Created on 10 March 2007 * - * $Id: ParameterTree.java 2489 2007-03-12 20:50:11Z nuance $ + * $Id$ * */ package pcgen.util; Property changes on: Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java ___________________________________________________________________ Name: svn:executable - * Name: svn:keywords + Date Author Revision Id Name: svn:eol-style + native Modified: Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java 2007-03-12 22:25:30 UTC (rev 2491) +++ Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java 2007-03-12 22:30:23 UTC (rev 2492) @@ -18,7 +18,7 @@ * * Created on 10 March 2007 * - * $Id: ParameterTreeTest.java 2489 2007-03-12 20:50:11Z nuance $ + * $Id$ * */ @@ -35,11 +35,11 @@ /** * <code>ParameterTreeTest</code> is ... * - * Last Editor: $Author: nuance $ - * Last Edited: $Date: 2007-03-12 20:50:11 +0000 (Mon, 12 Mar 2007) $ + * Last Editor: $Author$ + * Last Edited: $Date$ * * @author andrew wilson <nu...@us...> - * @version $Revision: 2489 $ + * @version $Revision$ */ public class ParameterTreeTest extends PCGenTestCase { Property changes on: Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java ___________________________________________________________________ Name: svn:executable - * Name: svn:keywords + Date Author Revision Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nu...@us...> - 2007-03-15 01:05:28
|
Revision: 2506 http://svn.sourceforge.net/pcgen/?rev=2506&view=rev Author: nuance Date: 2007-03-14 18:05:29 -0700 (Wed, 14 Mar 2007) Log Message: ----------- Committing this even though the tests are failing. I believe the tests are failing because the ABILITY: tag is currently broken. This adds a method to PlayerCharacter to return a map of sets of ability objects that the pc currently has. It will eventually be used by the jep count code. Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-03-14 21:55:07 UTC (rev 2505) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-03-15 01:05:29 UTC (rev 2506) @@ -15900,6 +15900,35 @@ return new ArrayList<Ability>(featList); } + public HashMap<Ability.Nature, Set<Ability>> getAbilitiesSet() + { + + final Set<AbilityCategory> abCats = theAbilities.getKeySet(); + + HashMap<Ability.Nature, Set<Ability>> st = new HashMap<Ability.Nature, Set<Ability>>(); + + st.put(Ability.Nature.AUTOMATIC, new HashSet<Ability>()); + st.put(Ability.Nature.NORMAL, new HashSet<Ability>()); + st.put(Ability.Nature.VIRTUAL, new HashSet<Ability>()); + st.put(Ability.Nature.ANY, new HashSet<Ability>()); + + if (abCats == null) + { + return st; + } + + st.get(Ability.Nature.VIRTUAL).addAll(getVirtualFeatList()); + st.get(Ability.Nature.AUTOMATIC).addAll(featAutoList()); + st.get(Ability.Nature.NORMAL).addAll(getRealFeatList()); + + st.get(Ability.Nature.ANY).addAll(st.get(Ability.Nature.NORMAL)); + st.get(Ability.Nature.ANY).addAll(st.get(Ability.Nature.AUTOMATIC)); + st.get(Ability.Nature.ANY).addAll(st.get(Ability.Nature.VIRTUAL)); + + return st; + } + + public List<Ability> getRealAbilitiesList(final AbilityCategory aCategory) { if (aCategory == AbilityCategory.FEAT) @@ -17443,7 +17472,7 @@ { for (String key : pobj.getAbilityKeys(this, AbilityCategory.FEAT, Nature.AUTOMATIC)) { - Logging.errorPrint("Got ability key " + key + " from " + pobj + "."); + //Logging.errorPrint("Got ability key " + key + " from " + pobj + "."); Ability added = AbilityUtilities .addCloneOfGlobalAbilityToListWithChoices( Modified: Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java 2007-03-14 21:55:07 UTC (rev 2505) +++ Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java 2007-03-15 01:05:29 UTC (rev 2506) @@ -784,4 +784,86 @@ -1), giantClass, spellBookName); assertEquals("Delete spell should not be rejected.", "", response); } + + /** + * Tests getting a map of sets of abilities + */ + public void testGetAbilitiesSet() + { + verbose = true; + Logging.errorPrint("--- Start Get Abilities Set Test ---"); + + PCClass arClass = null; + + + // do so setup that is specific to testing this method + arClass = new PCClass(); + arClass.setName("AbilityRichClass"); + arClass.setAbbrev("ARc"); + arClass.setSpellType("ARCANE"); + + Globals.getClassList().add(arClass); + + TestHelper.makeAbilityFromString( + "TestARc01\tCATEGORY:FEAT\tMULT:YES\tSTACK:YES\tVISIBLE:YES\tCHOOSE:NOCHOICE"); + TestHelper.makeAbilityFromString( + "TestARc02\tCATEGORY:FEAT\tMULT:YES\tSTACK:YES\tVISIBLE:YES\tCHOOSE:NOCHOICE"); + TestHelper.makeAbilityFromString( + "TestARc03\tCATEGORY:FEAT\tMULT:YES\tSTACK:YES\tVISIBLE:YES\tCHOOSE:NOCHOICE"); + TestHelper.makeAbilityFromString( + "TestARc04\tCATEGORY:FEAT\tMULT:YES\tSTACK:YES\tVISIBLE:YES\tCHOOSE:NOCHOICE"); + TestHelper.makeAbilityFromString( + "TestARc05\tCATEGORY:FEAT\tMULT:YES\tSTACK:YES\tVISIBLE:YES\tCHOOSE:NOCHOICE"); + + AbilityLst abl = new AbilityLst(); + + + try + { + abl.parse(arClass, "FEAT|NORMAL|TestARc01", 1); + abl.parse(arClass, "FEAT|AUTOMATIC|TestARc02", 1); + abl.parse(arClass, "FEAT|VIRTUAL|TestARc03", 2); + abl.parse(arClass, "FEAT|AUTOMATIC|TestARc04", 3); + abl.parse(arClass, "FEAT|AUTOMATIC|TestARc05", 3); + } + catch (PersistenceLayerException e) + { + Logging.errorPrint("Oops, Parse exception" + e); + } + + final PlayerCharacter pc = new PlayerCharacter(); + + HashMap<Ability.Nature, Set<Ability>> map; + + pc.setRace(human); + + pc.incrementClassLevel(1, arClass, true); + + map = pc.getAbilitiesSet(); + + is(map.get(Ability.Nature.NORMAL).size(), eq(1), "First Level human with class AbilityRichClass has 1 normal feat"); + is(map.get(Ability.Nature.AUTOMATIC).size(), eq(1), "First Level human with class AbilityRichClass has 1 automatic feat"); + is(map.get(Ability.Nature.VIRTUAL).size(), eq(0), "First Level human with class AbilityRichClass has 0 virtual feats"); + + pc.incrementClassLevel(1, arClass, true); + + map = pc.getAbilitiesSet(); + + is(map.get(Ability.Nature.NORMAL).size(), eq(1), "Second Level human with class AbilityRichClass has 1 normal feat"); + is(map.get(Ability.Nature.AUTOMATIC).size(), eq(1), "Second Level human with class AbilityRichClass has 1 automatic feat"); + is(map.get(Ability.Nature.VIRTUAL).size(), eq(1), "Second Level human with class AbilityRichClass has 1 virtual feat"); + + pc.incrementClassLevel(1, arClass, true); + + map = pc.getAbilitiesSet(); + + is(map.get(Ability.Nature.NORMAL).size(), eq(1), "Third Level human with class AbilityRichClass has 1 normal feat"); + is(map.get(Ability.Nature.AUTOMATIC).size(), eq(3), "Third Level human with class AbilityRichClass has 3 automatic feats"); + is(map.get(Ability.Nature.VIRTUAL).size(), eq(1), "Third Level human with class AbilityRichClass has 1 virtual feat"); + + GameMode gm = SettingsHandler.getGame(); + AbilityCategory ac = gm.getAbilityCategory("FEAT"); + Logging.errorPrint("Real abilities: " + pc.getRealAbilityList(ac).size()); + + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-03-19 01:07:52
|
Revision: 2526 http://svn.sourceforge.net/pcgen/?rev=2526&view=rev Author: jdempsey Date: 2007-03-18 18:07:52 -0700 (Sun, 18 Mar 2007) Log Message: ----------- [1262317] Ability Object: Add ability tags [1262313] Ability Object: Fix feat tags to only add feat ability objs - Switch normal (real) and automatic feats to use ability lists - Aggregate normal and automatic abilities from all a character's PObjects Issue#: 1262317,1262313 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java Trunk/pcgen/code/src/java/pcgen/core/PObject.java Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/VariableProcessorPC.java Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java 2007-03-19 01:02:35 UTC (rev 2525) +++ Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java 2007-03-19 01:07:52 UTC (rev 2526) @@ -460,7 +460,7 @@ { int listSize = ability.getAssociatedCount(); - for (Ability myAbility : aPC.getRealFeatList()) + for (Ability myAbility : aPC.getRealAbilitiesList(AbilityCategory.FEAT)) { if (myAbility.getKeyName().equalsIgnoreCase(ability.getKeyName())) { Modified: Trunk/pcgen/code/src/java/pcgen/core/PObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2007-03-19 01:02:35 UTC (rev 2525) +++ Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2007-03-19 01:07:52 UTC (rev 2526) @@ -2186,7 +2186,7 @@ if (arg.startsWith("TYPE.")) { final String theType = arg.substring(5); - for (Ability aFeat : aPC.getRealFeatList()) + for (Ability aFeat : aPC.getRealAbilitiesList(AbilityCategory.FEAT)) { if (aFeat.isType(theType) && !theFeatList.contains(aFeat)) theFeatList.add(aFeat); @@ -2213,7 +2213,7 @@ } else if (arg.equals("CHOICE")) { - for (Ability aFeat : aPC.getRealFeatList()) + for (Ability aFeat : aPC.getRealAbilitiesList(AbilityCategory.FEAT)) { theFeatList.add(aFeat); } Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-03-19 01:02:35 UTC (rev 2525) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-03-19 01:07:52 UTC (rev 2526) @@ -262,13 +262,22 @@ private boolean processLevelAbilities = true; /** - * Abilities stored as a double key map. The keys are the Category and type - * (Normal, Virtual, or Automatic). The value is a list of abilities that - * match the keys. + * Aggregate abilities stored as a double key map. The keys are the Category + * and nature (Normal, Virtual, or Automatic). The value is a list of abilities + * that match the keys. When populated the list will contain a copy of all + * abilities the character possesses via any of its classes, feats, + * templates, equipoment etc. */ private DoubleKeyMap<AbilityCategory, Ability.Nature, List<Ability>> theAbilities = new DoubleKeyMap<AbilityCategory, Ability.Nature, List<Ability>>(); /** + * List of all directly assigned normal nature abilities split by category. + * These are abilities that are added directly to the character rather than + * being added to a class, tempalte etc that the character possesses. + */ + private Map<AbilityCategory, List<Ability>> realAbilities = new HashMap<AbilityCategory, List<Ability>>(); + + /** * This map stores any user bonuses (entered through the GUI) to the * corrisponding ability pool. */ @@ -14134,7 +14143,7 @@ { // remove this object from the feats lists - for (Iterator<Ability> iterator = getRealFeatList().iterator(); iterator + for (Iterator<Ability> iterator = getRealAbilitiesList(AbilityCategory.FEAT).iterator(); iterator .hasNext();) { final Ability feat = iterator.next(); @@ -14714,7 +14723,7 @@ aClone.addArmorProfs(getArmorProfList()); - for (final Ability a : this.getRealFeatList()) + for (final Ability a : this.getRealAbilitiesList(AbilityCategory.FEAT)) { aClone.addRealAbility(AbilityCategory.FEAT, (a.clone())); } @@ -15674,9 +15683,7 @@ // Feat/Ability stuff // -------------------------------------------------- // List of Feats - private final ArrayList<Ability> featList = new ArrayList<Ability>(); private List<Ability> stableAggregateFeatList = null; - private List<Ability> stableAutomaticFeatList = null; private List<Ability> stableVirtualFeatList = null; // Whether one can trust the most recently calculated aggregateFeatList @@ -15699,14 +15706,7 @@ */ private void setAggregateFeatsStable(final boolean stable) { - aggregateFeatsStable = stable; - setVirtualFeatsStable(stable); - setAutomaticFeatsStable(stable); - if (!stable) - { - cachedWeaponProfs = null; - } - // setDirty(true); + setAggregateAbilitiesStable(AbilityCategory.FEAT, stable); } public void setAggregateAbilitiesStable(final AbilityCategory aCategory, @@ -15718,8 +15718,13 @@ } if (aCategory == AbilityCategory.FEAT) { - setAggregateFeatsStable(stable); - return; + aggregateFeatsStable = stable; + setVirtualFeatsStable(stable); + setAutomaticFeatsStable(stable); + if (!stable) + { + cachedWeaponProfs = null; + } } if (aCategory == null) { @@ -15739,6 +15744,7 @@ theAbilities.put(aCategory, Ability.Nature.AUTOMATIC, null); // TODO - Deal with non-aggregate virtual abilities (i.e. from ADD:) theAbilities.put(aCategory, Ability.Nature.VIRTUAL, null); + theAbilities.put(aCategory, Ability.Nature.NORMAL, null); } } @@ -15750,8 +15756,9 @@ */ private boolean isAggregateFeatsStable() { - return (stableAutomaticFeatList != null) && virtualFeatsStable - && aggregateFeatsStable; + return (theAbilities + .get(AbilityCategory.FEAT, Ability.Nature.AUTOMATIC) != null) + && virtualFeatsStable && aggregateFeatsStable; } public boolean isAggregateAbilitiesStable(final AbilityCategory aCategory) @@ -15772,10 +15779,7 @@ */ private void setAutomaticFeatsStable(final boolean stable) { - if (!stable) - { - stableAutomaticFeatList = null; - } + setAutomaticAbilitiesStable(AbilityCategory.FEAT, stable); } public void setAutomaticAbilitiesStable(final AbilityCategory aCategory, @@ -15793,63 +15797,30 @@ setAutomaticFeatsStable(stable); return; } - if (aCategory == AbilityCategory.FEAT) - { - setAutomaticFeatsStable(stable); - return; - } if (!stable) { theAbilities.put(aCategory, Ability.Nature.AUTOMATIC, null); } } - /** - * Add a "real" (not virtual or auto) feat to the character - * - * @param aFeat - * the Ability (of category FEAT) to add - * - * @return true if added successfully - */ - private boolean addRealFeat(final Ability aFeat) - { - // return abilityStore.addCategorisable(aFeat) - return featList.add(aFeat); - } - public boolean addRealAbility(final AbilityCategory aCategory, final Ability anAbility) { - if (aCategory == AbilityCategory.FEAT) - { - return addRealFeat(anAbility); - } - if (anAbility == null) { return false; } anAbility.setFeatType(Ability.Nature.NORMAL); - List<Ability> abilities = theAbilities.get(aCategory, - Ability.Nature.NORMAL); + List<Ability> abilities = realAbilities.get(aCategory); if (abilities == null) { abilities = new ArrayList<Ability>(); - theAbilities.put(aCategory, Ability.Nature.NORMAL, abilities); + realAbilities.put(aCategory, abilities); } abilities.add(anAbility); return true; } - /** - * Remove all "real" (not auto or auto) feats from the character - */ - private void clearRealFeats() - { - featList.clear(); - } - public void clearRealAbilities(final AbilityCategory aCategory) { if (aCategory == null) @@ -15860,32 +15831,12 @@ } return; } - if (aCategory == AbilityCategory.FEAT) - { - clearRealFeats(); - return; - } theAbilities.put(aCategory, Ability.Nature.NORMAL, null); } - /** - * Get number of "real" (not virtual or auto) feats the character has - * - * @return DOCUMENT ME! - */ - private int getNumberOfRealFeats() - { - return featList.size(); - } - public int getNumberOfRealAbilities(final AbilityCategory aCategory) { - if (aCategory == AbilityCategory.FEAT) - { - return getNumberOfRealFeats(); - } - final List<Ability> abilities = theAbilities.get(aCategory, Ability.Nature.NORMAL); if (abilities == null) @@ -15895,11 +15846,6 @@ return abilities.size(); } - private List<Ability> getRealFeatsList() - { - return new ArrayList<Ability>(featList); - } - public HashMap<Ability.Nature, Set<Ability>> getAbilitiesSet() { @@ -15931,17 +15877,38 @@ public List<Ability> getRealAbilitiesList(final AbilityCategory aCategory) { - if (aCategory == AbilityCategory.FEAT) + List<Ability> abilities = theAbilities.get(aCategory, + Ability.Nature.NORMAL); + if (abilities != null) { - return getRealFeatsList(); + return Collections.unmodifiableList(abilities); } + // If the list is null it means it needs to be recalculated. - final List<Ability> abilities = theAbilities.get(aCategory, - Ability.Nature.NORMAL); - if (abilities == null) + abilities = new ArrayList<Ability>(); + if (realAbilities.get(aCategory) != null) { - return Collections.emptyList(); + abilities.addAll(realAbilities.get(aCategory)); } + theAbilities.put(aCategory, Ability.Nature.NORMAL, abilities); + + // Scan other objects which might hold abilities + for (final PObject pobj : getPObjectList()) + { + final List<String> abilityKeys = pobj.getAbilityKeys(this, + aCategory, Ability.Nature.NORMAL); + for (final String key : abilityKeys) + { + final Ability added = AbilityUtilities + .addCloneOfGlobalAbilityToListWithChoices(abilities, + aCategory, key); + if (added != null) + { + added.setFeatType(Ability.Nature.NORMAL); + } + } + } + return new ArrayList<Ability>(abilities); } @@ -15953,22 +15920,17 @@ */ public List<Ability> getRealFeatList() { - return featList; + return getRealAbilitiesList(AbilityCategory.FEAT); } + /** + * @deprecated Use getRealAbilitiesList instead. + * @param aCategory + * @return + */ public List<Ability> getRealAbilityList(final AbilityCategory aCategory) { - if (aCategory == AbilityCategory.FEAT) - { - return getRealFeatList(); - } - final List<Ability> ret = theAbilities.get(aCategory, - Ability.Nature.NORMAL); - if (ret == null) - { - return Collections.emptyList(); - } - return ret; + return getRealAbilitiesList(aCategory); } /** @@ -15983,20 +15945,14 @@ */ public Ability getRealFeatKeyed(final String featName) { - return getFeatKeyed(featName, featList); + return getRealAbilityKeyed(AbilityCategory.FEAT, featName); } public Ability getRealAbilityKeyed(final AbilityCategory aCategory, final String aKey) { - if (aCategory == AbilityCategory.FEAT) - { - return getRealFeatKeyed(aKey); - } + final List<Ability> abilities = getRealAbilitiesList(aCategory); - final List<Ability> abilities = theAbilities.get(aCategory, - Ability.Nature.NORMAL); - if (abilities != null) { for (final Ability ability : abilities) @@ -16024,8 +15980,8 @@ public Ability getRealFeatNamed(final String featName) { - return AbilityUtilities.getAbilityFromList(featList, "FEAT", featName, - Ability.Nature.ANY); + return AbilityUtilities.getAbilityFromList(realAbilities + .get(AbilityCategory.FEAT), "FEAT", featName, Ability.Nature.ANY); } /** @@ -16038,9 +15994,7 @@ */ public boolean hasRealFeat(final Ability aFeat) { - // return (abilityStore.getCategorisableNamed(aCategory, aFeat) != - // null); - return featList.contains(aFeat); + return hasRealAbility(AbilityCategory.FEAT, aFeat); } /** @@ -16056,11 +16010,6 @@ public boolean hasRealAbility(final AbilityCategory aCategory, final Ability anAbility) { - if (aCategory == AbilityCategory.FEAT) - { - return hasRealFeat(anAbility); - } - final List<Ability> abilities = theAbilities.get(aCategory, Ability.Nature.NORMAL); if (abilities == null) @@ -16131,34 +16080,18 @@ boolean hasIt = false; for (final AbilityCategory cat : categories) { - if (cat == AbilityCategory.FEAT) + switch (nature) { - switch (nature) - { - case NORMAL: - hasIt = hasRealAbility(cat, anAbility); - break; - case AUTOMATIC: - hasIt = hasAutomaticAbility(cat, anAbility); - break; - case VIRTUAL: - hasIt = hasVirtualAbility(cat, anAbility); - break; - } + case NORMAL: + hasIt = hasRealAbility(cat, anAbility); + break; + case AUTOMATIC: + hasIt = hasAutomaticAbility(cat, anAbility); + break; + case VIRTUAL: + hasIt = hasVirtualAbility(cat, anAbility); + break; } - else - { - final List<Ability> abilities = theAbilities.get(cat, - nature); - if (abilities == null) - { - continue; - } - if (abilities.contains(anAbility)) - { - hasIt = true; - } - } if (hasIt) { return true; @@ -16179,7 +16112,13 @@ public boolean hasRealFeatNamed(final String featName) { - return AbilityUtilities.getAbilityFromList(featList, "FEAT", featName, + final List<Ability> abilities = theAbilities.get(AbilityCategory.FEAT, + Ability.Nature.NORMAL); + if (abilities == null) + { + return false; + } + return AbilityUtilities.getAbilityFromList(abilities, "FEAT", featName, Ability.Nature.ANY) != null; } @@ -16193,19 +16132,13 @@ */ public boolean removeRealFeat(final Ability aFeat) { - return featList.remove(aFeat); + return removeRealAbility(AbilityCategory.FEAT, aFeat); } public boolean removeRealAbility(final AbilityCategory aCategory, final Ability anAbility) { - if (aCategory == AbilityCategory.FEAT) - { - return removeRealFeat(anAbility); - } - - final List<Ability> abilities = theAbilities.get(aCategory, - Ability.Nature.NORMAL); + final List<Ability> abilities = realAbilities.get(aCategory); if (abilities == null) { return false; @@ -16317,11 +16250,7 @@ public List<Ability> getSelectedAbilities(final AbilityCategory aCategory) { - if (aCategory == AbilityCategory.FEAT) - { - return getRealFeatList(); - } - return getRealAbilityList(aCategory); + return getRealAbilitiesList(aCategory); } public double getFeats() @@ -16405,7 +16334,7 @@ { double iCount = 0; - for (Ability aFeat : getRealFeatList()) + for (Ability aFeat : realAbilities.get(AbilityCategory.FEAT)) { // // Don't increment the count for @@ -16552,17 +16481,12 @@ public Ability getFeatAutomaticKeyed(final String aFeatKey) { - return AbilityUtilities.getAbilityFromList(featAutoList(), "FEAT", - aFeatKey, Ability.Nature.ANY); + return getAutomaticAbilityKeyed(AbilityCategory.FEAT, aFeatKey); } public Ability getAutomaticAbilityKeyed(final AbilityCategory aCategory, final String anAbilityKey) { - if (aCategory == AbilityCategory.FEAT) - { - return getFeatAutomaticKeyed(anAbilityKey); - } final List<Ability> abilities = getAutomaticAbilityList(aCategory); for (final Ability ability : abilities) { @@ -16734,7 +16658,7 @@ } final List<Ability> abilities = new ArrayList<Ability>( - getRealAbilityList(aCategory)); + getRealAbilitiesList(aCategory)); abilities.addAll(getVirtualAbilityList(aCategory)); abilities.addAll(getAutomaticAbilityList(aCategory)); @@ -16746,7 +16670,7 @@ List<Ability> aggregate = new ArrayList<Ability>(); final Map<String, Ability> aHashMap = new HashMap<String, Ability>(); - for (Ability aFeat : getRealFeatList()) + for (Ability aFeat : getRealAbilitiesList(AbilityCategory.FEAT)) { if (aFeat != null) { @@ -16851,17 +16775,8 @@ return Collections.unmodifiableList(ret); } - // boolean isAutomaticFeatsStable() - // { - // return automaticFeatsStable; - // } - boolean isAutomaticAbilitiesStable(final AbilityCategory aCategory) { - if (aCategory == AbilityCategory.FEAT) - { - return stableAutomaticFeatList != null; - } return theAbilities.get(aCategory, Ability.Nature.AUTOMATIC) != null; } @@ -16895,6 +16810,18 @@ { final List<Ability> aList = pcClass.getVirtualFeatList(pcClass .getLevel()); + final List<String> abilityKeys = pcClass.getAbilityKeys(this, + AbilityCategory.FEAT, Ability.Nature.VIRTUAL); + for (final String key : abilityKeys) + { + final Ability added = AbilityUtilities + .addCloneOfGlobalAbilityToListWithChoices(aList, + AbilityCategory.FEAT, key); + if (added != null) + { + added.setFeatType(Ability.Nature.VIRTUAL); + } + } for (Ability feat : aList) { @@ -16905,7 +16832,7 @@ } } - for (Ability aFeat : getRealFeatList()) + for (Ability aFeat : getRealAbilitiesList(AbilityCategory.FEAT)) { final List<Ability> aList = aFeat.getVirtualFeatList(); @@ -17027,27 +16954,38 @@ { return getVirtualFeatList(); } - List<Ability> ret = theAbilities.get(aCategory, Ability.Nature.VIRTUAL); - if (ret == null) + List<Ability> abilities = + theAbilities.get(aCategory, Ability.Nature.VIRTUAL); + if (abilities == null) { - ret = Collections.emptyList(); + abilities = new ArrayList<Ability>(); + theAbilities.put(aCategory, Ability.Nature.VIRTUAL, abilities); + + for (final PObject pobj : getPObjectList()) + { + final List<String> abilityKeys = + pobj.getAbilityKeys(this, aCategory, + Ability.Nature.VIRTUAL); + for (final String key : abilityKeys) + { + final Ability added = + AbilityUtilities + .addCloneOfGlobalAbilityToListWithChoices( + abilities, aCategory, key); + if (added != null) + { + added.setFeatType(Ability.Nature.VIRTUAL); + } + } + } } - return Collections.unmodifiableList(ret); + return Collections.unmodifiableList(abilities); } public List<Ability> featAutoList() { - if (stableAutomaticFeatList == null) - { - stableAutomaticFeatList = rebuildAutoFeatList(); - setAutomaticFeatsStable(true); - } - if (stableAutomaticFeatList == null) - { - return Collections.emptyList(); - } - return stableAutomaticFeatList; + return getAutomaticAbilityList(AbilityCategory.FEAT); } /** @@ -17064,11 +17002,6 @@ */ public List<Ability> getAutomaticAbilityList(final AbilityCategory aCategory) { - if (aCategory == AbilityCategory.FEAT) - { - return featAutoList(); - } - List<Ability> abilities = theAbilities.get(aCategory, Ability.Nature.AUTOMATIC); if (abilities == null) @@ -17091,136 +17024,11 @@ } } } - // - // add racial feats - // - // if ((getRace() != null) && - // !PlayerCharacterUtilities.canReassignRacialFeats()) - // { - // final List<String> abilityKeys = - // getRace().getAutoAbilityList(aCategory); - // for ( final String key : abilityKeys ) - // { - // final Ability added = - // AbilityUtilities.addCloneOfGlobalAbilityToListWithChoices(abilities, - // aCategory, key); - // added.setFeatType(Ability.Nature.AUTOMATIC); - // } - // } - // - // for (final PCClass aClass : getClassList()) - // { - // final Collection<String> abilityKeys = - // aClass.getAutoAbilityList(aCategory); - // for ( String key : abilityKeys ) - // { - // final int idx = key.indexOf('['); - // - // if (idx >= 0) - // { - // final StringTokenizer bTok = new - // StringTokenizer(key.substring(idx + 1), "[]"); - // final List<Prerequisite> preReqList = new - // ArrayList<Prerequisite>(); - // - // while (bTok.hasMoreTokens()) - // { - // final String prereqString = bTok.nextToken(); - // Logging.debugPrint("Why is the prerequisite '"+prereqString+ - // "' parsed in PlayerCharacter.featAutoList() rather than the - // persistence layer"); - // try { - // final PreParserFactory factory = PreParserFactory.getInstance(); - // final Prerequisite prereq = factory.parse(prereqString); - // preReqList.add(prereq); - // } - // catch (PersistenceLayerException ple){ - // Logging.errorPrint(ple.getMessage(), ple); - // } - // } - // - // key = key.substring(0, idx); - // - // if (preReqList.size() != 0) - // { - // if (! PrereqHandler.passesAll(preReqList, this, null )) - // { - // continue; - // } - // } - // } - // - // final Ability added = - // AbilityUtilities.addCloneOfGlobalAbilityToListWithChoices(abilities, - // aCategory, key); - // added.setFeatType(Ability.Nature.AUTOMATIC); - // } - // } - // - // if (!PlayerCharacterUtilities.canReassignTemplateFeats() && - // !getTemplateList().isEmpty()) - // { - // for (final PCTemplate template : getTemplateList()) - // { - // final List<String> abilityKeys = - // template.getAutoAbilityKeys(aCategory, this, false); - // - // for ( final String key : abilityKeys ) - // { - // // TODO - Not sure if we need to tokenize on comma - // final Ability added = - // AbilityUtilities.addCloneOfGlobalAbilityToListWithChoices(abilities, - // aCategory, key); - // added.setFeatType(Ability.Nature.AUTOMATIC); - // } - // } - // } - // - // for (final CharacterDomain aCD : getCharacterDomainList()) - // { - // final Domain domain = aCD.getDomain(); - // - // if (domain != null) - // { - // for (int e2 = 0; e2 < domain.getAssociatedCount(); ++e2) - // { - // final String aString = domain.getAssociated(e2); - // - // // TODO - This is not working - // if (aString.startsWith("ABILITY")) - // { - // final int idx = aString.indexOf('?'); - // - // if (idx > -1) - // { - // final Ability added = - // AbilityUtilities.addCloneOfGlobalAbilityToListWithChoices(abilities, - // aCategory, aString.substring(idx + 1)); - // added.setFeatType(Ability.Nature.AUTOMATIC); - // } - // else - // { - // Logging.errorPrint("no '?' in Domain assocatedList entry: " + - // aString); - // } - // } - // } - // - // // TODO - Need to change Domain to take AbilityCategories - // final Iterator<Categorisable> anIt = - // domain.getAbilityIterator(aCategory.getAbilityCategory()); - // - // for (; anIt.hasNext();) - // { - // final Categorisable c = anIt.next(); - // final Ability added = - // AbilityUtilities.addCloneOfGlobalAbilityToListWithChoices(abilities, - // aCategory, c.getKeyName()); - // added.setFeatType(Ability.Nature.AUTOMATIC); - // } - // } - // } + if (aCategory == AbilityCategory.FEAT) + { + addNonAbilityAutoFeats(abilities); + } cachedWeaponProfs = null; } return abilities; @@ -17235,22 +17043,6 @@ return null; } - void setStableAutomaticFeatList(final List<Ability> aFeatList) - { - stableAutomaticFeatList = aFeatList; - cachedWeaponProfs = null; - // setAutomaticFeatsStable( aFeatList != null ); - } - - // private List<Ability> getStableAutomaticFeatList() - // { - // if (isAutomaticFeatsStable()) - // { - // return stableAutomaticFeatList; - // } - // return null; - // } - private void setStableVirtualFeatList(final List<Ability> aFeatList) { stableVirtualFeatList = aFeatList; @@ -17270,10 +17062,14 @@ return null; } - private List<Ability> rebuildAutoFeatList() + /** + * Add any automatic feats not stored as abilities to the + * supplied list. + * + * @param abilities The Ability list to be populated. + */ + private void addNonAbilityAutoFeats(List<Ability> abilities) { - stableAutomaticFeatList = new ArrayList<Ability>(); - // // add racial feats // @@ -17287,7 +17083,7 @@ { Ability added = AbilityUtilities .addCloneOfGlobalAbilityToListWithChoices( - stableAutomaticFeatList, Constants.FEAT_CATEGORY, aTok + abilities, Constants.FEAT_CATEGORY, aTok .nextToken()); if (added != null) { @@ -17296,7 +17092,7 @@ } addAutoProfsToList(getRace().getSafeListFor( - ListKey.SELECTED_WEAPON_PROF_BONUS), stableAutomaticFeatList); + ListKey.SELECTED_WEAPON_PROF_BONUS), abilities); } @@ -17354,7 +17150,7 @@ Ability added = AbilityUtilities .addCloneOfGlobalAbilityToListWithChoices( - stableAutomaticFeatList, Constants.FEAT_CATEGORY, + abilities, Constants.FEAT_CATEGORY, autoFeat); if (added != null) { @@ -17363,7 +17159,7 @@ } addAutoProfsToList(aClass .getSafeListFor(ListKey.SELECTED_WEAPON_PROF_BONUS), - stableAutomaticFeatList); + abilities); } if (!PlayerCharacterUtilities.canReassignTemplateFeats() @@ -17387,7 +17183,7 @@ { Ability added = AbilityUtilities .addCloneOfGlobalAbilityToListWithChoices( - stableAutomaticFeatList, + abilities, Constants.FEAT_CATEGORY, aTok.nextToken()); if (added != null) { @@ -17398,15 +17194,12 @@ } addAutoProfsToList(aTemplate .getSafeListFor(ListKey.SELECTED_WEAPON_PROF_BONUS), - stableAutomaticFeatList); + abilities); } } - /* - * BUG I think -> if it's empty, we step through it?!? - thpr 11/3/06 - */ - if (getCharacterDomainList().isEmpty()) + if (!getCharacterDomainList().isEmpty()) { for (final CharacterDomain aCD : getCharacterDomainList()) { @@ -17426,7 +17219,7 @@ { Ability added = AbilityUtilities .addCloneOfGlobalAbilityToListWithChoices( - stableAutomaticFeatList, + abilities, Constants.FEAT_CATEGORY, aString .substring(idx + 1)); if (added != null) @@ -17451,7 +17244,7 @@ final Ability abI = (Ability) anIt.next(); Ability added = AbilityUtilities .addCloneOfGlobalAbilityToListWithChoices( - stableAutomaticFeatList, + abilities, Constants.FEAT_CATEGORY, abI.getKeyName()); if (added != null) { @@ -17461,26 +17254,11 @@ addAutoProfsToList(aDomain .getSafeListFor(ListKey.SELECTED_WEAPON_PROF_BONUS), - stableAutomaticFeatList); + abilities); } } } - - // Grab any Abilities of category FEAT lurking in any PObjects - for (PObject pobj : getPObjectList()) - { - for (String key : pobj.getAbilityKeys(this, AbilityCategory.FEAT, Nature.AUTOMATIC)) - { - //Logging.errorPrint("Got ability key " + key + " from " + pobj + "."); - Ability added = - AbilityUtilities - .addCloneOfGlobalAbilityToListWithChoices( - stableAutomaticFeatList, - Constants.FEAT_CATEGORY, key); - } - } - return stableAutomaticFeatList; } /** Modified: Trunk/pcgen/code/src/java/pcgen/core/VariableProcessorPC.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/VariableProcessorPC.java 2007-03-19 01:02:35 UTC (rev 2525) +++ Trunk/pcgen/code/src/java/pcgen/core/VariableProcessorPC.java 2007-03-19 01:07:52 UTC (rev 2526) @@ -663,11 +663,11 @@ } else if ("COUNT[FEATS.HIDDEN]".equals(valString)) { - valString = Integer.toString(countVisibleFeats(getPc().getRealFeatList(), false, true)); + valString = Integer.toString(countVisibleFeats(getPc().getRealAbilitiesList(AbilityCategory.FEAT), false, true)); } else if ("COUNT[FEATS]".equals(valString) || "COUNT[FEATS.VISIBLE]".equals(valString)) { - valString = Integer.toString(countVisibleFeats(getPc().getRealFeatList(), true, false)); + valString = Integer.toString(countVisibleFeats(getPc().getRealAbilitiesList(AbilityCategory.FEAT), true, false)); } else if ("COUNT[VFEATS.ALL]".equals(valString)) { Modified: Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java 2007-03-19 01:02:35 UTC (rev 2525) +++ Trunk/pcgen/code/src/test/pcgen/core/PlayerCharacterTest.java 2007-03-19 01:07:52 UTC (rev 2526) @@ -863,7 +863,7 @@ GameMode gm = SettingsHandler.getGame(); AbilityCategory ac = gm.getAbilityCategory("FEAT"); - Logging.errorPrint("Real abilities: " + pc.getRealAbilityList(ac).size()); + Logging.errorPrint("Real abilities: " + pc.getRealAbilitiesList(ac).size()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-03-24 22:53:05
|
Revision: 2574 http://svn.sourceforge.net/pcgen/?rev=2574&view=rev Author: jdempsey Date: 2007-03-24 15:52:58 -0700 (Sat, 24 Mar 2007) Log Message: ----------- Strings of all spaces never output Issue#: 1684403 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java Modified: Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java 2007-03-24 11:40:26 UTC (rev 2573) +++ Trunk/pcgen/code/src/java/pcgen/io/ExportHandler.java 2007-03-24 22:52:58 UTC (rev 2574) @@ -2531,8 +2531,12 @@ if (manualWhitespace) { aString = aString.replaceAll("[ \\t]", ""); + if (len > 0) + { + FileAccess.write(output, aString); + } } - if (len > 0) + else { FileAccess.write(output, aString); } Modified: Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java 2007-03-24 11:40:26 UTC (rev 2573) +++ Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java 2007-03-24 22:52:58 UTC (rev 2574) @@ -265,6 +265,17 @@ // "|OIF(max(0,2)==2)|\ntrue\n|ELSE|\nfalse\n|ENDIF|", character)); } + public void testFor() throws IOException + { + PlayerCharacter pc = getCharacter(); + assertEquals("Test for evaluates correctly", "----------------", + evaluateToken( + "FOR.1,((24-STRLEN[SKILL.0])).INTVAL,24,-,NONE,NONE,1", pc)); + assertEquals("Test for evaluates correctly", " ", + evaluateToken( + "FOR.1,((24-STRLEN[SKILL.0])).INTVAL,24, ,NONE,NONE,1", pc)); + } + public void testExpressionOutput() throws IOException { Ability dummyFeat = new Ability(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-03-29 22:27:19
|
Revision: 2611 http://svn.sourceforge.net/pcgen/?rev=2611&view=rev Author: jdempsey Date: 2007-03-29 15:27:19 -0700 (Thu, 29 Mar 2007) Log Message: ----------- Freq: ATTACK token enhancement Issue#: 1353596 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/io/exporttoken/AttackToken.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java Modified: Trunk/pcgen/code/src/java/pcgen/io/exporttoken/AttackToken.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/io/exporttoken/AttackToken.java 2007-03-29 11:51:18 UTC (rev 2610) +++ Trunk/pcgen/code/src/java/pcgen/io/exporttoken/AttackToken.java 2007-03-29 22:27:19 UTC (rev 2611) @@ -86,18 +86,20 @@ if (aTok.hasMoreTokens()) { String attackType = aTok.nextToken(); - String modifier = ""; + String modifier = aTok.hasMoreTokens() ? aTok.nextToken() : ""; + String format = aTok.hasMoreTokens() ? aTok.nextToken() : ""; - try + retString = getParsedToken(pc, attackType, modifier); + + // SHORT means we only return the first attack bonus + if ("SHORT".equalsIgnoreCase(format)) { - modifier = aTok.nextToken(); + int sepPos = retString.indexOf("/"); + if (sepPos >= 0) + { + retString = retString.substring(0, sepPos); + } } - catch (Exception e) - { - //TODO: Should this really be ignored? - } - - retString = getParsedToken(pc, attackType, modifier); } return retString; Added: Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java 2007-03-29 22:27:19 UTC (rev 2611) @@ -0,0 +1,136 @@ +/* + * AttackTokenTest.java + * Copyright 2007 (C) James Dempsey <jde...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on Mar 30, 2007 + * + * $Id$ + * + */ +package plugin.exporttokens; + +import junit.framework.Test; +import junit.framework.TestSuite; +import pcgen.AbstractCharacterTestCase; +import pcgen.core.Equipment; +import pcgen.core.EquipmentList; +import pcgen.core.EquipmentModifier; +import pcgen.core.GameMode; +import pcgen.core.Globals; +import pcgen.core.PCClass; +import pcgen.core.PCStat; +import pcgen.core.PlayerCharacter; +import pcgen.core.SettingsHandler; +import pcgen.core.bonus.Bonus; +import pcgen.core.bonus.BonusObj; +import pcgen.core.character.EquipSet; +import pcgen.io.exporttoken.AttackToken; + +/** + * <code>ACTokenTest</code> tests the function of the AC token and + * thus the calculations of armor class. + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author James Dempsey <jde...@us...> + * @version $Revision$ + */ +public class AttackTokenTest extends AbstractCharacterTestCase +{ + PCClass myClass = new PCClass(); + + /** + * Quick test suite creation - adds all methods beginning with "test" + * @return The Test suite + */ + public static Test suite() + { + return new TestSuite(AttackTokenTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + PlayerCharacter character = getCharacter(); + setPCStat(character, "STR", 14); + PCStat stat = + character.getStatList().getStatAt( + SettingsHandler.getGame().getStatFromAbbrev("STR")); + stat.getBonusList().clear(); + stat.addBonusList("COMBAT|TOHIT.Melee|STR|TYPE=Ability"); +// // Ignoring max dex +// stat.addBonusList("COMBAT|AC|DEX|TYPE=Ability"); + + EquipSet def = new EquipSet("0.1", "Default"); + character.addEquipSet(def); + character.setCalcEquipmentList(); + + character.calcActiveBonuses(); + + myClass.setName("My Class"); + myClass.setAbbrev("Myc"); + myClass.setSkillPointFormula("3"); + final BonusObj babClassBonus = Bonus.newBonus("1|COMBAT|BAB|CL+5"); + myClass.addBonusList(babClassBonus); + Globals.getClassList().add(myClass); + + } + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception + { + super.tearDown(); + } + + /** + * Test the character's attack calcs with no bonus. + * @throws Exception + */ + public void testBase() throws Exception + { + assertEquals("Total melee attack no bonus", "+2", new AttackToken() + .getToken("ATTACK.MELEE.TOTAL", getCharacter(), null)); + + assertEquals("Total melee attack no bonus short", "+2", + new AttackToken().getToken("ATTACK.MELEE.TOTAL.SHORT", + getCharacter(), null)); + } + + /** + * Test the character's attack calcs with a bonus. + * @throws Exception + */ + public void testIterative() throws Exception + { + getCharacter().incrementClassLevel(1, myClass, true); + getCharacter().calcActiveBonuses(); + + assertEquals("Total melee attack no bonus", "+8/+3", new AttackToken() + .getToken("ATTACK.MELEE.TOTAL", getCharacter(), null)); + + assertEquals("Total melee attack no bonus short", "+8", + new AttackToken().getToken("ATTACK.MELEE.TOTAL.SHORT", + getCharacter(), null)); + } + +} \ No newline at end of file Property changes on: Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java ___________________________________________________________________ Name: svn:keywords + Author Revision Date Id Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-04-20 13:01:40
|
Revision: 2755 http://svn.sourceforge.net/pcgen/?rev=2755&view=rev Author: jdempsey Date: 2007-04-20 06:01:41 -0700 (Fri, 20 Apr 2007) Log Message: ----------- Fix bug: [ABILITY OBJECT] can't output bonus feats Issue#: 1702512 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/VariableProcessorPC.java Trunk/pcgen/code/src/java/pcgen/io/exporttoken/AbilityListToken.java Trunk/pcgen/code/src/java/plugin/exporttokens/AbilityAllToken.java Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java Property Changed: ---------------- Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-04-20 11:37:19 UTC (rev 2754) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-04-20 13:01:41 UTC (rev 2755) @@ -15979,7 +15979,31 @@ return new ArrayList<Ability>(abilities); } + /** + * Get a list of real abiltiies of a particualr AbilityCategory + * no matter which AbilityCategory list they reside in. + * + * @param aCategory The AbilityCategory of the desired abilities. + * @return List of abilities + */ + public List<Ability> getRealAbilitiesListAnyCat(final AbilityCategory aCategory) + { + List<Ability> abilities = new ArrayList<Ability>(); + for (AbilityCategory cat : SettingsHandler.getGame().getAllAbilityCategories()) + { + for (Ability ability : getRealAbilitiesList(cat)) + { + if (aCategory.getKeyName().equals(ability.getCategory())) + { + abilities.add(ability); + } + } + } + return abilities; + } + + /** * Get an iterator over all the feats "Real" feats For Example, not virtual * or auto * @@ -16813,28 +16837,16 @@ public List<Ability> aggregateVisibleFeatList() { - final List<Ability> tempFeatList = new ArrayList<Ability>(); - - for (Ability feat : aggregateFeatList()) - { - if ((feat.getVisibility() == Visibility.DEFAULT) - || (feat.getVisibility() == Visibility.OUTPUT_ONLY)) - { - tempFeatList.add(feat); - } - } - - return tempFeatList; + return getAggregateVisibleAbilityList(AbilityCategory.FEAT); } public List<Ability> getAggregateVisibleAbilityList( final AbilityCategory aCategory) { - if (aCategory == AbilityCategory.FEAT) - { - return aggregateVisibleFeatList(); - } - final List<Ability> abilities = getAggregateAbilityList(aCategory); + final List<Ability> abilities = new ArrayList<Ability>(); + abilities.addAll(getRealAbilitiesListAnyCat(AbilityCategory.FEAT)); + abilities.addAll(getAutomaticAbilityList(AbilityCategory.FEAT)); + abilities.addAll(getVirtualAbilityList(AbilityCategory.FEAT)); final List<Ability> ret = new ArrayList<Ability>(abilities.size()); for (final Ability ability : abilities) { Modified: Trunk/pcgen/code/src/java/pcgen/core/VariableProcessorPC.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/VariableProcessorPC.java 2007-04-20 11:37:19 UTC (rev 2754) +++ Trunk/pcgen/code/src/java/pcgen/core/VariableProcessorPC.java 2007-04-20 13:01:41 UTC (rev 2755) @@ -659,15 +659,15 @@ } else if ("COUNT[FEATS.ALL]".equals(valString)) { - valString = Integer.toString(getPc().getNumberOfRealAbilities(AbilityCategory.FEAT)); + valString = Integer.toString(getPc().getRealAbilitiesListAnyCat(AbilityCategory.FEAT).size()); } else if ("COUNT[FEATS.HIDDEN]".equals(valString)) { - valString = Integer.toString(countVisibleFeats(getPc().getRealAbilitiesList(AbilityCategory.FEAT), false, true)); + valString = Integer.toString(countVisibleFeats(getPc().getRealAbilitiesListAnyCat(AbilityCategory.FEAT), false, true)); } else if ("COUNT[FEATS]".equals(valString) || "COUNT[FEATS.VISIBLE]".equals(valString)) { - valString = Integer.toString(countVisibleFeats(getPc().getRealAbilitiesList(AbilityCategory.FEAT), true, false)); + valString = Integer.toString(countVisibleFeats(getPc().getRealAbilitiesListAnyCat(AbilityCategory.FEAT), true, false)); } else if ("COUNT[VFEATS.ALL]".equals(valString)) { Modified: Trunk/pcgen/code/src/java/pcgen/io/exporttoken/AbilityListToken.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/io/exporttoken/AbilityListToken.java 2007-04-20 11:37:19 UTC (rev 2754) +++ Trunk/pcgen/code/src/java/pcgen/io/exporttoken/AbilityListToken.java 2007-04-20 13:01:41 UTC (rev 2755) @@ -167,7 +167,7 @@ AbilityCategory aCategory) { List<Ability> listOfAbilities = new ArrayList<Ability>(); - for (Ability ability : pc.getRealAbilityList(aCategory)) + for (Ability ability : pc.getRealAbilitiesListAnyCat(aCategory)) { listOfAbilities.add(ability); } Modified: Trunk/pcgen/code/src/java/plugin/exporttokens/AbilityAllToken.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/exporttokens/AbilityAllToken.java 2007-04-20 11:37:19 UTC (rev 2754) +++ Trunk/pcgen/code/src/java/plugin/exporttokens/AbilityAllToken.java 2007-04-20 13:01:41 UTC (rev 2755) @@ -71,7 +71,7 @@ final AbilityCategory aCategory) { List<Ability> ret = new ArrayList<Ability>(); - ret.addAll(pc.getRealAbilityList(aCategory)); + ret.addAll(pc.getRealAbilitiesListAnyCat(aCategory)); ret.addAll(pc.getAutomaticAbilityList(aCategory)); ret.addAll(pc.getVirtualAbilityList(aCategory)); return ret; Modified: Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java 2007-04-20 11:37:19 UTC (rev 2754) +++ Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java 2007-04-20 13:01:41 UTC (rev 2755) @@ -18,7 +18,7 @@ * * Created on 23/11/2006 * - * $Id: $ + * $Id$ */ package plugin.jepcommands; @@ -45,11 +45,11 @@ * The first parameter will be the type of object being counted * and further parameters will specify the criteria. * - * Last Editor: $Author: $ - * Last Edited: $Date: $ + * Last Editor: $Author$ + * Last Edited: $Date$ * * @author James Dempsey <jde...@us...> - * @version $Revision: $ + * @version $Revision$ */ public class CountCommand extends PCGenCommand { Property changes on: Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java ___________________________________________________________________ Name: keywords - Author Revision Date Id Name: svn:keywords + Author Revision Date Id Modified: Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java 2007-04-20 11:37:19 UTC (rev 2754) +++ Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java 2007-04-20 13:01:41 UTC (rev 2755) @@ -67,20 +67,24 @@ PlayerCharacter character = getCharacter(); // Make some ability categories and add them to the game mode - AbilityCategory featCategory = - SettingsHandler.getGame().getAbilityCategory("Feat"); - + AbilityCategory featCategory = + SettingsHandler.getGame().getAbilityCategory("FEAT"); if (featCategory == null) { - featCategory = new AbilityCategory("Feat"); + featCategory = new AbilityCategory("FEAT"); SettingsHandler.getGame().addAbilityCategory(featCategory); } - AbilityCategory bardCategory = new AbilityCategory("BARDIC"); - SettingsHandler.getGame().addAbilityCategory(bardCategory); + AbilityCategory bardCategory = + SettingsHandler.getGame().getAbilityCategory("BARDIC"); + if (bardCategory == null) + { + bardCategory = new AbilityCategory("BARDIC"); + SettingsHandler.getGame().addAbilityCategory(bardCategory); + } Ability ab1 = - TestHelper.makeAbility("Perform (Dance)", "Feat", + TestHelper.makeAbility("Perform (Dance)", "FEAT", "General.Fighter"); ab1.setMultiples("NO"); ab1.setVisibility(Visibility.DEFAULT); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <van...@us...> - 2007-05-04 09:01:17
|
Revision: 2837 http://svn.sourceforge.net/pcgen/?rev=2837&view=rev Author: vandaelek Date: 2007-05-04 02:01:16 -0700 (Fri, 04 May 2007) Log Message: ----------- Fix bug: [1699779] PREWEAPONPROF fails with simple proficiencies Issue#: 1699779 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreWeaponProfTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-05-04 04:52:42 UTC (rev 2836) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-05-04 09:01:16 UTC (rev 2837) @@ -4194,20 +4194,16 @@ */ public boolean hasWeaponProfKeyed(final String aKey) { - // for ( WeaponProf wp : getWeaponProfList() ) - // { - // if (aKey.equalsIgnoreCase(wp.getKeyName())) - // { - // return true; - // } - // } - // - // return false; if (cachedWeaponProfs == null) { cachedWeaponProfs = buildWeaponProfCache(); } - return cachedWeaponProfs.get(aKey) != null; + for (WeaponProf wp : cachedWeaponProfs.values() ) { + if (wp != null && wp.getKeyName().equalsIgnoreCase(aKey) ) { + return true; + } + } + return false; } public boolean hasWeaponProf(final WeaponProf wp) Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreWeaponProfTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreWeaponProfTest.java 2007-05-04 04:52:42 UTC (rev 2836) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreWeaponProfTest.java 2007-05-04 09:01:16 UTC (rev 2837) @@ -250,11 +250,12 @@ * This test was written to help find the source of bug 1699779 * @throws Exception */ - /* public void testWithFeatThatGrantsBonus() throws Exception { final PlayerCharacter character = getCharacter(); + final FeatLoader featLoader = new FeatLoader(); + CampaignSourceEntry cse; try { @@ -266,13 +267,6 @@ throw new UnreachableError(e); } - Ability foo = new Ability(); - final String fooStr = - "Foo TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50|PREWEAPONPROF:1,Longsword"; - final FeatLoader featLoader = new FeatLoader(); - featLoader.parseLine(foo, fooStr, cse); - character.addFeat(foo, null); - int baseHp = character.hitPoints(); Ability bar = new Ability(); @@ -286,20 +280,20 @@ character.hitPoints() ); - assertEquals("Character doesn't have the longsword proficiency.", - baseHp+50, - character.hitPoints() - ); - character.addWeaponProf("Longsword"); + Ability foo = new Ability(); + final String fooStr = + "Foo TYPE:General DESC:See Text BONUS:HP|CURRENTMAX|50|PREWEAPONPROF:1,Longsword"; + featLoader.parseLine(foo, fooStr, cse); + character.addFeat(foo, null); + assertEquals("Character has the longsword proficiency so the bonus should be added", baseHp+50+50, character.hitPoints() ); } - */ /* (non-Javadoc) * @see pcgen.AbstractCharacterTestCase#setUp() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-05-26 03:33:27
|
Revision: 3015 http://svn.sourceforge.net/pcgen/?rev=3015&view=rev Author: jdempsey Date: 2007-05-25 20:33:27 -0700 (Fri, 25 May 2007) Log Message: ----------- Fix bug: Characters saved in 5.12 RC1 Cannot be Loaded Issue#: 1725968 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java Trunk/pcgen/code/src/test/pcgen/io/PCGVer2ParserTest.java Modified: Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java 2007-05-26 01:24:06 UTC (rev 3014) +++ Trunk/pcgen/code/src/java/pcgen/io/PCGVer2Parser.java 2007-05-26 03:33:27 UTC (rev 3015) @@ -4052,9 +4052,16 @@ } catch (NumberFormatException e) { - // Something in the first 3 digits was not an integer - throw new PCGParseException( - "parseVersionLine", line, "Invalid PCGen version."); //$NON-NLS-1$ + if (idx == 2 && (tokens[idx].startsWith("RC"))) + { + pcgenVersionSuffix = tokens[2]; + } + else + { + // Something in the first 3 digits was not an integer + throw new PCGParseException( + "parseVersionLine", line, "Invalid PCGen version."); //$NON-NLS-1$ + } } } if (tokens.length == 4) Modified: Trunk/pcgen/code/src/test/pcgen/io/PCGVer2ParserTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/io/PCGVer2ParserTest.java 2007-05-26 01:24:06 UTC (rev 3014) +++ Trunk/pcgen/code/src/test/pcgen/io/PCGVer2ParserTest.java 2007-05-26 03:33:27 UTC (rev 3015) @@ -20,6 +20,7 @@ */ package pcgen.io; +import pcgen.gui.PCGenProp; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -155,4 +156,41 @@ assertEquals("Invalid PCGen version.", e.getMessage()); } } + + /** + * Test parsing of version line for broken 5.12RC1 version number. + * @throws PCGParseException + */ + public void test_1045596_8() throws PCGParseException + { + PCGVer2Parser parser = new PCGVer2Parser(null); + + parser.parseVersionLine("VERSION:5.12 RC1"); + + int[] version = parser.getPcgenVersion(); + String suffix = parser.getPcgenVersionSuffix(); + + assertEquals(3, version.length); + assertEquals(5, version[0]); + assertEquals(12, version[1]); + assertEquals(0, version[2]); + assertEquals("RC1", suffix); + } + + + /** + * Test that the currently specified version can be parsed. + * @throws PCGParseException + */ + public void testCurrVersion() throws PCGParseException + { + PCGVer2Parser parser = new PCGVer2Parser(null); + + parser.parseVersionLine("VERSION:" + PCGenProp.getVersionNumber()); + + int[] version = parser.getPcgenVersion(); + String suffix = parser.getPcgenVersionSuffix(); + + assertEquals(3, version.length); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <th...@us...> - 2007-05-29 00:29:09
|
Revision: 3075 http://svn.sourceforge.net/pcgen/?rev=3075&view=rev Author: thpr Date: 2007-05-28 17:29:06 -0700 (Mon, 28 May 2007) Log Message: ----------- Correct PRECLASS:x,ANY=y behavior to match SPELLCASTER, et al in PRECLASS (y is the level count requried in a single class) Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java 2007-05-29 00:28:40 UTC (rev 3074) +++ Trunk/pcgen/code/src/java/plugin/pretokens/test/PreClassTester.java 2007-05-29 00:29:06 UTC (rev 3075) @@ -68,7 +68,7 @@ { for (PCClass cl : character.getClassList()) { - runningTotal += cl.getLevel(); + runningTotal = Math.max(runningTotal, cl.getLevel()); } } else Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java 2007-05-29 00:28:40 UTC (rev 3074) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreClassTest.java 2007-05-29 00:29:06 UTC (rev 3075) @@ -35,6 +35,7 @@ import pcgen.AbstractCharacterTestCase; import pcgen.core.PCClass; import pcgen.core.PlayerCharacter; +import pcgen.persistence.lst.prereq.PreParserFactory; import plugin.pretokens.parser.PreClassLevelMaxParser; import plugin.pretokens.test.PreClassTester; @@ -184,6 +185,84 @@ } /** + * Test to ensure that a character will fail a test + * if it does not have the correct number of levels + * in the class. + * @throws Exception + */ + public void testFromParserCharWithMultipleSpellClasses() throws Exception + { + final PCClass pcClass = new PCClass(); + pcClass.setName("MyClass"); + pcClass.setAbbrev("My"); + pcClass.setSpellBaseStat("CHA"); + pcClass.setSpellType("ARCANE"); + pcClass.setCast(1, Arrays.asList("5,4".split(","))); + + final PCClass pcClass2 = new PCClass(); + pcClass2.setName("Other Class"); + pcClass2.setAbbrev("OC"); + pcClass.setSpellBaseStat("INT"); + pcClass2.setSpellType("ARCANE"); + pcClass2.setCast(1, Arrays.asList("5,4".split(","))); + + final PlayerCharacter character = getCharacter(); + character.incrementClassLevel(1, pcClass); + character.incrementClassLevel(2, pcClass2); + + final PreParserFactory factory = PreParserFactory.getInstance(); + + final Prerequisite prereq = factory.parse("PRECLASS:1,SPELLCASTER.ARCANE=3"); + + final PreClassTester test = new PreClassTester(); + int passes = test.passes(prereq, character); + // Doens't pass - levels not summed... + assertEquals(0, passes); + character.incrementClassLevel(1, pcClass2); + passes = test.passes(prereq, character); + assertEquals(1, passes); + } + + /** + * Test to ensure that a character will fail a test + * if it does not have the correct number of levels + * in the class. + * @throws Exception + */ + public void testFromParserAny() throws Exception + { + final PCClass pcClass = new PCClass(); + pcClass.setName("MyClass"); + pcClass.setAbbrev("My"); + pcClass.setSpellBaseStat("CHA"); + pcClass.setSpellType("ARCANE"); + pcClass.setCast(1, Arrays.asList("5,4".split(","))); + + final PCClass pcClass2 = new PCClass(); + pcClass2.setName("Other Class"); + pcClass2.setAbbrev("OC"); + pcClass.setSpellBaseStat("INT"); + pcClass2.setSpellType("ARCANE"); + pcClass2.setCast(1, Arrays.asList("5,4".split(","))); + + final PlayerCharacter character = getCharacter(); + character.incrementClassLevel(1, pcClass); + character.incrementClassLevel(2, pcClass2); + + final PreParserFactory factory = PreParserFactory.getInstance(); + + final Prerequisite prereq = factory.parse("PRECLASS:1,ANY=3"); + + final PreClassTester test = new PreClassTester(); + int passes = test.passes(prereq, character); + // Doens't pass - levels not summed... + assertEquals(0, passes); + character.incrementClassLevel(1, pcClass2); + passes = test.passes(prereq, character); + assertEquals(1, passes); + } + + /** * Test to ensure that a character without a named class cannot be found * @throws Exception */ @@ -482,13 +561,16 @@ final Prerequisite prereq = new Prerequisite(); prereq.setKind("class"); prereq.setKey("Any"); - prereq.setOperand("3"); + prereq.setOperand("2"); prereq.setOperator(PrerequisiteOperator.GTEQ); final PreClassTester test = new PreClassTester(); assertEquals(0, test.passes(prereq, character)); - character.incrementClassLevel(2, pcClass2); + character.incrementClassLevel(1, pcClass2); + assertEquals(0, test.passes(prereq, character)); + + character.incrementClassLevel(1, pcClass2); assertEquals(1, test.passes(prereq, character)); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jde...@us...> - 2007-06-29 09:33:25
|
Revision: 3238 http://svn.sourceforge.net/pcgen/?rev=3238&view=rev Author: jdempsey Date: 2007-06-29 02:33:26 -0700 (Fri, 29 Jun 2007) Log Message: ----------- Fix bug: Gap in Fantasy Combined OS - Merged from 5.12.x branch r3237 Issue#: 1740513 Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/exporttokens/ArmorToken.java Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java Modified: Trunk/pcgen/code/src/java/plugin/exporttokens/ArmorToken.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/exporttokens/ArmorToken.java 2007-06-29 09:30:24 UTC (rev 3237) +++ Trunk/pcgen/code/src/java/plugin/exporttokens/ArmorToken.java 2007-06-29 09:33:26 UTC (rev 3238) @@ -41,7 +41,7 @@ && ((tokenSource.charAt(5) == '.') || Character.isDigit(tokenSource .charAt(5)))) { - return getArmorToken(tokenSource, pc); + return getArmorToken(tokenSource, pc, eh); } return ""; } @@ -49,12 +49,13 @@ /** * @param tokenSource * @param pc + * @param eh The ExportHandler to advise if there are no more items. * @return token * */ - public static String getArmorToken(String tokenSource, PlayerCharacter pc) + public static String getArmorToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) { - return replaceTokenArmor(tokenSource, pc); + return replaceTokenArmor(tokenSource, pc, eh); } /** @@ -62,9 +63,10 @@ * * @param aString * @param aPC + * @param eh The ExportHandler to advise if there are no more items. * @return int */ - private static String replaceTokenArmor(String aString, PlayerCharacter aPC) + private static String replaceTokenArmor(String aString, PlayerCharacter aPC, ExportHandler eh) { final StringTokenizer aTok = new StringTokenizer(aString, "."); final String[] tokens = new String[aTok.countTokens()]; @@ -206,32 +208,32 @@ if ("".equals(type)) { - return _replaceTokenArmor(index, property, equipped, merge, aPC); + return _replaceTokenArmor(index, property, equipped, merge, aPC, eh); } else if ("SUIT".equals(type)) { return _replaceTokenArmorSuit(index, subtype, property, equipped, - merge, aPC); + merge, aPC, eh); } else if ("SHIRT".equals(type)) { return _replaceTokenArmorShirt(index, subtype, property, equipped, - merge, aPC); + merge, aPC, eh); } else if ("SHIELD".equals(type)) { return _replaceTokenArmorShield(index, subtype, property, equipped, - merge, aPC); + merge, aPC, eh); } else if ("ITEM".equals(type) || "ACITEM".equals(type)) { return _replaceTokenArmorItem(index, subtype, property, equipped, - merge, aPC); + merge, aPC, eh); } else { return _replaceTokenArmorVarious(index, type, subtype, property, - equipped, merge, aPC); + equipped, merge, aPC, eh); } } @@ -242,10 +244,11 @@ * @param equipped * @param merge * @param aPC + * @param eh The ExportHandler to advise if there are no more items. * @return int */ private static String _replaceTokenArmor(int armor, String property, - int equipped, int merge, PlayerCharacter aPC) + int equipped, int merge, PlayerCharacter aPC, ExportHandler eh) { final List<Equipment> aArrayList = aPC.getEquipmentOfTypeInOutputOrder("Armor", equipped, merge); @@ -262,7 +265,7 @@ final Equipment eq = aArrayList.get(armor); return _writeArmorProperty(eq, property, aPC); } - + eh.setNoMoreItems(true); return ""; } @@ -274,10 +277,11 @@ * @param equipped * @param merge * @param aPC + * @param eh The ExportHandler to advise if there are no more items. * @return int */ private static String _replaceTokenArmorItem(int item, String subtype, - String property, int equipped, int merge, PlayerCharacter aPC) + String property, int equipped, int merge, PlayerCharacter aPC, ExportHandler eh) { // select all pieces of equipment of status==equipped // filter all AC relevant stuff @@ -302,7 +306,7 @@ final Equipment eq = aArrayList.get(item); return _writeArmorProperty(eq, property, aPC); } - + eh.setNoMoreItems(true); return ""; } @@ -314,10 +318,11 @@ * @param equipped * @param merge * @param aPC + * @param eh The ExportHandler to advise if there are no more items. * @return int */ private static String _replaceTokenArmorShield(int shield, String subtype, - String property, int equipped, int merge, PlayerCharacter aPC) + String property, int equipped, int merge, PlayerCharacter aPC, ExportHandler eh) { final List<Equipment> aArrayList = aPC.getEquipmentOfTypeInOutputOrder("Shield", subtype, @@ -328,7 +333,7 @@ final Equipment eq = aArrayList.get(shield); return _writeArmorProperty(eq, property, aPC); } - + eh.setNoMoreItems(true); return ""; } @@ -340,10 +345,11 @@ * @param equipped * @param merge * @param aPC + * @param eh The ExportHandler to advise if there are no more items. * @return int */ private static String _replaceTokenArmorShirt(int shirt, String subtype, - String property, int equipped, int merge, PlayerCharacter aPC) + String property, int equipped, int merge, PlayerCharacter aPC, ExportHandler eh) { final List<Equipment> aArrayList = aPC.getEquipmentOfTypeInOutputOrder("Shirt", subtype, equipped, @@ -354,7 +360,7 @@ final Equipment eq = aArrayList.get(shirt); return _writeArmorProperty(eq, property, aPC); } - + eh.setNoMoreItems(true); return ""; } @@ -366,10 +372,11 @@ * @param equipped * @param merge * @param aPC + * @param eh The ExportHandler to advise if there are no more items. * @return int */ private static String _replaceTokenArmorSuit(int suit, String subtype, - String property, int equipped, int merge, PlayerCharacter aPC) + String property, int equipped, int merge, PlayerCharacter aPC, ExportHandler eh) { final List<Equipment> aArrayList = aPC.getEquipmentOfTypeInOutputOrder("Suit", subtype, equipped, @@ -385,7 +392,7 @@ final Equipment eq = aArrayList.get(suit); return _writeArmorProperty(eq, property, aPC); } - + eh.setNoMoreItems(true); return ""; } @@ -398,11 +405,12 @@ * @param equipped * @param merge * @param aPC + * @param eh The ExportHandler to advise if there are no more items. * @return int */ private static String _replaceTokenArmorVarious(int index, String type, String subtype, String property, int equipped, int merge, - PlayerCharacter aPC) + PlayerCharacter aPC, ExportHandler eh) { final List<Equipment> aArrayList = new ArrayList<Equipment>(); @@ -424,7 +432,7 @@ final Equipment eq = aArrayList.get(index); return _writeArmorProperty(eq, property, aPC); } - + eh.setNoMoreItems(true); return ""; } Modified: Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java 2007-06-29 09:30:24 UTC (rev 3237) +++ Trunk/pcgen/code/src/test/pcgen/io/ExportHandlerTest.java 2007-06-29 09:33:26 UTC (rev 3238) @@ -61,6 +61,7 @@ private Skill tumble = null; private Equipment weapon = null; private Equipment gem = null; + private Equipment armor = null; /** * Quick test suite creation - adds all methods beginning with "test" @@ -166,6 +167,11 @@ gem.setName("TestGem"); gem.setTypeInfo("gem"); gem.setQty(1); + + armor = new Equipment(); + armor.setName("TestArmorSuit"); + armor.setTypeInfo("armor.suit"); + } /** @@ -276,6 +282,23 @@ "FOR.1,((24-STRLEN[SKILL.0])).INTVAL,24, ,NONE,NONE,1", pc)); } + public void testForNoMoreItems() throws IOException + { + PlayerCharacter pc = getCharacter(); + assertEquals("Test for evaluates correctly", "SF", + evaluateToken( + "FOR.0,100,1,\\ARMOR.SUIT.ALL.%.NAME\\,S,F,1", pc)); + + // Now assign a gem + pc.addEquipment(armor); + EquipSet es = new EquipSet("1", "Default", "", armor); + pc.addEquipSet(es); + assertEquals("Test for evaluates correctly", "STestArmorSuitFSF", + evaluateToken( + "FOR.0,100,1,\\ARMOR.SUIT.ALL.%.NAME\\,S,F,1", pc)); + + } + public void testExpressionOutput() throws IOException { Ability dummyFeat = new Ability(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <za...@us...> - 2007-09-20 09:12:34
|
Revision: 4113 http://pcgen.svn.sourceforge.net/pcgen/?rev=4113&view=rev Author: zaister Date: 2007-09-20 02:12:31 -0700 (Thu, 20 Sep 2007) Log Message: ----------- Removed some unused imports Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PCSpell.java Trunk/pcgen/code/src/java/pcgen/core/chooser/ProficiencyChoiceManager.java Trunk/pcgen/code/src/java/pcgen/core/kit/KitSpells.java Trunk/pcgen/code/src/java/pcgen/core/npcgen/TreasureGenerator.java Trunk/pcgen/code/src/java/pcgen/gui/MainDebug.java Trunk/pcgen/code/src/java/pcgen/gui/editor/DeityBasePanel.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoAbilities.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoKnownSpells.java Trunk/pcgen/code/src/java/pcgen/io/filters/CharacterFilter.java Trunk/pcgen/code/src/java/pcgen/persistence/lst/BonusSpellLoader.java Trunk/pcgen/code/src/java/pcgen/persistence/lst/CampaignLoader.java Trunk/pcgen/code/src/java/pcgen/util/chooser/ChooserFactory.java Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreAgeSetParser.java Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityAbilityTest.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreAbilityTest.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreWeaponProfTest.java Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/BioSetLoaderTest.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreAbilityParserTest.java Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PCSpell.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PCSpell.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/core/PCSpell.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -1,13 +1,7 @@ package pcgen.core; -import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteUtilities; -import pcgen.persistence.PersistenceLayerException; -import pcgen.persistence.lst.output.prereq.PrerequisiteWriter; -import pcgen.util.Logging; -import java.io.StringWriter; -import java.util.Iterator; import java.util.List; /** Modified: Trunk/pcgen/code/src/java/pcgen/core/chooser/ProficiencyChoiceManager.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/chooser/ProficiencyChoiceManager.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/core/chooser/ProficiencyChoiceManager.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -32,7 +32,6 @@ import pcgen.core.PObject; import pcgen.core.PlayerCharacter; import pcgen.core.WeaponProf; -import pcgen.core.utils.ListKey; import pcgen.util.Logging; import java.util.ArrayList; Modified: Trunk/pcgen/code/src/java/pcgen/core/kit/KitSpells.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/kit/KitSpells.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/core/kit/KitSpells.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -37,7 +37,6 @@ import pcgen.core.PObject; import pcgen.core.PlayerCharacter; import pcgen.core.character.CharacterSpell; -import pcgen.core.character.SpellBook; import pcgen.core.spell.Spell; import pcgen.gui.CharacterInfo; import pcgen.gui.PCGen_Frame1; Modified: Trunk/pcgen/code/src/java/pcgen/core/npcgen/TreasureGenerator.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/npcgen/TreasureGenerator.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/core/npcgen/TreasureGenerator.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -7,7 +7,6 @@ import java.util.List; import pcgen.core.GameMode; -import pcgen.core.Globals; import pcgen.core.SettingsHandler; import pcgen.util.Logging; Modified: Trunk/pcgen/code/src/java/pcgen/gui/MainDebug.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/MainDebug.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/gui/MainDebug.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -30,13 +30,11 @@ import java.io.File; import java.io.OutputStream; import java.io.PrintStream; -import java.util.Arrays; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; -import java.util.logging.Logger; import javax.swing.JButton; import javax.swing.JLabel; Modified: Trunk/pcgen/code/src/java/pcgen/gui/editor/DeityBasePanel.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/editor/DeityBasePanel.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/gui/editor/DeityBasePanel.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -37,7 +37,6 @@ import javax.swing.JPanel; import javax.swing.JTextField; -import pcgen.core.Constants; import pcgen.core.Deity; import pcgen.core.Description; import pcgen.core.Globals; Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoAbilities.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoAbilities.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoAbilities.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -30,7 +30,6 @@ import pcgen.core.AbilityCategory; import pcgen.core.PlayerCharacter; import pcgen.core.SettingsHandler; -import pcgen.util.Logging; import pcgen.util.enumeration.Tab; /** Modified: Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoKnownSpells.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoKnownSpells.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/gui/tabs/spells/InfoKnownSpells.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -38,7 +38,6 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileOutputStream; -import java.io.IOException; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.List; Modified: Trunk/pcgen/code/src/java/pcgen/io/filters/CharacterFilter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/io/filters/CharacterFilter.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/io/filters/CharacterFilter.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -1,6 +1,5 @@ package pcgen.io.filters; -import pcgen.core.Globals; import pcgen.core.Constants; import pcgen.core.SettingsHandler; import pcgen.core.utils.CoreUtility; Modified: Trunk/pcgen/code/src/java/pcgen/persistence/lst/BonusSpellLoader.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/persistence/lst/BonusSpellLoader.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/persistence/lst/BonusSpellLoader.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -27,7 +27,6 @@ import pcgen.util.Logging; import java.net.URI; -import java.net.URL; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; Modified: Trunk/pcgen/code/src/java/pcgen/persistence/lst/CampaignLoader.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/persistence/lst/CampaignLoader.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/persistence/lst/CampaignLoader.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -25,7 +25,6 @@ */ package pcgen.persistence.lst; -import java.io.File; import java.net.URI; import java.util.ArrayList; import java.util.List; Modified: Trunk/pcgen/code/src/java/pcgen/util/chooser/ChooserFactory.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/util/chooser/ChooserFactory.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/pcgen/util/chooser/ChooserFactory.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -19,8 +19,6 @@ */ package pcgen.util.chooser; -import pcgen.core.chooser.ChooserUtilities; - /** * This factory class returns a Chooser of the appropriate type. This is intended * to reduce the core/gui interdependence. Much more work is needed on this... Modified: Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreAgeSetParser.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreAgeSetParser.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreAgeSetParser.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -24,7 +24,6 @@ */ package plugin.pretokens.parser; -import pcgen.core.Globals; import pcgen.core.prereq.Prerequisite; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.prereq.AbstractPrerequisiteListParser; Modified: Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityAbilityTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityAbilityTest.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/test/pcgen/core/levelability/LevelAbilityAbilityTest.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -30,16 +30,13 @@ import pcgen.AbstractCharacterTestCase; import pcgen.core.Ability; import pcgen.core.AbilityCategory; -import pcgen.core.Globals; import pcgen.core.PCClass; import pcgen.core.PlayerCharacter; import pcgen.core.Race; -import pcgen.core.Skill; import pcgen.gui.utils.SwingChooser; import pcgen.util.Logging; import pcgen.util.TestHelper; import pcgen.util.chooser.ChooserFactory; -import pcgen.util.chooser.ChooserInterface; import plugin.lsttokens.AddLst; /** Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreAbilityTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreAbilityTest.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreAbilityTest.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -27,7 +27,6 @@ import junit.framework.TestSuite; import pcgen.AbstractCharacterTestCase; import pcgen.core.Ability; -import pcgen.core.AbilityCategory; import pcgen.core.PlayerCharacter; import pcgen.core.prereq.Prerequisite; import pcgen.persistence.PersistenceLayerException; Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreWeaponProfTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreWeaponProfTest.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreWeaponProfTest.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -32,7 +32,6 @@ import pcgen.core.Ability; import pcgen.core.AbilityUtilities; import pcgen.core.Campaign; -import pcgen.core.Equipment; import pcgen.core.Globals; import pcgen.core.PlayerCharacter; import pcgen.core.WeaponProf; Modified: Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -32,7 +32,6 @@ import pcgen.core.PlayerCharacter; import pcgen.core.SettingsHandler; import pcgen.io.ExportHandler; -import pcgen.util.Logging; import pcgen.util.TestHelper; import pcgen.util.enumeration.Visibility; Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/BioSetLoaderTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/BioSetLoaderTest.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/BioSetLoaderTest.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -28,7 +28,6 @@ */ package pcgen.persistence.lst; -import java.io.File; import java.net.URI; import java.util.List; import junit.framework.Test; Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreAbilityParserTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreAbilityParserTest.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/prereq/PreAbilityParserTest.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -33,7 +33,6 @@ import pcgen.core.SettingsHandler; import pcgen.core.prereq.Prerequisite; import pcgen.persistence.PersistenceLayerException; -import pcgen.util.Logging; import plugin.pretokens.parser.PreAbilityParser; /** Modified: Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java 2007-09-20 02:53:33 UTC (rev 4112) +++ Trunk/pcgen/code/src/test/plugin/exporttokens/AttackTokenTest.java 2007-09-20 09:12:31 UTC (rev 4113) @@ -26,10 +26,6 @@ import junit.framework.Test; import junit.framework.TestSuite; import pcgen.AbstractCharacterTestCase; -import pcgen.core.Equipment; -import pcgen.core.EquipmentList; -import pcgen.core.EquipmentModifier; -import pcgen.core.GameMode; import pcgen.core.Globals; import pcgen.core.PCClass; import pcgen.core.PCStat; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <za...@us...> - 2007-10-20 18:05:12
|
Revision: 4380 http://pcgen.svn.sourceforge.net/pcgen/?rev=4380&view=rev Author: zaister Date: 2007-10-20 11:05:15 -0700 (Sat, 20 Oct 2007) Log Message: ----------- [ 953153 ] New PCGen icon! Issue#: 953153 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/gui/AddSpecialAbility.java Trunk/pcgen/code/src/java/pcgen/gui/ChooseSpellDialog.java Trunk/pcgen/code/src/java/pcgen/gui/EQFrame.java Trunk/pcgen/code/src/java/pcgen/gui/HPFrame.java Trunk/pcgen/code/src/java/pcgen/gui/KitSelector.java Trunk/pcgen/code/src/java/pcgen/gui/LstEditorMain.java Trunk/pcgen/code/src/java/pcgen/gui/NameGui.java Trunk/pcgen/code/src/java/pcgen/gui/NewWeaponInfoDialog.java Trunk/pcgen/code/src/java/pcgen/gui/PCCCreator.java Trunk/pcgen/code/src/java/pcgen/gui/PCGenPopup.java Trunk/pcgen/code/src/java/pcgen/gui/PCGen_Frame1.java Trunk/pcgen/code/src/java/pcgen/gui/pcGenGUI.java Added Paths: ----------- Trunk/pcgen/code/src/images/PCGenApp.png Added: Trunk/pcgen/code/src/images/PCGenApp.png =================================================================== (Binary files differ) Property changes on: Trunk/pcgen/code/src/images/PCGenApp.png ___________________________________________________________________ Name: svn:executable + * Name: svn:mime-type + application/octet-stream Modified: Trunk/pcgen/code/src/java/pcgen/gui/AddSpecialAbility.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/AddSpecialAbility.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/AddSpecialAbility.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -99,7 +99,7 @@ setTitle(myGetTitle()); Toolkit kit = Toolkit.getDefaultToolkit(); - Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_URL + "PcgenIcon.gif")); + Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_APP_ICON)); this.setIconImage(img); // since the Toolkit.getScreenSize() method is broken in the Linux implementation Modified: Trunk/pcgen/code/src/java/pcgen/gui/ChooseSpellDialog.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/ChooseSpellDialog.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/ChooseSpellDialog.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -97,7 +97,7 @@ ChooseSpellDialog(JFrame parent, PlayerCharacter pc, final int eqType, final boolean metaAllowed, final List<String> classList, final List<String> levelList, final int spellBooks, final String choiceString) { super(parent); - IconUtilitities.maybeSetIcon(parent, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(parent, IconUtilitities.RESOURCE_APP_ICON); this.eqType = eqType; this.pc = pc; this.metaAllowed = metaAllowed; @@ -113,7 +113,7 @@ ChooseSpellDialog(JFrame parent, PlayerCharacter pc, final int eqType, final boolean metaAllowed, final List<String> classList, final List<String> levelList, final int spellBooks) { super(parent); - IconUtilitities.maybeSetIcon(parent, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(parent, IconUtilitities.RESOURCE_APP_ICON); this.eqType = eqType; this.metaAllowed = metaAllowed; Modified: Trunk/pcgen/code/src/java/pcgen/gui/EQFrame.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/EQFrame.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/EQFrame.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -55,7 +55,7 @@ this.aPC = aPC; Toolkit kit = Toolkit.getDefaultToolkit(); - Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_URL + "PcgenIcon.gif")); + Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_APP_ICON)); this.setIconImage(img); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); Modified: Trunk/pcgen/code/src/java/pcgen/gui/HPFrame.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/HPFrame.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/HPFrame.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -49,7 +49,7 @@ setTitle(myGetTitle()); Toolkit kit = Toolkit.getDefaultToolkit(); - Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_URL + "PcgenIcon.gif")); + Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_APP_ICON)); this.setIconImage(img); // since the Toolkit.getScreenSize() method is broken in the Linux implementation Modified: Trunk/pcgen/code/src/java/pcgen/gui/KitSelector.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/KitSelector.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/KitSelector.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -241,7 +241,7 @@ private void initComponentContents() { - IconUtilitities.maybeSetIcon(this, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(this, IconUtilitities.RESOURCE_APP_ICON); lstAvailable = new JList(new KitListModel(new ArrayList<Kit>())); lstAvailable.setCellRenderer(new MyCellRenderer()); Modified: Trunk/pcgen/code/src/java/pcgen/gui/LstEditorMain.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/LstEditorMain.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/LstEditorMain.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -130,7 +130,7 @@ { initComponents(); - IconUtilitities.maybeSetIcon(this, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(this, IconUtilitities.RESOURCE_APP_ICON); pcgen.gui.utils.Utility.centerFrame(this, false); } Modified: Trunk/pcgen/code/src/java/pcgen/gui/NameGui.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/NameGui.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/NameGui.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -58,8 +58,7 @@ this.pc = pc; // according to the API, the following should *ALWAYS* use '/' - this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(IconUtilitities.RESOURCE_URL - + "PcgenIcon.gif"))); + this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource(IconUtilitities.RESOURCE_APP_ICON))); Utility.centerFrame(this, true); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Modified: Trunk/pcgen/code/src/java/pcgen/gui/NewWeaponInfoDialog.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/NewWeaponInfoDialog.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/NewWeaponInfoDialog.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -59,7 +59,7 @@ Toolkit kit = Toolkit.getDefaultToolkit(); // according to the API, the following should *ALWAYS* use '/' - Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_URL + "PcgenIcon.gif")); + Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_APP_ICON)); parent.setIconImage(img); initComponents(); setLocationRelativeTo(parent); // centre on parent (Canadian spelling eh?) Modified: Trunk/pcgen/code/src/java/pcgen/gui/PCCCreator.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/PCCCreator.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/PCCCreator.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -86,7 +86,7 @@ mSrc = ms; Toolkit kit = Toolkit.getDefaultToolkit(); - Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_URL + "PcgenIcon.gif")); + Image img = kit.getImage(getClass().getResource(IconUtilitities.RESOURCE_APP_ICON)); this.setIconImage(img); buildTree(); Modified: Trunk/pcgen/code/src/java/pcgen/gui/PCGenPopup.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/PCGenPopup.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/PCGenPopup.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -48,7 +48,7 @@ { super(title); - IconUtilitities.maybeSetIcon(this, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(this, IconUtilitities.RESOURCE_APP_ICON); Utility.centerFrame(this, true); } @@ -63,7 +63,7 @@ { super(title); - IconUtilitities.maybeSetIcon(this, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(this, IconUtilitities.RESOURCE_APP_ICON); Utility.centerFrame(this, true); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); setPanel(panel); Modified: Trunk/pcgen/code/src/java/pcgen/gui/PCGen_Frame1.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/PCGen_Frame1.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/PCGen_Frame1.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -2282,7 +2282,7 @@ */ private void jbInit() throws Exception { - IconUtilitities.maybeSetIcon(this, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(this, IconUtilitities.RESOURCE_APP_ICON); getContentPane().setLayout(new BorderLayout()); getContentPane().add(panelMain, BorderLayout.CENTER); Modified: Trunk/pcgen/code/src/java/pcgen/gui/pcGenGUI.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/gui/pcGenGUI.java 2007-10-20 13:09:33 UTC (rev 4379) +++ Trunk/pcgen/code/src/java/pcgen/gui/pcGenGUI.java 2007-10-20 18:05:15 UTC (rev 4380) @@ -601,7 +601,7 @@ aFrame.dispose(); } }); - IconUtilitities.maybeSetIcon(aFrame, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(aFrame, IconUtilitities.RESOURCE_APP_ICON); final JEditorPane a = new JEditorPane("text/html", text); a.setEditable(false); @@ -641,7 +641,7 @@ aFrame.dispose(); } }); - IconUtilitities.maybeSetIcon(aFrame, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(aFrame, IconUtilitities.RESOURCE_APP_ICON); StringBuffer sb = new StringBuffer(); sb.append("<html>"); @@ -690,7 +690,7 @@ if (imgIcon != null) { final JFrame aFrame = new JFrame("D20 Required Information"); - IconUtilitities.maybeSetIcon(aFrame, "PcgenIcon.gif"); + IconUtilitities.maybeSetIcon(aFrame, IconUtilitities.RESOURCE_APP_ICON); final JPanel jPanel1 = new JPanel(); final JPanel jPanel2 = new JPanel(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nu...@us...> - 2007-10-21 04:42:35
|
Revision: 4383 http://pcgen.svn.sourceforge.net/pcgen/?rev=4383&view=rev Author: nuance Date: 2007-10-20 21:42:29 -0700 (Sat, 20 Oct 2007) Log Message: ----------- Implemented more of the new jep count code. Can now specify more than one type e.g. count("ABILITIES","CATEGORY=FEAT[and]TYPE=General.Fighter") will count abilties which are category FEAT and both type General and type fighter. Can also leave out all parameters except "ABILITIES" to return a count of all of them. Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java Trunk/pcgen/code/src/test/pcgen/io/exporttoken/AbilityListTokenTest.java Modified: Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java 2007-10-21 03:24:16 UTC (rev 4382) +++ Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java 2007-10-21 04:42:29 UTC (rev 4383) @@ -23,481 +23,946 @@ package plugin.jepcommands; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.Stack; - import org.nfunk.jep.ParseException; - -import pcgen.core.Ability; -import pcgen.core.PlayerCharacter; -import pcgen.core.VariableProcessor; +import pcgen.core.*; +import pcgen.core.character.Follower; +import pcgen.core.spell.Spell; import pcgen.util.Logging; import pcgen.util.PCGenCommand; import pcgen.util.ParameterTree; import pcgen.util.enumeration.Visibility; +import java.text.MessageFormat; +import java.util.*; + /** * <code>CountCommand</code> deals with the count() JEP command. - * The first parameter will be the type of object being counted - * and further parameters will specify the criteria. - * + * The first parameter will be the type of object being counted + * and further parameters will specify the criteria. + * <p/> * Last Editor: $Author$ * Last Edited: $Date$ * * @author James Dempsey <jde...@us...> * @version $Revision$ */ -public class CountCommand extends PCGenCommand -{ +public class CountCommand extends PCGenCommand { - public enum JepAbilityCountEnum - { - CATEGORY, - NATURE, - TYPE, - VISIBILITY - } + public enum JepAbilityCountEnum { + CATEGORY, + NAME, + NATURE, + TYPE, + VISIBILITY, + CAT, + NAM, + NAT, + TYP, + VIS + } - public enum JepCountEnum - { - ABILITIES - { - public HashMap<Ability.Nature, Set<Ability>> abdata; + public enum JepEquipmentCountEnum { + TYPE, + WIELDCATEGORY, + LOCATION, + TYP, + WDC, + LOC + } - /** - * Count a character's abiltiies. - * - * @param pc The character being counted. - * @param params The parameters determining which abilities get counted. - * @return A Double with the number of matching abilities. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - if (params.length < 2) - { - throw new ParseException( - "Count of abilities had too few parameters."); - } + public enum JepCountEnum { + ABILITIES { + // Abilities are PObjects, we can implement the filterSet directly + // i.e. without using PObject proxies. - abdata = pc.getAbilitiesSet(); + public Map<Ability.Nature, Set<Ability>> abdata; - ParameterTree pt = null; + protected void getData(final PlayerCharacter pc) { + abdata = pc.getAbilitiesSet(); + } - for (int i = 1; i < params.length; i++) - { - try - { - if (pt == null) - { - pt = ParameterTree.makeTree((String) params[i]); - } - else - { - ParameterTree npt = new ParameterTree(ParameterTree.andString); - npt.setLeftTree(pt); - pt = npt; - npt = ParameterTree.makeTree((String) params[i]); - pt.setRightTree(npt); - } - } - catch (ParseException pe) - { - Logging.errorPrint("Malformed parameter to count(ABILITY) " + (String) params[i], pe); - } - } + public Object count(final PlayerCharacter pc, final Object[] params) throws ParseException { - Set<Ability> filtered = FilterAbilities(pt); - -// Logging.errorPrint("Number remaining: " + filtered.size()); - - double accum = 0; - - for (Ability ab: filtered) - { - double ac = ab.getAssociatedCount(); - accum += (ac <= 1.01) ? 1 : ab.getAssociatedCount(); - } - return Double.valueOf(accum); - } + final Object[] par = validateParams(params); - //@SuppressWarnings("unchecked") //Uses JEP, which doesn't use generics - public Set<Ability> FilterAbilities (ParameterTree pt) - { - String c = pt.getContents(); -// System.err.println(c); - - if (c.equalsIgnoreCase(ParameterTree.orString) || c.equalsIgnoreCase(ParameterTree.andString)) - { - Set<Ability> a = FilterAbilities(pt.getLeftTree()); - Set<Ability> b = FilterAbilities(pt.getRightTree()); - if (c.equalsIgnoreCase(ParameterTree.orString)) - { - a.addAll(b); - } - else - { - a.retainAll(b); - } - return a; - } - - String[] keyValue = c.split("="); + final ParameterTree pt = convertParams(par); - JepAbilityCountEnum en = JepAbilityCountEnum.valueOf(keyValue[0]); - Set<Ability> cs = null; - Ability a; + getData(pc); - switch (en) - { - case CATEGORY: - String cat = keyValue[1]; - cs = new HashSet<Ability>(abdata.get(Ability.Nature.ANY)); - - Iterator It = cs.iterator(); - - while (It.hasNext()) - { - a = (Ability) It.next(); - if (!a.getCategory().equalsIgnoreCase(cat)) - { - It.remove(); - } - } - break; - - case NATURE: ; - Ability.Nature n; - try - { - n = Ability.Nature.valueOf(keyValue[1]); - } - catch (IllegalArgumentException ex) - { - Logging.errorPrint("Bad paramter to count(\"Ability\"), no such NATURE " + c); - n = Ability.Nature.ANY; - } - cs = new HashSet<Ability>(abdata.get(n)); - break; + final Set<PObject> filtered = doFilterP(pt); - case TYPE: ; - String ty = keyValue[1]; - cs = new HashSet<Ability>(abdata.get(Ability.Nature.ANY)); + return countData(filtered); + } - It = cs.iterator(); + protected Object countData(final Iterable<PObject> filtered) { + double accum = 0; - while (It.hasNext()) - { - a = (Ability) It.next(); - if (!a.isType(ty)) - { - It.remove(); - } - } - break; + for (final PObject ab : filtered) { + final double ac = ab.getAssociatedCount(); + accum += 1.01 >= ac ? 1 : ab.getAssociatedCount(); + } + return accum; + } - case VISIBILITY : - Visibility vi; - cs = new HashSet<Ability>(abdata.get(Ability.Nature.ANY)); + protected Set<PObject> filterSetP(final String c) { + final String[] keyValue = c.split("="); + final JepAbilityCountEnum en; - try - { - vi = Visibility.valueOf(keyValue[1]); + try { + en = JepAbilityCountEnum.valueOf(keyValue[0]); + } + catch (IllegalArgumentException ex) { + Logging.errorPrint("Bad paramter to count(\"Ability\"), " + c); + return new HashSet<PObject>(); + } - It = cs.iterator(); - - while(It.hasNext()) - { - a = (Ability) It.next(); - if (!a.getVisibility().equals(vi)) - { - It.remove(); - } - } - } - catch (IllegalArgumentException ex) - { - Logging.errorPrint("Bad paramter to count(\"Ability\"), no such Visibility " + keyValue[1]); - } + Set<Ability> cs = null; + Ability a; + final Iterator<? extends PObject> abIt; + switch (en) { + case CATEGORY: + case CAT: + final String cat = keyValue[1]; + cs = new HashSet<Ability>(abdata.get(Ability.Nature.ANY)); - } + abIt = cs.iterator(); -// System.err.println("--- start ---"); -// System.err.println(keyValue[0]); -// System.err.println(keyValue[1]); -// -// for (Ability ab : cs) -// { -// System.err.println(ab); -// } -// -// System.err.println("--- end ---"); - return cs; - } + while (abIt.hasNext()) { + a = (Ability) abIt.next(); + if (!a.getCategory().equalsIgnoreCase(cat)) { + abIt.remove(); + } + } + break; - }, - CLASSES - { - /** - * Count a character's Classes. - * - * @param pc The character being counted. - * @param params The parameters determining which classes get counted. - * @return A Double with the number of matching classes. - * @throws ParseException If any invalid parameters are encountered. - */ + case NAME: + case NAM: + cs = new HashSet<Ability>(abdata.get(Ability.Nature.ANY)); + abIt = cs.iterator(); - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - DOMAINS - { - /** - * Count a character's Domains. - * - * @param pc The character being counted. - * @param params The parameters determining which domains get counted. - * @return A Double with the number of matching domains. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - EQUIPMENT - { - /** - * Count a character's Equipment. - * - * @param pc The character being counted. - * @param params The parameters determining which equipment gets counted. - * @return A Double with the number of matching pieces of equipment. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - FOLLOWERS - { - /** - * Count a character's Followers. - * - * @param pc The character being counted. - * @param params The parameters determining which followers get counted. - * @return A Double with the number of matching followers. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - LANGUAGES - { - /** - * Count a character's Languages. - * - * @param pc The character being counted. - * @param params The parameters determining which languages get counted. - * @return A Double with the number of matching languages. - * @throws ParseException If any invalid parameters are encountered. - */ + while (abIt.hasNext()) { + final PObject p = abIt.next(); + if (!p.getKeyName().equalsIgnoreCase(keyValue[1])) { + abIt.remove(); + } + } - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - RACESUBTYPES - { - /** - * Count a character's Race Subtypes. - * - * @param pc The character being counted. - * @param params The parameters determining which Race subtypes get counted. - * @return A Double with the number of matching Race subtypes. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - SKILLS - { - /** - * Count a character's Skills. - * - * @param pc The character being counted. - * @param params The parameters determining which skills get counted. - * @return A Double with the number of matching skills. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - SPELLBOOKS - { - /** - * Count a character's Spell Books. - * - * @param pc The character being counted. - * @param params The parameters determining which spell books get counted. - * @return A Double with the number of matching spell books. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - SPELLS - { - /** - * Count a character's Spells. - * - * @param pc The character being counted. - * @param params The parameters determining which spells get counted. - * @return A Double with the number of matching spells. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - SPELLSINBOOK - { - /** - * Count the spells character's Book. - * - * @param pc The character being counted. - * @param params The parameters determining which book get counted. - * @return A Double with the number of matching spells. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - SPELLSKNOWN - { - /** - * Count a character's known spells. - * - * @param pc The character being counted. - * @param params The parameters determining which spells get counted. - * @return A Double with the number of matching spells. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }, - TEMPLATES - { - /** - * Count a character's Templates. - * - * @param pc The character being counted. - * @param params The parameters determining which templates get counted. - * @return A Double with the number of matching templates. - * @throws ParseException If any invalid parameters are encountered. - */ - public Object count(PlayerCharacter pc, Object[] params) throws ParseException - { - return Double.valueOf("0.0"); - } - }; - - abstract public Object count(PlayerCharacter pc, Object[] params) throws ParseException; + break; - } + case NATURE: + case NAT: + Ability.Nature n; + try { + n = Ability.Nature.valueOf(keyValue[1]); + } + catch (IllegalArgumentException ex) { + Logging.errorPrint("Bad paramter to count(\"Ability\"), no such NATURE " + c); + n = Ability.Nature.ANY; + } + cs = new HashSet<Ability>(abdata.get(n)); + break; - /** - * Constructor - */ - public CountCommand() - { - numberOfParameters = -1; - } + case TYPE: + case TYP: + cs = new HashSet<Ability>(abdata.get(Ability.Nature.ANY)); + abIt = cs.iterator(); - /** - * @see pcgen.util.PCGenCommand#getFunctionName() - */ - @Override - public String getFunctionName() - { - return "COUNT"; - } + filterPObjectByType(abIt, keyValue[1]); + break; - /** - * Runs count on the inStack. The parameter is popped - * off the <code>inStack</code>, and the variable's value is - * pushed back to the top of <code>inStack</code>. - * @param inStack - * @throws ParseException - */ - @Override - @SuppressWarnings("unchecked") //Uses JEP, which doesn't use generics - public void run(Stack inStack) throws ParseException - { - // check the stack - checkStack(inStack); + case VISIBILITY: + case VIS: + cs = new HashSet<Ability>(abdata.get(Ability.Nature.ANY)); - // get the parameters from the stack - // - // have to do this in reverse order...this is a stack afterall - // - Object params[] = new Object[curNumberOfParameters]; - for (int i = curNumberOfParameters - 1; i >= 0; i--) - { - params[i] = inStack.pop(); - } + try { + final Visibility vi = Visibility.valueOf(keyValue[1]); + abIt = cs.iterator(); - if ((params[0] instanceof String)) - { - // Grab the character under scrutiny - PlayerCharacter pc = null; - if (parent instanceof VariableProcessor) - { - pc = ((VariableProcessor) parent).getPc(); - } - else if (parent instanceof PlayerCharacter) - { - pc = (PlayerCharacter) parent; - } - if (pc == null) - { - throw new ParseException("Invalid parent (no PC): " - + parent.getClass().getName()); - } + while (abIt.hasNext()) { + a = (Ability) abIt.next(); + if (!a.getVisibility().equals(vi)) { + abIt.remove(); + } + } + } + catch (IllegalArgumentException ex) { + Logging.errorPrint("Bad paramter to count(\"Ability\"), no such Visibility " + keyValue[1]); + } - // Count the requested object type. - JepCountEnum CountEnum = JepCountEnum.valueOf((String) params[0]); - - Double result = (Double) CountEnum.count(pc, params); - - inStack.push(result); + } + + final Set<PObject> pSet = new HashSet<PObject>(); + + for (final Ability ab : cs) { + pSet.add(ab); + } + + return pSet; + } + + protected Set<String> filterSetS(final String c) throws ParseException { + throw new ParseException("PCClass is a PObject, should be calling filterSetP"); + } + }, + + CLASSES { + // Classes are PObjects, we can implement the filterSet directly + // i.e. without using PObject proxies. + + public Set<PCClass> objdata; + + protected void getData(final PlayerCharacter pc) { + objdata = new HashSet<PCClass>(); + objdata.addAll(pc.getClassList()); + } + + public Object count(final PlayerCharacter pc, final Object[] params) throws ParseException { + final Object[] par = validateParams(params); + final ParameterTree pt = convertParams(par); + + getData(pc); + final Set<PObject> filtered = doFilterP(pt); + + return (double) filtered.size(); + } + + protected Set<String> filterSetS(final String c) throws ParseException { + throw new ParseException("PCClass is a PObject, should be calling filterSetP"); + } + + protected Set<PObject> filterSetP(final String c) throws ParseException { + final String[] keyValue = c.split("="); + + if (!"TYPE".equalsIgnoreCase(keyValue[0])) { + throw new ParseException( + "Bad parameter to count(\"CLASSES\" ... )" + c); + } + + final Set<PCClass> cs = new HashSet<PCClass>(objdata); + final Iterator<? extends PObject> It = cs.iterator(); + + filterPObjectByType(It, keyValue[1]); + + final Set<PObject> pSet = new HashSet<PObject>(); + + for (final PCClass ab : cs) { + pSet.add(ab); + } + + return pSet; + } + }, + + DOMAINS { + // Domains are not PObjects + + public Map<CharacterDomain, String> objdata; + + protected void getData(final PlayerCharacter pc) { + final Collection<CharacterDomain> domdata = new HashSet<CharacterDomain>(); + + domdata.addAll(pc.getCharacterDomainList()); + + for (final CharacterDomain c : domdata) { + // map each domain to a String. + // Each of these Strings is unique and is mapped to exactly + // one Character domain. This means we can perform set + // operations on a collection of them and it will behave as + // if we were doing it on the set of CharacterDomains. We could + // then map the Strings back to a set of CharacterDomains, but we + // only really need to count them (and we can just as easily + // count Strings as CharacterDomains). + objdata.put(c, c.getObjectName()); + } + } + + public Object count(final PlayerCharacter pc, final Object[] params) throws ParseException { + final Object[] par = validateParams(params); + final ParameterTree pt = convertParams(par); + + getData(pc); + final Set<String> filtered = doFilterS(pt); + + return (double) filtered.size(); + } + + protected Set<String> filterSetS(final String kv) throws ParseException { + final String[] keyValue = kv.split("="); + + if (!"TYPE".equalsIgnoreCase(keyValue[0])) { + throw new ParseException( + "Bad parameter to count(\"" + this + "\" ... )" + kv); + } + + final Iterable<CharacterDomain> cs = new HashSet<CharacterDomain>(objdata.keySet()); + final Iterator It = cs.iterator(); + + if (!"ALL".equalsIgnoreCase(keyValue[1])) { + while (It.hasNext()) { + final CharacterDomain c = (CharacterDomain) It.next(); + if (!c.getDomainType().equalsIgnoreCase(keyValue[1])) { + It.remove(); + } + } + } + + // at this point we have a set of character domains which meet the + // selection criteria of this leaf node of the parameter tree. + // we now convert this to a set of Strings so that the generic doFilterS + // can perform set operations on them + + final Set<String> pSet = new HashSet<String>(); + + //noinspection TypeMayBeWeakened + for (final CharacterDomain d : cs) { + pSet.add(objdata.get(d)); + } + + return pSet; + } + + protected Set<PObject> filterSetP(final String c) throws ParseException { + throw new ParseException("CharacterDomain is not a PObject, should be calling filterSetS"); + } + }, + + EQUIPMENT { + // Equipment is/are PObjects, we can implement the filterSet directly + + public Set<Equipment> objdata; + + protected void getData(final PlayerCharacter pc) { + objdata = new HashSet<Equipment>(); + objdata.addAll(pc.getEquipmentListInOutputOrder()); + } + + public Object count(final PlayerCharacter pc, final Object[] params) throws ParseException { + final Object[] par = validateParams(params); + final ParameterTree pt = convertParams(par); + + getData(pc); + final Set<PObject> filtered = doFilterP(pt); + + return (double) filtered.size(); + } + + + protected Set<String> filterSetS(final String c) throws ParseException { + throw new ParseException("Equipment is a PObject, should be calling filterSetP"); + } + + protected Set<PObject> filterSetP(final String c) throws ParseException { + final String[] keyValue = c.split("="); + + final JepEquipmentCountEnum en; + + try { + en = JepEquipmentCountEnum.valueOf(keyValue[0]); + } + catch (IllegalArgumentException ex) { + Logging.errorPrint("Bad paramter to count(\"Equipment\"), " + c); + return new HashSet<PObject>(); + } + + final Set<Equipment> cs = new HashSet<Equipment>(objdata); + final Iterator<? extends PObject> It = cs.iterator(); + + switch (en) { + case TYPE: + filterPObjectByType(It, keyValue[1]); + break; + + case WIELDCATEGORY: + while (It.hasNext()) { + final Equipment e = (Equipment) It.next(); + if (!e.getWield().equalsIgnoreCase(keyValue[1])) { + It.remove(); + } + } + break; + + // TODO have no idea how to get a suitable list of equipement + // and test for this. + + case LOCATION: + if ("CARRIED".equalsIgnoreCase(keyValue[1]) || "Equipped".equalsIgnoreCase(keyValue[1])) { +// while (It.hasNext()) +// { +// Equipment e = (Equipment) It.next(); +// if (! e.getParent().equalsIgnoreCase(keyValue[1])); +// { +// It.remove(); +// } +// } + } + case LOC: + break; + case TYP: + break; + case WDC: + break; + } + + final Set<PObject> pSet = new HashSet<PObject>(); + + for (final Equipment e : cs) { + pSet.add(e); + } + + return pSet; + } + }, + + FOLLOWERS { + // Followers are not PObjects. + + public Map<Follower, String> objdata; + + protected void getData(final PlayerCharacter pc) { + final List<Follower> followerdata = pc.getFollowerList(); + + for (final Follower f : followerdata) { + + // map each followoer to an empty string. Each of these + // Strings is unique and is mapped to exactly one Follower. + + objdata.put(f, ""); + } + } + + public Object count(final PlayerCharacter pc, final Object[] params) throws ParseException { + final Object[] par = validateParams(params); + final ParameterTree pt = convertParams(par); + + getData(pc); + final Set<String> filtered = doFilterS(pt); + + return countDataS(filtered); + } + + protected Set<PObject> filterSetP(final String c) throws ParseException { + throw new ParseException("Follower is not a PObject, should be calling filterSetS"); + } + + // If we need to be able to filter out any of these followers, this is where + // it should be done. + protected Set<String> filterSetS(final String c) { + return (Set<String>) objdata.values(); + } + }, + + LANGUAGES { + // Languages are PObjects, we can implement the filterSet directly + // i.e. without using PObject proxies. + + public Set<Language> objdata; + + protected void getData(final PlayerCharacter pc) { + objdata = new HashSet<Language>(); + objdata.addAll(pc.getLanguagesList()); + } + + public Object count(final PlayerCharacter pc, final Object[] params) throws ParseException { + final Object[] par = validateParams(params); + final ParameterTree pt = convertParams(par); + + getData(pc); + final Set<PObject> filtered = doFilterP(pt); + + return (double) filtered.size(); + } + + protected Set<PObject> filterSetP(final String c) throws ParseException { + final String[] keyValue = c.split("="); + + if (!"TYPE".equalsIgnoreCase(keyValue[0])) { + throw new ParseException( + MessageFormat.format("Bad parameter to count(\"CLASSES\" ... ){0}", c)); + } + + final Set<Language> cs = new HashSet<Language>(objdata); + final Iterator<? extends PObject> It = cs.iterator(); + + filterPObjectByType(It, keyValue[1]); + + final Set<PObject> pSet =... [truncated message content] |
From: <nu...@us...> - 2007-10-26 20:23:20
|
Revision: 4425 http://pcgen.svn.sourceforge.net/pcgen/?rev=4425&view=rev Author: nuance Date: 2007-10-26 13:23:23 -0700 (Fri, 26 Oct 2007) Log Message: ----------- Fix ParameterTree so it handles parentheses correctly. Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/Ability.java Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/Ability.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/Ability.java 2007-10-26 03:02:43 UTC (rev 4424) +++ Trunk/pcgen/code/src/java/pcgen/core/Ability.java 2007-10-26 20:23:23 UTC (rev 4425) @@ -19,13 +19,6 @@ */ package pcgen.core; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import pcgen.core.chooser.ChooserUtilities; import pcgen.core.levelability.LevelAbility; import pcgen.core.prereq.PrereqHandler; @@ -34,10 +27,17 @@ import pcgen.core.utils.ShowMessageDelegate; import pcgen.core.utils.StringKey; import pcgen.util.Logging; -import pcgen.util.enumeration.Tab; import pcgen.util.chooser.ChooserFactory; import pcgen.util.chooser.ChooserInterface; +import pcgen.util.enumeration.Tab; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * Definition and games rules for an Ability. * @@ -55,7 +55,7 @@ /** Ability is Virtual */ VIRTUAL, /** Ability of any type */ - ANY; + ANY } private boolean multiples = false; @@ -93,15 +93,15 @@ */ public int getAddSpellLevel() { - Integer characteristic = integerChar.get(IntegerKey.ADD_SPELL_LEVEL); - return characteristic == null ? 0 : characteristic.intValue(); + final Integer characteristic = integerChar.get(IntegerKey.ADD_SPELL_LEVEL); + return characteristic == null ? 0 : characteristic; } /** * Set the attribute that controls what this ability adds, e.g. WEAPONPROF, * TEMPLATE, etc. * - * @param add + * @param add what this ability adds, e.g. WEAPONPROF, TEMPLATE, etc. */ public void setAddString(final String add) { @@ -117,7 +117,7 @@ */ public String getAddString() { - String characteristic = stringChar.get(StringKey.ADD); + final String characteristic = stringChar.get(StringKey.ADD); return characteristic == null ? "" : characteristic; } @@ -126,7 +126,7 @@ * and will be concatonated on output. * * <p>The format of the description tag - * @param aDesc + * @param aDesc a description of what this object provides */ public void addBenefit( final Description aDesc ) { @@ -256,7 +256,7 @@ */ public String getCategory() { - String characteristic = stringChar.get(StringKey.CATEGORY); + final String characteristic = stringChar.get(StringKey.CATEGORY); return characteristic == null ? Constants.FEAT_CATEGORY : characteristic; } @@ -296,7 +296,7 @@ */ public String getCostString() { - String characteristic = stringChar.get(StringKey.COST); + final String characteristic = stringChar.get(StringKey.COST); return characteristic == null ? "1" : characteristic; } @@ -366,7 +366,7 @@ } else { - char firstChar = aString.charAt(0); + final char firstChar = aString.charAt(0); multiples = firstChar == 'y' || firstChar == 'Y'; } } @@ -427,10 +427,10 @@ * Whether we can add newAssociation to the associated list of this * Ability * - * @param newAssociation + * @param newAssociation The thing to be associated with this Ability * @return true if we can add the association */ - public boolean canAddAssociation(String newAssociation) + public boolean canAddAssociation(final String newAssociation) { return this.isStacks() || (this.isMultiples() && !this.containsAssociated(newAssociation)); } @@ -524,7 +524,7 @@ if (getChoiceToModify().length() != 0) { - txt.append("\tMODIFYABILITYCHOICE:" + getChoiceToModify()); + txt.append("\tMODIFYABILITYCHOICE:").append(getChoiceToModify()); } txt.append(super.getPCCText(false)); @@ -550,7 +550,7 @@ // don't do for Weapon Profs final StringBuffer aStrBuf = new StringBuffer(getOutputName()); - if (getOutputName().equalsIgnoreCase("[BASE]")) + if ("[BASE]".equalsIgnoreCase(getOutputName())) { return getDisplayName(); } @@ -570,11 +570,11 @@ } else { - int i = 0; - // has a sub-detail aStrBuf.append(" ("); + int i = 0; + // list of items in associatedList, e.g. " (Sub1, Sub2, ...)" for (int e = 0; e < getAssociatedCount(true); ++e) { @@ -611,7 +611,7 @@ * * @return true if the Ability was modified, false otherwise */ - public boolean modChoices(final PlayerCharacter aPC, final boolean addIt, AbilityCategory category) + public boolean modChoices(final PlayerCharacter aPC, final boolean addIt, final AbilityCategory category) { final List availableList = new ArrayList(); // available list of choices final List selectedList = new ArrayList(); // selected list of choices @@ -632,11 +632,11 @@ * may also be used to build a list of choices available and choices * already made by passing false in the process parameter * - * @param availableList - * @param selectedList - * @param process - * @param aPC - * @param addIt + * @param availableList the list of things not already chosen + * @param selectedList the list of things already chosen + * @param process if false do not process the choice, just poplate the lists + * @param aPC the PC that owns the Ability + * @param addIt Whether to add or remove a choice from this Ability * @param category The ability category whose pool is to be charged for the ability. * * @return true if we processed the list of choices, false if we used the routine to @@ -664,23 +664,23 @@ * Enhanced containsAssociated, which parses the input parameter for "=", * "+num" and "-num" to extract the value to look for. * - * @param aType The type we're looking for + * @param type The type we're looking for * * @return enhanced containsAssociated, which parses the input parameter * for "=", "+num" and "-num" to extract the value to look for. */ - @Override int numberInList(String aType) + @Override int numberInList(final String type) { - int iCount = 0; - final String numString = "0123456789"; + String aType = type; - if (aType.lastIndexOf('=') > -1) + if (aType.lastIndexOf('=') > -1) { aType = aType.substring(aType.lastIndexOf('=') + 1); } // truncate at + sign if following character is a number - if (aType.lastIndexOf('+') > -1) + final String numString = "0123456789"; + if (aType.lastIndexOf('+') > -1) { final String aString = aType.substring(aType.lastIndexOf('+') + 1); @@ -701,7 +701,8 @@ } } - for (int i = 0; i < getAssociatedCount(); ++i) + int iCount = 0; + for (int i = 0; i < getAssociatedCount(); ++i) { if (getAssociated(i).equalsIgnoreCase(aType)) { @@ -758,7 +759,7 @@ */ public String getChoiceToModify() { - String characteristic = stringChar.get(StringKey.CHOICE_TO_MODIFY); + final String characteristic = stringChar.get(StringKey.CHOICE_TO_MODIFY); return characteristic == null ? "" : characteristic; } @@ -770,7 +771,7 @@ * * @return whether we modified the Ability */ - public boolean modifyChoice(PlayerCharacter aPC) + public boolean modifyChoice(final PlayerCharacter aPC) { String abilityName = getChoiceToModify(); @@ -779,12 +780,10 @@ return false; } - ArrayList<String> abilityList = new ArrayList<String>(); - ArrayList<String> selectedList = new ArrayList<String>(); + final List<String> abilityList = new ArrayList<String>(); + final List<String> selectedList = new ArrayList<String>(); - Ability anAbility; - - if (abilityName.startsWith("TYPE=") || abilityName.startsWith("TYPE=")) + if (abilityName.startsWith("TYPE=") || abilityName.startsWith("TYPE.")) { final String anAbilityType = abilityName.substring(5); @@ -792,7 +791,7 @@ // Get a list of all ability possessed by the character that // are the specified type // - for ( Ability ability : aPC.aggregateFeatList() ) + for ( final PObject ability : aPC.aggregateFeatList() ) { if (ability.isType(anAbilityType)) { @@ -844,9 +843,9 @@ } } - anAbility = aPC.getFeatNamed(abilityName); + final Ability anAbility = aPC.getFeatNamed(abilityName); - if (anAbility == null) + if (anAbility == null) { Logging.debugPrint("PC does not have ability: " + abilityName); @@ -912,7 +911,7 @@ * Compare an ability (category) to another one * Returns the compare value from String.compareToIgnoreCase * - * @param obj + * @param obj the object that we're comparing against * @return compare value */ @Override @@ -922,7 +921,7 @@ { try { - Ability ab = (Ability) obj; + final Categorisable ab = (Categorisable) obj; if (this.getCategory().compareToIgnoreCase(ab.getCategory()) != 0) { return this.getCategory().compareToIgnoreCase(ab.getCategory()); @@ -949,7 +948,7 @@ * @return true if they are equal */ @Override - public boolean equals(Object other) + public boolean equals(final Object other) { return other instanceof Ability && this.compareTo(other) == 0; } @@ -967,7 +966,7 @@ * Test whether other is the same base ability as this (ignoring any changes * made to apply either to a PC) * - * @param that + * @param that the other ability * @return true is the abilities are copies of the same base ability */ public boolean isSameBaseAbility(Ability that) { Modified: Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java 2007-10-26 03:02:43 UTC (rev 4424) +++ Trunk/pcgen/code/src/java/pcgen/util/ParameterTree.java 2007-10-26 20:23:23 UTC (rev 4425) @@ -23,158 +23,242 @@ */ package pcgen.util; +import org.nfunk.jep.ParseException; + import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.nfunk.jep.ParseException; - public class ParameterTree { - String data; - ParameterTree left; - ParameterTree right; - static public String orString = "[or]"; - static public String andString = "[and]"; + String contents; + ParameterTree left = null; + ParameterTree right = null; + public static String orString = "[or]"; + public static String andString = "[and]"; static String orPatString = "\\[or\\]"; static String andPatString = "\\[and\\]"; - - static String patString = "(\\(|\\)|" + orPatString + "|" + andPatString + ")"; + + private static String leftBracket = "("; + private static String leftPatString = "\\("; + private static String rightPatString = "\\)"; + + static String patString = "(" + leftPatString + "|" + rightPatString+ "|" + orPatString + "|" + andPatString + ")"; static Pattern pat = Pattern.compile(patString); + // the grouping pattern & matcher + private static final String parenString = "(" + leftPatString + "|" + rightPatString + ")"; + private static final Pattern parenPattern = Pattern.compile(parenString); - public static ParameterTree makeTree (final String source) throws ParseException + // the opertor pattern & matcher + private static final String operatorString = "(" + orPatString + "|" + andPatString + ")"; + private static final Pattern operatorPattern = Pattern.compile(operatorString); + + + private static int getIndexOfClosingParen ( + final String s, + final int start) throws ParseException + { + final Matcher aMat = parenPattern.matcher(s); + + aMat.find(start); + int level = 1; + + while (level > 0) { + if (!aMat.find()) { + throw new ParseException("unbalanced parenthesis in " + s); + } + + if (leftBracket.equalsIgnoreCase(aMat.group())) { + level++; + } else { + level--; + } + } + + return aMat.end(); + } + + public static ParameterTree makeTree (final String source) throws ParseException { - Matcher mat = ParameterTree.pat.matcher(source); + final Matcher mat = ParameterTree.pat.matcher(source); if (mat.find()) { - return ParameterTree.makeTree(null, source.substring(0, mat.start()), mat, source, 0); + return makeTree(source, false); } else { return new ParameterTree(source); } } - static ParameterTree makeTree (ParameterTree outertree, String beforeop, Matcher m, String s, int start) throws ParseException + private static ParameterTree makeTree ( + final String source, + final boolean operatorNeeded) throws ParseException { - ParameterTree newt = null; + final Matcher pM = parenPattern.matcher(source); + final boolean hasP = pM.find(); - if (m.group().equalsIgnoreCase("(")) - { - if (m.start() != start) - { - throw new ParseException("found ( with no preceeding operator at char " + start + " of " + s); - } - - if (m.find()) - { - newt = makeTree(null, s.substring(start + 1, m.start()), m, s, start + 1); - - } - else - { - throw new ParseException("We should have matched a ')' to close the inner expression."); - } - } - - - ParameterTree root = outertree; - - if (beforeop.equalsIgnoreCase("")) - { - if (null == newt) - { - throw new ParseException("Apparently empty operand at char " + start + " of " + s); - } - else - { - if (root == null) { - root = newt; - } - else - { - root.setRightTree(newt); - } - } - } - else - { - if (root == null) { - root = new ParameterTree(beforeop); - } - else - { - root.setRightTree(new ParameterTree(beforeop)); - } - } - - int nextstart = 0; - - // we can't just check for ")" because that will close all recursed subtrees - // if we match the ), then we try to match again, this resets the match object - // for the calling instance of this method. This may mean that when the caller - // hits this piece of code, the match object is in an invalid state. - try - { - nextstart = m.end(); - - if (m.group().equalsIgnoreCase(")")) - { - // because this find may not work, the match object in the caller needs this try block - if (m.find()) - { - if (nextstart != m.start()) - { - throw new ParseException("a close bracket must be followed by an operator or another close bracket"); - } - } - return root; - } - } - catch (IllegalStateException e) - { - return root; - } + ParameterTree t; - final ParameterTree op = new ParameterTree(m.group()); - - op.setLeftTree(root); - root = op; - - // grab the start of the right operand incase we need it next - nextstart = m.end(); + if (hasP) { + final String pre = source.substring(0, pM.start()); + final int end = getIndexOfClosingParen(source, pM.start()); - if (m.find()) { - - ParameterTree t1 = makeTree(root, s.substring(nextstart, m.start()), m, s, nextstart); - return t1; - - } else { - root.setRightTree(new ParameterTree(s.substring(nextstart))); - return root; - } - } + if (0 == pre.length()) { - public Double processTree (Enum e) + final String inside = source.substring(pM.end(), end - 1); + t = makeTree(inside, false); + + } else { + + t = toTree(pre, operatorNeeded); + + final Matcher rM = operatorPattern.matcher(t.getContents()); + + if (rM.find()) { + + if (t.getRightTree() == null) { + // Since we found an operator in the root of the tree, but + // the right subtree is null, then the parens must contain + // a complete expression (or the whole thing is illegal) + // so make a tree from the contents and append it here + // remember to strip off the outer parens. + final String inside = source.substring(pM.end(), end - 1); + t.setRightTree(makeTree(inside, false)); + } else { + // The root of the tree generated from the first section of the + // string has something in its right sub tree. That means the + // parenthesised expression is a part of that string (since + // if it ended with an operator that would be in a separate + // "root") + final StringBuilder rNodeContents = new StringBuilder(); + rNodeContents.append(t.getRightTree().getContents()); + rNodeContents.append(source.substring(pM.start(), end)); + } + + } else { + // root of the generated tree doesn't contain an operator, so + // the paren expression should be tacked onto it. + final String parenExp = source.substring(pM.end() - 1, end); + final StringBuilder rNodeContents = new StringBuilder(); + rNodeContents.append(t.getContents()).append(parenExp); + t.setContents(rNodeContents.toString()); + } + } + + if (end < source.length()) { + final String sEnd = source.substring(end); + final ParameterTree r = makeTree(sEnd,true); + + ParameterTree c = r; + + final Matcher cM = operatorPattern.matcher(r.getContents()); + + if (!cM.find()) { + throw new ParseException("expected \"" + source.substring(end) + "\" to begin with an operator"); + } + + while (c.getLeftTree() != null) { + c = c.getLeftTree(); + } + + c.setLeftTree(t); + t = r; + } + } else { + t = toTree(source, operatorNeeded); + } + + return t; + } + + private static ParameterTree toTree( + final String source, + final boolean operatorNeeded) throws ParseException { - - return new Double(0.0); - } + String s = source; + // the opertor matcher + Matcher oM = operatorPattern.matcher(s); + ParameterTree cT = new ParameterTree(""); //current Tree - /** - * @param data + boolean hasO = oM.find(); + + // this is for operators, obviously + if (hasO && operatorNeeded) { + if (oM.start() != 0) { + throw new ParseException("expected \"" + s + "\" to begin with an operator"); + } else { + cT = new ParameterTree(oM.group()); + final int end = oM.end(); + s = s.substring(end); + oM = operatorPattern.matcher(s); + hasO = oM.find(); + } + } + + int start = 0; + + while (hasO) { + + final String pre = s.substring(start, oM.start()); + + final ParameterTree P = new ParameterTree(pre); // pre Tree + final ParameterTree R = new ParameterTree(oM.group()); // root Tree - must be an operator (it matched) + + // is the "root" of the current tree an operator + final Matcher cM = operatorPattern.matcher(cT.getContents()); + + if (cM.find()) { + cT.setRightTree(P); + R.setLeftTree(cT); + // right branch of R is null + } else { + R.setLeftTree(P); + // can discard current tree, it's empty (first iteration) + } + + // root becomes new current tree + cT = R; + + start = oM.end(); + hasO = oM.find(); + } + + // no more operators, but string is not empty + if (start < s.length()) { + + final ParameterTree p = new ParameterTree(s.substring(start)); + final Matcher cM = operatorPattern.matcher(cT.getContents()); + + if (cM.find()) { + // current tree has operator in root + cT.setRightTree(p); + } else { + // current tree is the default empty tree created above + cT = p; + } + } + + return cT; + } + + + /** + * @param data The value that will end up in the node of the tree */ - public ParameterTree(String data) { + ParameterTree(final String data) { super(); - this.data = data; - left = null; - right = null; - } + this.contents = data; + } - /** + public void setContents(final String data) { + this.contents = data; + } + + /** * @return the Contents */ public String getContents() { - return data; + return contents; } @@ -188,8 +272,8 @@ /** * @param l the ParameterTree to add as the left sub tree */ - public void setLeftTree(ParameterTree l) { - this.left = l; + public void setLeftTree(final ParameterTree l) { + left = l; } /** @@ -202,7 +286,27 @@ /** * @param r the ParameterTree to add as the right sub tree */ - public void setRightTree(ParameterTree r) { - this.right = r; + public void setRightTree(final ParameterTree r) { + right = r; } + + public String toString() { + final StringBuilder sb = new StringBuilder(200); + + sb.append("["); + sb.append(contents); + sb.append(" "); + + if (left != null) { + sb.append(left.toString()); + } + + if (right != null) { + sb.append(right.toString()); + } + + sb.append("]"); + + return sb.toString(); + } } \ No newline at end of file Modified: Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java 2007-10-26 03:02:43 UTC (rev 4424) +++ Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java 2007-10-26 20:23:23 UTC (rev 4425) @@ -144,11 +144,10 @@ while (abIt.hasNext()) { final PObject p = abIt.next(); - if (!p.getKeyName().equalsIgnoreCase(keyValue[1])) { + if (!p.getDisplayName().equalsIgnoreCase(keyValue[1])) { abIt.remove(); } } - break; case NATURE: @@ -740,7 +739,7 @@ if (pt == null) { pt = ParameterTree.makeTree((String) param); } else { - final ParameterTree npt = new ParameterTree(ParameterTree.andString); + final ParameterTree npt = ParameterTree.makeTree(ParameterTree.andString); npt.setLeftTree(pt); pt = npt; final ParameterTree npt1 = ParameterTree.makeTree((String) param); Modified: Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java 2007-10-26 03:02:43 UTC (rev 4424) +++ Trunk/pcgen/code/src/test/pcgen/util/ParameterTreeTest.java 2007-10-26 20:23:23 UTC (rev 4425) @@ -24,14 +24,12 @@ package pcgen.util; -import java.util.regex.Matcher; - import org.junit.Test; import org.nfunk.jep.ParseException; - import pcgen.PCGenTestCase; -import pcgen.util.ParameterTree; +import java.util.regex.Matcher; + /** * <code>ParameterTreeTest</code> is ... * @@ -51,23 +49,23 @@ @Test public final void testParameterTree() { - ParameterTree t1 = new ParameterTree("Test Node1"); - is(t1.getContents(), strEq("Test Node1"), "New ParamterTrre has correct contents"); - is(t1.getLeftTree(), eqnull(), "New ParamterTrre has null left subtree"); - is(t1.getRightTree(), eqnull(), "New ParamterTrre has null right subtree"); + final ParameterTree t1 = new ParameterTree("Test Node1"); + is(t1.getContents(), strEq("Test Node1"), "New ParameterTree has correct contents"); + is(t1.getLeftTree(), eqnull(), "New ParameterTree has null left subtree"); + is(t1.getRightTree(), eqnull(), "New ParameterTree has null right subtree"); - ParameterTree t2 = new ParameterTree("Test Node2"); + final ParameterTree t2 = new ParameterTree("Test Node2"); t2.setLeftTree(t1); - is(t2.getContents(), strEq("Test Node2"), "New ParamterTrre has correct contents"); - is(t2.getLeftTree().getContents(), strEq("Test Node1"), "New ParamterTrre has null left subtree"); - is(t1.getRightTree(), eqnull(), "New ParamterTrre has null right subtree"); + is(t2.getContents(), strEq("Test Node2"), "New ParameterTree has correct contents"); + is(t2.getLeftTree().getContents(), strEq("Test Node1"), "New ParameterTree has null left subtree"); + is(t1.getRightTree(), eqnull(), "New ParameterTree has null right subtree"); } @Test public final void testMakeTree1() { - String s = "TYPE=Foo"; - Matcher mat = ParameterTree.pat.matcher(s); + final String s = "TYPE=Foo"; + final Matcher mat = ParameterTree.pat.matcher(s); mat.find(); ParameterTree t1 = new ParameterTree("Foo"); @@ -84,8 +82,8 @@ @Test public final void testMakeTree2() { - String s = "(TYPE=Foo)"; - Matcher mat = ParameterTree.pat.matcher(s); + final String s = "(TYPE=Foo)"; + final Matcher mat = ParameterTree.pat.matcher(s); mat.find(); ParameterTree t1 = new ParameterTree("Foo"); @@ -102,8 +100,8 @@ @Test public final void testMakeTree3() { - String s = "((TYPE=Foo))"; - Matcher mat = ParameterTree.pat.matcher(s); + final String s = "((TYPE=Foo))"; + final Matcher mat = ParameterTree.pat.matcher(s); mat.find(); ParameterTree t1 = new ParameterTree("Foo"); @@ -120,8 +118,8 @@ @Test public final void testMakeTree4() { - String s = "TYPE=Foo[or]TYPE=Bar"; - Matcher mat = ParameterTree.pat.matcher(s); + final String s = "TYPE=Foo[or]TYPE=Bar"; + final Matcher mat = ParameterTree.pat.matcher(s); mat.find(); ParameterTree t1 = new ParameterTree("Foo"); @@ -146,8 +144,8 @@ @Test public final void testMakeTree5() { - String s = "(TYPE=Foo[or]TYPE=Bar)"; - Matcher mat = ParameterTree.pat.matcher(s); + final String s = "(TYPE=Foo[or]TYPE=Bar)"; + final Matcher mat = ParameterTree.pat.matcher(s); mat.find(); ParameterTree t1 = new ParameterTree("Foo"); @@ -171,8 +169,8 @@ @Test public final void testMakeTree6() { - String s = "(TYPE=Foo[or]TYPE=Bar[and]String3)"; - Matcher mat = ParameterTree.pat.matcher(s); + final String s = "(TYPE=Foo[or]TYPE=Bar[and]String3)"; + final Matcher mat = ParameterTree.pat.matcher(s); mat.find(); ParameterTree t = new ParameterTree("Foo"); @@ -183,10 +181,10 @@ fail("Threw a parse exception"); } - ParameterTree tl = t.getLeftTree(); - ParameterTree tr = t.getRightTree(); - ParameterTree tll = tl.getLeftTree(); - ParameterTree tlr = tl.getRightTree(); + final ParameterTree tl = t.getLeftTree(); + final ParameterTree tr = t.getRightTree(); + final ParameterTree tll = tl.getLeftTree(); + final ParameterTree tlr = tl.getRightTree(); // expected branch nodes is(t.getContents(), strEq("[and]"), "t1 ParamterTree has correct contents"); @@ -214,8 +212,8 @@ // verbose = true; // Logging.errorPrint("\n\n --- Start Test Make tree 7 --- \n\n"); - String s = "TYPE=Foo[or](TYPE=Bar[and]String3)"; - Matcher mat = ParameterTree.pat.matcher(s); + final String s = "TYPE=Foo[or](TYPE=Bar[and]String3)"; + final Matcher mat = ParameterTree.pat.matcher(s); mat.find(); ParameterTree t = new ParameterTree("Foo"); @@ -226,10 +224,10 @@ fail("Threw a parse exception"); } - ParameterTree tl = t.getLeftTree(); - ParameterTree tr = t.getRightTree(); - ParameterTree trl = tr.getLeftTree(); - ParameterTree trr = tr.getRightTree(); + final ParameterTree tl = t.getLeftTree(); + final ParameterTree tr = t.getRightTree(); + final ParameterTree trl = tr.getLeftTree(); + final ParameterTree trr = tr.getRightTree(); // expected branch nodes is(t, not(eqnull()), "t not null"); @@ -265,8 +263,8 @@ // verbose = true; // Logging.errorPrint("\n\n --- Start Test Make tree 8 --- \n\n"); - String s = "TYPE=Foo[or]((CATEGORY=FEAT[or]NATURE=AUTO)[and]TYPE=Bar)"; - Matcher mat = ParameterTree.pat.matcher(s); + final String s = "TYPE=Foo[or]((CATEGORY=FEAT[or]NATURE=AUTO)[and]TYPE=Bar)"; + final Matcher mat = ParameterTree.pat.matcher(s); mat.find(); ParameterTree t = new ParameterTree("Foo"); @@ -280,14 +278,14 @@ } - ParameterTree tl = t.getLeftTree(); - ParameterTree tr = t.getRightTree(); + final ParameterTree tl = t.getLeftTree(); + final ParameterTree tr = t.getRightTree(); - ParameterTree trl = tr.getLeftTree(); - ParameterTree trr = tr.getRightTree(); + final ParameterTree trl = tr.getLeftTree(); + final ParameterTree trr = tr.getRightTree(); - ParameterTree trll = trl.getLeftTree(); - ParameterTree trlr = trl.getRightTree(); + final ParameterTree trll = trl.getLeftTree(); + final ParameterTree trlr = trl.getRightTree(); // expected branch nodes @@ -332,8 +330,8 @@ // verbose = true; // Logging.errorPrint("\n\n --- Start Test Make tree 9 --- \n\n"); - String s = "TYPE=Foo[or]((CATEGORY=FEAT[or]NATURE=AUTO[or]CATEGORY=SA)[and]TY... [truncated message content] |
From: <nu...@us...> - 2007-10-26 23:19:39
|
Revision: 4429 http://pcgen.svn.sourceforge.net/pcgen/?rev=4429&view=rev Author: nuance Date: 2007-10-26 16:19:44 -0700 (Fri, 26 Oct 2007) Log Message: ----------- Add some tests for the jep if command Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/jepcommands/IfCommand.java Trunk/pcgen/code/src/test/pcgen/PCGenTestCase.java Trunk/pcgen/code/src/test/pcgen/util/testchecker/CompareGreaterThan.java Added Paths: ----------- Trunk/pcgen/code/src/test/plugin/jepcommands/IfCommandTest.java Modified: Trunk/pcgen/code/src/java/plugin/jepcommands/IfCommand.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/jepcommands/IfCommand.java 2007-10-26 23:08:31 UTC (rev 4428) +++ Trunk/pcgen/code/src/java/plugin/jepcommands/IfCommand.java 2007-10-26 23:19:44 UTC (rev 4429) @@ -1,11 +1,10 @@ package plugin.jepcommands; -import java.util.Stack; - import org.nfunk.jep.ParseException; - import pcgen.util.PCGenCommand; +import java.util.Stack; + /** * <p> * If class; extends PostfixMathCommand. This class accepts three agruments. @@ -54,7 +53,7 @@ * @throws ParseException */ @SuppressWarnings("unchecked") //Uses JEP, which doesn't use generics - public void run(Stack stack) throws ParseException + public void run(final Stack stack) throws ParseException { // Check if stack is null if (null == stack) @@ -62,37 +61,26 @@ throw new ParseException("Stack argument null"); } - Object result = null; + final boolean condition; - boolean condition = false; + final Object param3 = stack.pop(); + final Object param2 = stack.pop(); + final Object param1 = stack.pop(); - Object param3 = stack.pop(); - Object param2 = stack.pop(); - Object param1 = stack.pop(); - if (param1 instanceof Number) { condition = (((Number) param1).doubleValue() != 0d); } else if (param1 instanceof Boolean) { - condition = ((Boolean) param1).booleanValue(); + condition = (Boolean) param1; } else { throw new ParseException("Invalid parameter type for Parameter 1"); } - if (condition) - { - result = param2; - } - else - { - result = param3; - } - // push the result on the inStack - stack.push(result); + stack.push(condition ? param2 : param3); } } Modified: Trunk/pcgen/code/src/test/pcgen/PCGenTestCase.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/PCGenTestCase.java 2007-10-26 23:08:31 UTC (rev 4428) +++ Trunk/pcgen/code/src/test/pcgen/PCGenTestCase.java 2007-10-26 23:19:44 UTC (rev 4429) @@ -80,7 +80,8 @@ /** * Constructs a new <code>PCGenTestCase</code> with the given <var>name</var>. * - * @see TestCase#TestCase(String) + * @param name The name of the test case + * @see TestCase#TestCase(String) */ public PCGenTestCase(final String name) { @@ -137,9 +138,9 @@ } } - protected void is(Object something, TestChecker matches) + protected void is(final Object something, final TestChecker matches) { - count = count + 1; + count += 1; if (verbose) { @@ -151,27 +152,27 @@ { Logging.errorPrint("\n!!! Not OK !!! - unlabelled test case"); - StringBuffer message = new StringBuffer(" Expected: "); + final StringBuffer message = new StringBuffer(" Expected: "); matches.scribe(message); message.append("\n but got: ").append(something).append('\n'); Logging.errorPrint(message.toString()); - errors = errors + 1; + errors += 1; } } else if (!matches.check(something)) { - StringBuffer message = new StringBuffer("\nExpected: "); + final StringBuffer message = new StringBuffer("\nExpected: "); matches.scribe(message); message.append("\nbut got: ").append(something).append('\n'); fail(message.toString()); } } - protected void is(Object something, TestChecker matches, String testCase) + protected void is(final Object something, final TestChecker matches, final String testCase) { - count = count + 1; + count += 1; if (verbose) { @@ -183,18 +184,18 @@ { Logging.errorPrint("\n!!! Not OK !!! - " + testCase); - StringBuffer message = new StringBuffer(" Expected: "); + final StringBuffer message = new StringBuffer(" Expected: "); matches.scribe(message); message.append("\n but got: ").append(something).append("\n"); Logging.errorPrint(message.toString()); - errors = errors + 1; + errors += 1; } } else if (!matches.check(something)) { - StringBuffer message = new StringBuffer("\nExpected: "); + final StringBuffer message = new StringBuffer("\nExpected: "); matches.scribe(message); message.append("\nbut got: ").append(something); message.append(" \nIn test ").append(testCase); @@ -203,57 +204,57 @@ } } - public CompareEqualString strEq(String s) + public CompareEqualString strEq(final String s) { return new CompareEqualString(s); } - public CompareEqualObject eq(Object operand) + public CompareEqualObject eq(final Object operand) { return new CompareEqualObject(operand); } - public CompareEqualBoolean eq(boolean bo) + public CompareEqualBoolean eq(final boolean bo) { return new CompareEqualBoolean(bo); } - public CompareEqualByte eq(byte operand) + public CompareEqualByte eq(final byte operand) { return new CompareEqualByte(operand); } - public CompareEqualShort eq(short operand) + public CompareEqualShort eq(final short operand) { return new CompareEqualShort(operand); } - public CompareEqualChar eq(char operand) + public CompareEqualChar eq(final char operand) { return new CompareEqualChar(operand); } - public CompareEqualInt eq(int operand) + public CompareEqualInt eq(final int operand) { return new CompareEqualInt(operand); } - public CompareEqualLong eq(long operand) + public CompareEqualLong eq(final long operand) { return new CompareEqualLong(operand); } - public CompareEqualFloat eq(float operand) + public CompareEqualFloat eq(final float operand) { return new CompareEqualFloat(operand); } - public CompareEqualDouble eq(double operand) + public CompareEqualDouble eq(final double operand) { return new CompareEqualDouble(operand); } - public CompareDeadband eq(double operand, double error) + public CompareDeadband eq(final double operand, final double error) { return new CompareDeadband(operand, error); } @@ -263,52 +264,52 @@ return new CompareNull(); } - public CompareSame same(Object operand) + public CompareSame same(final Object operand) { return new CompareSame(operand); } - public CompareSubstring stringContains(String substring) + public CompareSubstring stringContains(final String substring) { return new CompareSubstring(substring); } - public BoolNot not(TestChecker c) + public BoolNot not(final TestChecker c) { return new BoolNot(c); } - public BoolAnd and(TestChecker left, TestChecker right) + public BoolAnd and(final TestChecker left, final TestChecker right) { return new BoolAnd(left, right); } - public BoolOr or(TestChecker left, TestChecker right) + public BoolOr or(final TestChecker left, final TestChecker right) { return new BoolOr(left, right); } - public BoolXor xor(TestChecker left, TestChecker right) + public BoolXor xor(final TestChecker left, final TestChecker right) { return new BoolXor(left, right); } - public CompareGreaterThan gt(Comparable operand) + public CompareGreaterThan gt(final Comparable<Object> operand) { return new CompareGreaterThan(operand); } - public CompareGreaterOrEqual ge(Comparable operand) + public CompareGreaterOrEqual ge(final Comparable<Object> operand) { return new CompareGreaterOrEqual(operand); } - public CompareLessThan lt(Comparable operand) + public CompareLessThan lt(final Comparable<Object> operand) { return new CompareLessThan(operand); } - public CompareLessOrEqual le(Comparable operand) + public CompareLessOrEqual le(final Comparable<Object> operand) { return new CompareLessOrEqual(operand); } Modified: Trunk/pcgen/code/src/test/pcgen/util/testchecker/CompareGreaterThan.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/util/testchecker/CompareGreaterThan.java 2007-10-26 23:08:31 UTC (rev 4428) +++ Trunk/pcgen/code/src/test/pcgen/util/testchecker/CompareGreaterThan.java 2007-10-26 23:19:44 UTC (rev 4429) @@ -34,19 +34,19 @@ /** * Constructor - * @param comp + * @param comp The first operand of the compare */ - public CompareGreaterThan(Comparable<Object> comp) + public CompareGreaterThan(final Comparable<Object> comp) { this.comp = comp; } - public boolean check(Object obj) + public boolean check(final Object obj) { - return this.comp.compareTo(obj) < 0; + return comp.compareTo(obj) < 0; } - public StringBuffer scribe(StringBuffer buf) + public StringBuffer scribe(final StringBuffer buf) { buf.append("a value greater than <"); buf.append(this.comp); Copied: Trunk/pcgen/code/src/test/plugin/jepcommands/IfCommandTest.java (from rev 4427, Trunk/pcgen/code/src/test/plugin/jepcommands/CountCommandTest.java) =================================================================== --- Trunk/pcgen/code/src/test/plugin/jepcommands/IfCommandTest.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/jepcommands/IfCommandTest.java 2007-10-26 23:19:44 UTC (rev 4429) @@ -0,0 +1,146 @@ +/* + * IfCommandTest.java + * Copyright 2007 (C) andrew wilson <nu...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on Oct 26, 2007 + * + * $Id$ + * + */ +package plugin.jepcommands; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.nfunk.jep.ParseException; +import org.nfunk.jep.function.PostfixMathCommandI; +import pcgen.PCGenTestCase; + +import java.util.Stack; + +/** + * <code>IfCommandTest</code> tests the functioning of the jep if plugin + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author andrew wilson <nu...@us...> + * @version $Revision$ + */ +public class IfCommandTest extends PCGenTestCase +{ + + /** + * Quick test suite creation - adds all methods beginning with "test" + * @return The Test suite + */ + public static Test suite() + { + return new TestSuite(IfCommandTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + + } + + private static boolean runIf(final Stack stack, final PostfixMathCommandI pCommand) + { + boolean b; + try + { + pCommand.run(stack); + b = true; + } + catch (ParseException e) + { + b = false; + } + return b; + } + + /* Test the case where the condition is a zero double */ + public void testIf01() + { + final PostfixMathCommandI c = new IfCommand(); + final Stack<Double> s = new Stack<Double>(); + + s.push(0.0); + s.push(1.0); + s.push(2.0); + + runIf(s, c); + + final Double result = s.pop(); + + is(result, eq(2.0, 0.1), "if (0.0,1.0,2.0) returns 2.0"); + } + + /* Test the case where the condition is a non zero double */ + public void testIf02() + { + final PostfixMathCommandI c = new IfCommand(); + final Stack<Double> s = new Stack<Double>(); + + s.push(1.0); + s.push(1.0); + s.push(2.0); + + runIf(s, c); + + final Double result = s.pop(); + + is(result, eq(1.0, 0.1), "if (1.0,1.0,2.0) returns 1.0"); + } + + /* Test the case where the condition is a false boolean */ + public void testIf03() + { + final PostfixMathCommandI c = new IfCommand(); + final Stack<Boolean> s = new Stack<Boolean>(); + + s.push(false); + s.push(false); + s.push(true); + + runIf(s, c); + + final Boolean result = s.pop(); + + is(result, eq(true), "if (false,false,true) returns true"); + } + + /* Test the case where the condition is a true boolean */ + public void testIf04() + { + final PostfixMathCommandI c = new IfCommand(); + final Stack<Boolean> s = new Stack<Boolean>(); + + s.push(true); + s.push(false); + s.push(true); + + runIf(s, c); + + final Boolean result = s.pop(); + + is(result, eq(false), "if (true,false,true) returns false"); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nu...@us...> - 2007-10-27 02:19:59
|
Revision: 4432 http://pcgen.svn.sourceforge.net/pcgen/?rev=4432&view=rev Author: nuance Date: 2007-10-26 19:19:47 -0700 (Fri, 26 Oct 2007) Log Message: ----------- Implement jep or function Added Paths: ----------- Trunk/pcgen/code/src/java/plugin/jepcommands/OrCommand.java Trunk/pcgen/code/src/test/plugin/jepcommands/OrCommandTest.java Added: Trunk/pcgen/code/src/java/plugin/jepcommands/OrCommand.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/jepcommands/OrCommand.java (rev 0) +++ Trunk/pcgen/code/src/java/plugin/jepcommands/OrCommand.java 2007-10-27 02:19:47 UTC (rev 4432) @@ -0,0 +1,120 @@ +/* + * IfCommand.java + * Copyright 2007 (C) Andrew Wilson <nu...@so...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on 27/10/2007 + * + * $Id$ + */ + +package plugin.jepcommands; + +import org.nfunk.jep.ParseException; +import pcgen.util.PCGenCommand; + +import java.util.Stack; + +/** + * <p> + * Or class; extends PostfixMathCommand. This class accepts two or more + * agruments. Each may be a boolean or a number interpreted as a boolean. + * Returns a logical or of the operands. + * </p> + * <p> + * So, given or(x,y,z), x or y or z is returned + * </p> + * + * @author Andrew Wilson + * + */ +public class OrCommand extends PCGenCommand +{ + + public OrCommand() + { + super(); + numberOfParameters = -1; + } + + public String getFunctionName() + { + return "OR"; + } + + /** + * @param inStack + * Stack of incoming arguments. + * @throws ParseException + */ + @Override + @SuppressWarnings({"unchecked"}) + //Uses JEP, which doesn't use generics + public void run(final Stack inStack) throws ParseException + { + + // check the stack + checkStack(inStack); + + // Check if stack is null + if (null == inStack) + { + throw new ParseException("Stack argument null"); + } + + final Stack newStack = new Stack(); + int paramCount = curNumberOfParameters; + + while (paramCount > 0) + { + paramCount--; + newStack.push(inStack.pop()); + } + + int paramCount1 = curNumberOfParameters; + Object result = 0.0; + + while (paramCount1 > 0) + { + paramCount1--; + + final Object operand = newStack.pop(); + + // If we're haven't found a true value yet + if (operand instanceof Number) + { + if (((Number) operand).doubleValue() != 0d) { + result = operand; + break; + } + } + else if (operand instanceof Boolean) + { + if ((Boolean) operand) { + result = operand; + break; + } + } + else + { + throw new ParseException("Invalid parameter type for: " + operand); + } + } + + // finally, put back the result + inStack.push(result); + } +} Property changes on: Trunk/pcgen/code/src/java/plugin/jepcommands/OrCommand.java ___________________________________________________________________ Name: svn:keywords + Date Author Revision Id Name: svn:eol-style + native Copied: Trunk/pcgen/code/src/test/plugin/jepcommands/OrCommandTest.java (from rev 4429, Trunk/pcgen/code/src/test/plugin/jepcommands/IfCommandTest.java) =================================================================== --- Trunk/pcgen/code/src/test/plugin/jepcommands/OrCommandTest.java (rev 0) +++ Trunk/pcgen/code/src/test/plugin/jepcommands/OrCommandTest.java 2007-10-27 02:19:47 UTC (rev 4432) @@ -0,0 +1,172 @@ +/* + * OrCommandTest.java + * Copyright 2007 (C) andrew wilson <nu...@us...> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Created on Oct 26, 2007 + * + * $Id$ + * + */ +package plugin.jepcommands; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.nfunk.jep.ParseException; +import org.nfunk.jep.function.PostfixMathCommandI; +import pcgen.PCGenTestCase; + +import java.util.Stack; + +/** + * <code>OrCommandTest</code> tests the functioning of the jep or plugin + * + * Last Editor: $Author$ + * Last Edited: $Date$ + * + * @author andrew wilson <nu...@us...> + * @version $Revision$ + */ +public class OrCommandTest extends PCGenTestCase +{ + + /** + * Quick test suite creation - adds all methods beginning with "test" + * @return The Test suite + */ + public static Test suite() + { + return new TestSuite(OrCommandTest.class); + } + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception + { + super.setUp(); + + } + + private static boolean runOr(final Stack stack, final PostfixMathCommandI pCommand) + { + boolean b; + try + { + pCommand.run(stack); + b = true; + } + catch (ParseException e) + { + b = false; + } + return b; + } + + /* Test the case where the first operand is true */ + public void testOr01() + { + final PostfixMathCommandI c = new OrCommand(); + final Stack<Object> s = new Stack<Object>(); + + s.push(1.0); + s.push(2.0); + + c.setCurNumberOfParameters(2); + + runOr(s, c); + + final Double result = (Double) s.pop(); + + is(result, eq(1.0, 0.1), "if (1.0,2.0) returns 1.0"); + } + + /* Test the case where the first operand is false, but the second is true */ + public void testOr02() + { + final PostfixMathCommandI c = new OrCommand(); + final Stack<Double> s = new Stack<Double>(); + + s.push(0.0); + s.push(2.0); + + c.setCurNumberOfParameters(2); + + runOr(s, c); + + final Double result = s.pop(); + + is(result, eq(2.0, 0.1), "if (0.0,2.0) returns 2.0"); + } + + /* Test the case where the first two operands are false*/ + public void testOr03() + { + final PostfixMathCommandI c = new OrCommand(); + final Stack<Boolean> s = new Stack<Boolean>(); + + s.push(false); + s.push(false); + s.push(true); + + c.setCurNumberOfParameters(3); + + runOr(s, c); + + final Boolean result = s.pop(); + + is(result, eq(true), "if (false,false,true) returns true"); + } + + /* Test the case where false and zero are skipped */ + public void testOr04() + { + final PostfixMathCommandI c = new OrCommand(); + final Stack s = new Stack(); + + s.push(0.0); + s.push(false); + s.push(true); + + c.setCurNumberOfParameters(3); + + runOr(s, c); + + final Object result = (Boolean) s.pop(); + + is(result, eq(true), "if (0.0,false,true) returns true"); + } + + /* Test the case where false and zero are skipped */ + public void testOr05() + { + final PostfixMathCommandI c = new OrCommand(); + final Stack s = new Stack(); + + s.push(false); + s.push(false); + s.push(false); + s.push(false); + + c.setCurNumberOfParameters(4); + + runOr(s, c); + + final Object result = (Double) s.pop(); + + is(result, eq(0.0), "if (false,false,false,false) returns 0.0"); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nu...@us...> - 2007-10-28 04:01:01
|
Revision: 4447 http://pcgen.svn.sourceforge.net/pcgen/?rev=4447&view=rev Author: nuance Date: 2007-10-27 21:01:05 -0700 (Sat, 27 Oct 2007) Log Message: ----------- Refactoring, moved stuff to more sensible places. Removed some silly redundant methods. Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/AbilityInfo.java Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java Trunk/pcgen/code/src/java/pcgen/core/CategorisableStore.java Trunk/pcgen/code/src/java/pcgen/core/Equipment.java Trunk/pcgen/code/src/java/pcgen/core/EquipmentUtilities.java Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java Trunk/pcgen/code/src/java/pcgen/core/SettingsHandler.java Trunk/pcgen/code/src/java/pcgen/core/bonus/BonusObj.java Trunk/pcgen/code/src/java/pcgen/core/kit/KitProf.java Trunk/pcgen/code/src/java/pcgen/core/utils/CoreUtility.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoGear.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoSkills.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/InfoSpecialAbilities.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/ability/AbilityInfoPanel.java Trunk/pcgen/code/src/java/pcgen/gui/tabs/ability/AbilityModel.java Trunk/pcgen/code/src/java/pcgen/persistence/lst/LstSystemLoader.java Trunk/pcgen/code/src/java/pcgen/persistence/lst/utils/FeatParser.java Trunk/pcgen/code/src/test/pcgen/core/EquipmentUtilitiesTest.java Trunk/pcgen/code/src/test/pcgen/core/utils/CoreUtilityTest.java Added Paths: ----------- Trunk/pcgen/code/src/test/pcgen/core/AbilityUtilitiesTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/AbilityInfo.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/AbilityInfo.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/AbilityInfo.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -44,7 +44,7 @@ protected String category; private Ability realThing; private List<Prerequisite> prereqList; - private ArrayList<String> decorations; + private List<String> decorations; protected char delim = '<'; private static final String split1 = "[<>\\|]"; @@ -95,8 +95,7 @@ { // get the decorations, throw away the name (because we already // have it in keyname) - EquipmentUtilities - .getUndecoratedName(this.keyName, decorations); + AbilityUtilities.getUndecoratedName(this.keyName, decorations); } } Modified: Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/AbilityUtilities.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -24,13 +24,12 @@ package pcgen.core; import pcgen.core.pclevelinfo.PCLevelInfo; +import pcgen.core.utils.CoreUtility; import pcgen.core.utils.ListKey; import pcgen.util.Logging; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; +import java.util.*; /** * General utilities related to the Ability class. @@ -48,14 +47,14 @@ /** * Add the choices in the List to the ability if it is legal to do so. * - * @param ability - * @param choices + * @param ability Ability to add the choices to + * @param choices the iterable collection of choices to add */ private static void addChoicesToAbility( final Ability ability, - final List<String> choices) + final Iterable<String> choices) { - for ( String choice : choices ) + for ( final String choice : choices ) { if (ability.canAddAssociation(choice)) { @@ -114,8 +113,8 @@ final String category, final String abilityName) { - final ArrayList<String> choices = new ArrayList<String>(); - EquipmentUtilities.getUndecoratedName(abilityName, choices); + final Collection<String> choices = new ArrayList<String>(); + getUndecoratedName(abilityName, choices); Ability anAbility = getAbilityFromList(theAbilityList, "FEAT", abilityName, Ability.Nature.ANY); @@ -142,8 +141,8 @@ final AbilityCategory aCategory, final String aKey) { - final ArrayList<String> choices = new ArrayList<String>(); - EquipmentUtilities.getUndecoratedName(aKey, choices); + final Collection<String> choices = new ArrayList<String>(); + getUndecoratedName(aKey, choices); Ability anAbility = getAbilityFromList(anAbilityList, aCategory.getAbilityCategory(), aKey, Ability.Nature.ANY); @@ -218,8 +217,8 @@ final List<Ability> abilityList, final PCLevelInfo levelInfo) { - final ArrayList<String> choices = new ArrayList<String>(); - final String abilityKey = EquipmentUtilities.getUndecoratedName(aFeatKey, choices); + final List<String> choices = new ArrayList<String>(); + final String abilityKey = getUndecoratedName(aFeatKey, choices); final Ability anAbility = Globals.getAbilityKeyed(category, abilityKey); return addVirtualAbility(anAbility, choices, abilityList, levelInfo); @@ -251,10 +250,10 @@ * in brackets) from the name, then check the undecorated names are * equal. */ - final ArrayList<String> decorationsThis = new ArrayList<String>(); - final ArrayList<String> decorationsThat = new ArrayList<String>(); - final String undecoratedThis = EquipmentUtilities.getUndecoratedName(first.getKeyName(), decorationsThis); - final String undecoratedThat = EquipmentUtilities.getUndecoratedName(second.getKeyName(), decorationsThat); + final Collection<String> decorationsThis = new ArrayList<String>(); + final Collection<String> decorationsThat = new ArrayList<String>(); + final String undecoratedThis = getUndecoratedName(first.getKeyName(), decorationsThis); + final String undecoratedThat = getUndecoratedName(second.getKeyName(), decorationsThat); nameCheck = undecoratedThis.compareToIgnoreCase(undecoratedThat) == 0; } else if (multFirst || multSecond) { @@ -330,11 +329,10 @@ final String category, final String anAbilityKey) { - Ability anAbility; - final ArrayList<String> choices = new ArrayList<String>(); - final String baseKey = EquipmentUtilities.getUndecoratedName(anAbilityKey, choices); + final Collection<String> choices = new ArrayList<String>(); + final String baseKey = getUndecoratedName(anAbilityKey, choices); - anAbility = Globals.getAbilityKeyed(category, anAbilityKey); + Ability anAbility = Globals.getAbilityKeyed(category, anAbilityKey); if ((anAbility == null) && (baseKey.length() != 0)) { @@ -676,13 +674,12 @@ aPC.getSpellList(); } - final ArrayList<String> choices = new ArrayList<String>(); - final String undoctoredKey = aFeatKey; - final String baseKey = EquipmentUtilities.getUndecoratedName(aFeatKey, choices); - String subKey = choices.size() > 0 ? choices.get(0) : ""; + final Collection<String> choices = new ArrayList<String>(); + final String baseKey = getUndecoratedName(aFeatKey, choices); + String subKey = choices.size() > 0 ? choices.iterator().next() : ""; // See if our choice is not auto or virtual - Ability anAbility = aPC.getRealFeatKeyed(undoctoredKey); + Ability anAbility = aPC.getRealFeatKeyed(aFeatKey); // if a feat keyed aFeatKey doesn't exist, and aFeatKey // contains a (blah) descriptor, try removing it. @@ -704,7 +701,7 @@ if (anAbility == null) { - anAbility = Globals.getAbilityKeyed("FEAT", undoctoredKey); + anAbility = Globals.getAbilityKeyed("FEAT", aFeatKey); if (anAbility != null) { @@ -714,9 +711,9 @@ if (anAbility == null) { - Logging.errorPrint("Feat not found: " + undoctoredKey); + Logging.errorPrint("Feat not found: " + aFeatKey); - return addIt ? 1 : 0; + return 1; } anAbility = anAbility.clone(); @@ -1104,7 +1101,7 @@ return ability; } - final String stripped = EquipmentUtilities.removeChoicesFromName(token); + final String stripped = removeChoicesFromName(token); ability = Globals.getAbilityKeyed(cat, stripped); if (ability != null) @@ -1127,4 +1124,52 @@ { return SettingsHandler.getGame().getAbilityCategory(aKey); } + + /** + * Extracts the choiceless form of a name, for example, with all choices removed + * + * @param aName + * + * @return the name with sub-choices stripped from it + */ + public static String removeChoicesFromName(String aName) + { + final int anInt = aName.indexOf('('); + + return (anInt >= 0) ? aName.substring(0, anInt).trim() : aName; + } + + /** + * Takes a string of the form "foo (bar, baz)", populates the array with ["bar", "baz"] + * and returns foo. All strings returned by this function have had leading.trailing + * whitespace removed. + * + * @param name The full name with stuff in parenthesis + * @param specifics a list which will contain the specifics after the operation has + * completed + * + * @return the name with sub-choices stripped from it + */ + public static String getUndecoratedName( + final String name, + final Collection<String> specifics) + { + + final String altName = removeChoicesFromName(name); + + specifics.clear(); + final int start = name.indexOf('(') + 1; + final int end = name.lastIndexOf(')'); + + if (start >= 0 && end > start) + { + + // we want what is inside the outermost parenthesis. + final String subName = name.substring(start, end); + + specifics.addAll(CoreUtility.split(subName, ',')); + } + + return altName; + } } Modified: Trunk/pcgen/code/src/java/pcgen/core/CategorisableStore.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/CategorisableStore.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/CategorisableStore.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -203,7 +203,7 @@ return null; } - String strippedName = EquipmentUtilities.removeChoicesFromName(aName); + String strippedName = AbilityUtilities.removeChoicesFromName(aName); while (it.hasNext()) { @@ -407,7 +407,7 @@ return false; } - String strippedName = EquipmentUtilities.removeChoicesFromName(aName); + String strippedName = AbilityUtilities.removeChoicesFromName(aName); while (it.hasNext()) { Modified: Trunk/pcgen/code/src/java/pcgen/core/Equipment.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/Equipment.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/Equipment.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -25,41 +25,22 @@ */ package pcgen.core; -import java.io.BufferedWriter; -import java.io.Serializable; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.StringTokenizer; -import java.util.TreeSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import pcgen.core.bonus.BonusObj; import pcgen.core.character.WieldCategory; import pcgen.core.prereq.PrereqHandler; import pcgen.core.prereq.Prerequisite; -import pcgen.core.utils.CoreUtility; -import pcgen.core.utils.IntegerKey; -import pcgen.core.utils.MessageType; -import pcgen.core.utils.ShowMessageDelegate; -import pcgen.core.utils.StringKey; +import pcgen.core.utils.*; import pcgen.io.FileAccess; -import pcgen.util.BigDecimalHelper; -import pcgen.util.Delta; -import pcgen.util.JEPResourceChecker; -import pcgen.util.Logging; -import pcgen.util.PJEP; -import pcgen.util.PjepPool; -import pcgen.util.PropertyFactory; +import pcgen.util.*; import pcgen.util.enumeration.Load; +import java.io.BufferedWriter; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + /** * <code>Equipment</code>. * @@ -2242,15 +2223,15 @@ removeCommonFromList(list2, comn, "SPROP: eqMod expected but not found: "); - final String common = CoreUtility - .commaDelimit(getSpecialAbilityTimesList(getSpecialAbilityList( - comn, aPC))); - final String saList1 = CoreUtility - .commaDelimit(getSpecialAbilityTimesList(getSpecialAbilityList( - list1, aPC))); - final String saList2 = CoreUtility - .commaDelimit(getSpecialAbilityTimesList(getSpecialAbilityList( - list2, aPC))); + final String common = CoreUtility.join( + getSpecialAbilityTimesList(getSpecialAbilityList(comn, aPC)), + ", "); + final String saList1 = CoreUtility.join( + getSpecialAbilityTimesList(getSpecialAbilityList(list1, aPC)), + ", "); + final String saList2 = CoreUtility.join( + getSpecialAbilityTimesList(getSpecialAbilityList(list2, aPC)), + ", "); final StringBuffer sp = new StringBuffer(); boolean first = true; Modified: Trunk/pcgen/code/src/java/pcgen/core/EquipmentUtilities.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/EquipmentUtilities.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/EquipmentUtilities.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -26,11 +26,7 @@ */ package pcgen.core; -import pcgen.core.utils.CoreUtility; - import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.List; /** @@ -45,135 +41,7 @@ //Don't allow instantiation of utility class } - private static Comparator<Equipment> equipmentComparator = new Comparator<Equipment>() - { - private int compareInts(final int obj1Index, final int obj2Index) - { - if (obj1Index > obj2Index) - { - return 1; - } - else if (obj1Index < obj2Index) - { - return -1; - } - else - { - return 0; - } - } - - public int compare(final Equipment obj1, final Equipment obj2) - { - int o1i = obj1.getOutputIndex(); - int o2i = obj2.getOutputIndex(); - - // Force unset items (index of 0) to appear at the end - o1i = (o1i == 0) ? 999 : o1i; - o2i = (o2i == 0) ? 999 : o2i; - - final int result1 = compareInts(o1i, o2i); - - if (result1 != 0) - { - return result1; - } - - final int result2 = compareInts(obj1.getOutputSubindex(), obj2.getOutputSubindex()); - - if (result2 != 0) - { - return result2; - } - - final int result3 = obj1.getName().compareToIgnoreCase(obj2.getName()); - - if (result3 != 0) - { - return result3; - } - - return obj1.getParentName().compareToIgnoreCase(obj2.getParentName()); - } - - public boolean equals(final Equipment obj) - { - return false; - } - - public int hashCode() - { - return 0; - } - }; - /** - * Merge the equipment list - * - * @param aList the list of Equipment - * @param merge The type of merge to perform - * - * @return merged list - */ - public static List<Equipment> mergeEquipmentList(final List<Equipment> aList, final int merge) - { - Collections.sort(aList, equipmentComparator); - - // no merging, just sorting - if (merge == Constants.MERGE_NONE) - { - return aList; - } - - final List<Equipment> workingList = new ArrayList<Equipment>(); - - // create a temporary list to merge with - for (final Equipment tempEq : aList) - { - workingList.add(tempEq.clone()); - } - - int endIndex = workingList.size(); - - for (int i = 0; i < endIndex; i++) - { - final Equipment eq1 = workingList.get(i); - double eQty = eq1.qty(); - - for (int j = i + 1; j < endIndex; j++) - { - final Equipment eq2 = workingList.get(j); - - // no container merge or Temporary Bonus generated equipment must not merge - if (eq1.isContainer() || eq1.isType("TEMPORARY") || eq2.isType("TEMPORARY")) - { - continue; - } - - if (eq1.getName().equals(eq2.getName())) - { - // merge all like equipment together - if (merge == Constants.MERGE_ALL || - - // merge like equipment within same container - (merge == Constants.MERGE_LOCATION - && (eq1.getLocation() == eq2.getLocation()) - && eq1.getParentName().equals(eq2.getParentName()))) - { - workingList.remove(eq2); - eQty += eq2.qty(); - endIndex--; - } - } - } - - eq1.setQty(eQty); - } - - return workingList; - } - - /** * filters a list of equipment to remove all equipment of a given type * * @param aList the list to remove @@ -253,51 +121,4 @@ return aBuf.toString(); } - - /** - * Extracts the choiceless form of a name, for example, with all choices removed - * - * @param aName - * - * @return the name with sub-choices stripped from it - */ - public static String removeChoicesFromName(String aName) - { - final int anInt = aName.indexOf('('); - - return (anInt >= 0) ? aName.substring(0, anInt).trim() : aName; - } - - - /** - * Takes a string of the form "foo (bar, baz)", populates the array with ["bar", "baz"] - * and returns foo. All strings returned by this function have had leading.trailing - * whitespace removed. - * - * @param name The full name with stuff in parenthesis - * @param specifics a list which will contain the specifics after the operation has - * completed - * - * @return the name with sub-choices stripped from it - */ - public static String getUndecoratedName(final String name, final ArrayList<String> specifics) - { - - final String altName = removeChoicesFromName(name); - - specifics.clear(); - final int start = name.indexOf('(') + 1; - final int end = name.lastIndexOf(')'); - - if (start >= 0 && end > start) - { - - // we want what is inside the outermost parenthesis. - final String subName = name.substring(start, end); - - specifics.addAll(CoreUtility.split(subName, ',')); - } - - return altName; - } } Modified: Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/PlayerCharacter.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -25,40 +25,9 @@ */ package pcgen.core; -import java.awt.geom.Point2D; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Observable; -import java.util.Set; -import java.util.SortedSet; -import java.util.StringTokenizer; -import java.util.TreeMap; -import java.util.TreeSet; - import pcgen.core.bonus.Bonus; import pcgen.core.bonus.BonusObj; -import pcgen.core.character.CharacterSpell; -import pcgen.core.character.CompanionMod; -import pcgen.core.character.EquipSet; -import pcgen.core.character.EquipSlot; -import pcgen.core.character.Follower; -import pcgen.core.character.SpellBook; -import pcgen.core.character.SpellInfo; +import pcgen.core.character.*; import pcgen.core.levelability.LevelAbility; import pcgen.core.pclevelinfo.PCLevelInfo; import pcgen.core.prereq.PrereqHandler; @@ -67,26 +36,23 @@ import pcgen.core.spell.PCSpellTracker; import pcgen.core.spell.Spell; import pcgen.core.system.GameModeRollMethod; -import pcgen.core.utils.CoreUtility; -import pcgen.core.utils.ListKey; -import pcgen.core.utils.MessageType; -import pcgen.core.utils.ShowMessageDelegate; -import pcgen.core.utils.StringKey; +import pcgen.core.utils.*; import pcgen.gui.GuiConstants; import pcgen.io.PCGFile; import pcgen.io.exporttoken.BonusToken; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.prereq.PreParserFactory; -import pcgen.util.Delta; -import pcgen.util.DoubleKeyMap; -import pcgen.util.HashMapToList; -import pcgen.util.Logging; -import pcgen.util.PropertyFactory; +import pcgen.util.*; import pcgen.util.enumeration.AttackType; import pcgen.util.enumeration.Load; import pcgen.util.enumeration.Visibility; import pcgen.util.enumeration.VisionType; +import java.awt.geom.Point2D; +import java.io.*; +import java.math.BigDecimal; +import java.util.*; + /** * <code>PlayerCharacter</code>. * @@ -1511,11 +1477,10 @@ */ public List<Equipment> getEquipmentMasterList() { - final ArrayList<Equipment> aList = new ArrayList<Equipment>( - equipmentMasterList); + final List<Equipment> aList = new ArrayList<Equipment>(equipmentMasterList); // Try all possible POBjects - for (PObject aPObj : getPObjectList()) + for (final PObject aPObj : getPObjectList()) { if (aPObj != null) { @@ -1533,8 +1498,9 @@ */ public List<Equipment> getEquipmentMasterListInOutputOrder() { - return EquipmentUtilities.mergeEquipmentList(getEquipmentMasterList(), - Constants.MERGE_NONE); + final List<Equipment> l = getEquipmentMasterList(); + Collections.sort(l, CoreUtility.equipmentComparator); + return l; } /** @@ -14433,19 +14399,17 @@ * @return An ArrayList of the equipment objects in output order. */ private List<Equipment> sortEquipmentList( - final List<Equipment> unsortedEquipList, final int merge) + final List<Equipment> unsortedEquipList, final int merge) { if (unsortedEquipList.isEmpty()) { return unsortedEquipList; } - final List<Equipment> sortedList; - // Merge list for duplicates // The sorting is done during the Merge - sortedList = EquipmentUtilities.mergeEquipmentList(unsortedEquipList, - merge); + final List<Equipment> sortedList = + CoreUtility.mergeEquipmentList(unsortedEquipList, merge); // Remove the hidden items from the list for (Iterator<Equipment> i = sortedList.iterator(); i.hasNext();) @@ -16718,9 +16682,12 @@ return null; } - public int addAbility(final PCLevelInfo LevelInfo, - final AbilityCategory aCategory, final String aKey, - final boolean addIt, final boolean singleChoice) + public int addAbility( + final PCLevelInfo LevelInfo, + final AbilityCategory aCategory, + final String aKey, + final boolean addIt, + final boolean singleChoice) { boolean singleChoice1 = !singleChoice; if (!isImporting()) @@ -16728,12 +16695,10 @@ getSpellList(); } - final ArrayList<String> choices = new ArrayList<String>(); + final Collection<String> choices = new ArrayList<String>(); final String undoctoredKey = aKey; - final String baseKey = EquipmentUtilities.getUndecoratedName(aKey, - choices); - String subKey = choices.size() > 0 ? choices.get(0) - : Constants.EMPTY_STRING; + final String baseKey = AbilityUtilities.getUndecoratedName(aKey, choices); + String subKey = choices.size() > 0 ? choices.iterator().next() : Constants.EMPTY_STRING; // See if our choice is not auto or virtual Ability anAbility = getRealAbilityKeyed(aCategory, undoctoredKey); Modified: Trunk/pcgen/code/src/java/pcgen/core/SettingsHandler.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/SettingsHandler.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/SettingsHandler.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -1321,9 +1321,9 @@ retractRelativePath(getSelectedPartyPDFOutputSheet())); getOptions().setProperty("pcgen.files.selectedEqSetTemplate", retractRelativePath(getSelectedEqSetTemplate())); //$NON-NLS-1$ getOptions().setProperty("pcgen.files.chosenCampaignSourcefiles", //$NON-NLS-1$ - CoreUtility.join(PersistenceManager.getInstance().getChosenCampaignSourcefiles(), ',')); + CoreUtility.join(PersistenceManager.getInstance().getChosenCampaignSourcefiles(), ", ")); - getOptions().setProperty("pcgen.options.custColumnWidth", CoreUtility.join(Globals.getCustColumnWidth(), ',')); //$NON-NLS-1$ + getOptions().setProperty("pcgen.options.custColumnWidth", CoreUtility.join(Globals.getCustColumnWidth(), ", ")); //$NON-NLS-1$ if (getPcgenCustomDir() != null) { Modified: Trunk/pcgen/code/src/java/pcgen/core/bonus/BonusObj.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/bonus/BonusObj.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/bonus/BonusObj.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -25,22 +25,15 @@ */ package pcgen.core.bonus; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - -import pcgen.core.Constants; -import pcgen.core.Equipment; -import pcgen.core.PObject; -import pcgen.core.PlayerCharacter; -import pcgen.core.PrereqObject; +import pcgen.core.*; import pcgen.core.prereq.Prerequisite; import pcgen.core.utils.CoreUtility; import pcgen.util.Delta; +import java.io.Serializable; +import java.util.*; +import java.util.regex.Pattern; + /** * <code>BonusObj</code> * @@ -1233,7 +1226,9 @@ for (int i = 0; i < anObj.getAssociatedCount(); ++i) { final StringBuffer ab = new StringBuffer(); - final String tName = CoreUtility.replaceFirst(name, VALUE_TOKEN_REPLACEMENT, anObj.getAssociated(i)); + final String tName = + name.replaceFirst(Pattern.quote(VALUE_TOKEN_REPLACEMENT), + anObj.getAssociated(i)); ab.append(tName).append('.'); ab.append(info); @@ -1250,7 +1245,9 @@ for (int i = 0; i < anObj.getAssociatedCount(true); ++i) { final StringBuffer ab = new StringBuffer(); - final String tName = CoreUtility.replaceFirst(info, VALUE_TOKEN_REPLACEMENT, anObj.getAssociated(i, true)); + final String tName = + info.replaceFirst(Pattern.quote(VALUE_TOKEN_REPLACEMENT), + anObj.getAssociated(i, true)); ab.append(getTypeOfBonus()).append('.'); ab.append(tName); Modified: Trunk/pcgen/code/src/java/pcgen/core/kit/KitProf.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/kit/KitProf.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/kit/KitProf.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -22,22 +22,16 @@ */ package pcgen.core.kit; +import pcgen.core.*; +import pcgen.core.utils.CoreUtility; +import pcgen.core.utils.ListKey; + import java.io.Serializable; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; -import pcgen.core.Globals; -import pcgen.core.Kit; -import pcgen.core.PCClass; -import pcgen.core.PObject; -import pcgen.core.PlayerCharacter; -import pcgen.core.Race; -import pcgen.core.WeaponProf; -import pcgen.core.utils.CoreUtility; -import pcgen.core.utils.ListKey; - /** * <code>KitFeat</code>. * @@ -109,7 +103,7 @@ info.append(choiceCount).append(" of "); } - info.append(CoreUtility.joinToStringBuffer(profList, ", ")); + info.append(CoreUtility.join(profList, ", ")); return info.toString(); } Modified: Trunk/pcgen/code/src/java/pcgen/core/utils/CoreUtility.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/utils/CoreUtility.java 2007-10-28 02:36:36 UTC (rev 4446) +++ Trunk/pcgen/code/src/java/pcgen/core/utils/CoreUtility.java 2007-10-28 04:01:05 UTC (rev 4447) @@ -22,13 +22,13 @@ */ package pcgen.core.utils; +import pcgen.core.Constants; +import pcgen.core.Equipment; + import java.io.File; import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; +import java.util.*; +import java.util.regex.Pattern; /** * <code>CoreUtility</code>. @@ -41,6 +41,68 @@ */ public final class CoreUtility { + public static Comparator<Equipment> equipmentComparator = new Comparator<Equipment>() + { + private int compareInts(final int obj1Index, final int obj2Index) + { + if (obj1Index > obj2Index) + { + return 1; + } + else if (obj1Index < obj2Index) + { + return -1; + } + else + { + return 0; + } + } + + public int compare(final Equipment obj1, final Equipment obj2) + { + int o1i = obj1.getOutputIndex(); + int o2i = obj2.getOutputIndex(); + + // Force unset items (index of 0) to appear at the end + o1i = (o1i == 0) ? 999 : o1i; + o2i = (o2i == 0) ? 999 : o2i; + + final int result1 = compareInts(o1i, o2i); + + if (result1 != 0) + { + return result1; + } + + final int result2 = compareInts(obj1.getOutputSubindex(), obj2.getOutputSubindex()); + + if (result2 != 0) + { + return result2; + } + + final int result3 = obj1.getName().compareToIgnoreCase(obj2.getName()); + + if (result3 != 0) + { + return result3; + } + + return obj1.getParentName().compareToIgnoreCase(obj2.getParentName()); + } + + public boolean equals(final Equipment obj) + { + return false; + } + + public int hashCode() + { + return 0; + } + }; + private CoreUtility() { super(); @@ -48,13 +110,12 @@ /** * Converts an array of Objects into a List of Objects - * - * @param <T> - * @param array - * the array to be converted. If this array is null then this - * method will return an empty list; + * + * @param array the array to be converted. If this array is null then this method + * will return an empty list; + * * @return The list containing the objects passed in. - * + * * CONSIDER This should really be eliminated, as the only value over * Arrays.asList is the null check... - thpr 11/3/06 */ @@ -66,10 +127,7 @@ } final List<T> list = new ArrayList<T>(array.length); - for (int i = 0; i < array.length; i++) - { - list.add(array[i]); - } + list.addAll(Arrays.asList(array))... [truncated message content] |
From: <nu...@us...> - 2007-10-28 19:24:43
|
Revision: 4461 http://pcgen.svn.sourceforge.net/pcgen/?rev=4461&view=rev Author: nuance Date: 2007-10-28 12:24:47 -0700 (Sun, 28 Oct 2007) Log Message: ----------- Finish the count("ABILITIES") function Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PObject.java Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java Trunk/pcgen/code/src/test/plugin/jepcommands/CountCommandTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PObject.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2007-10-28 18:54:13 UTC (rev 4460) +++ Trunk/pcgen/code/src/java/pcgen/core/PObject.java 2007-10-28 19:24:47 UTC (rev 4461) @@ -878,7 +878,7 @@ /** * Add the item to the associated list for this object - * @param aString + * @param aString the string to add to the associated list */ public final void addAssociated(final String aString) { Modified: Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java 2007-10-28 18:54:13 UTC (rev 4460) +++ Trunk/pcgen/code/src/java/plugin/jepcommands/CountCommand.java 2007-10-28 19:24:47 UTC (rev 4461) @@ -167,6 +167,7 @@ ab.getDisplayName(), new ArrayList<String>()) : ab.getDisplayName(); + if (!name.equalsIgnoreCase(keyValue[1])) { abIt.remove(); Modified: Trunk/pcgen/code/src/test/plugin/jepcommands/CountCommandTest.java =================================================================== --- Trunk/pcgen/code/src/test/plugin/jepcommands/CountCommandTest.java 2007-10-28 18:54:13 UTC (rev 4460) +++ Trunk/pcgen/code/src/test/plugin/jepcommands/CountCommandTest.java 2007-10-28 19:24:47 UTC (rev 4461) @@ -119,8 +119,10 @@ abArray[1].setMultiples("YES"); + abArray[1].addAssociated("one"); + abArray[1].addAssociated("two"); - for (int i = 0;6 > i;i++) { + for (int i = 0;6 > i;i++) { character.addAbility(featCategory, abArray[i], null); } @@ -142,7 +144,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\")",""), - eq(14.0, 0.1), + eq(15.0, 0.1), "count(\"ABILITIES\")"); } @@ -152,7 +154,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=FEAT\")",""), - eq(6.0, 0.1), + eq(7.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=FEAT\")"); } @@ -203,7 +205,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=FEAT[or]CATEGORY=BARDIC\")",""), - eq(12.0, 0.1), + eq(13.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=FEAT[or]CATEGORY=BARDIC\")"); } @@ -214,7 +216,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=FEAT[or]CATEGORY=BARDIC[or]CATEGORY=CLERICAL\")",""), - eq(14.0, 0.1), + eq(15.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=FEAT[or]CATEGORY=BARDIC[or]CATEGORY=CLERICAL\")"); } @@ -226,7 +228,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"VISIBILITY=DEFAULT\")",""), - eq(8.0, 0.1), + eq(9.0, 0.1), "count(\"ABILITIES\",\"VISIBILITY=DEFAULT\")"); } @@ -267,7 +269,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=FEAT\",\"VISIBILITY=DEFAULT\")",""), - eq(3.0, 0.1), + eq(4.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=FEAT\",\"VISIBILITY=DEFAULT\")"); } @@ -277,7 +279,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"CATEGORY=FEAT[or]CATEGORY=CLERICAL\",\"VISIBILITY=DEFAULT[or]VISIBILITY=OUTPUT_ONLY\")",""), - eq(5.0, 0.1), + eq(6.0, 0.1), "count(\"ABILITIES\",\"CATEGORY=FEAT[or]CATEGORY=CLERICAL\",\"VISIBILITY=DEFAULT[or]VISIBILITY=OUTPUT_ONLY\")"); } @@ -292,7 +294,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"TYPE=Fighter\")",""), - eq(4.0, 0.1), + eq(5.0, 0.1), "count(\"ABILITIES\",\"TYPE=Fighter\")"); } @@ -301,7 +303,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"TYPE=General.Fighter\")", ""), - eq(4.0, 0.1), + eq(5.0, 0.1), "count(\"ABILITIES\",\"TYPE=General.Fighter\")"); } @@ -310,7 +312,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"TYPE=General.Fighter[or]TYPE=Epic\")", ""), - eq(7.0, 0.1), + eq(8.0, 0.1), "count(\"ABILITIES\",\"TYPE=General.Fighter[or]TYPE=Epic\")"); } @@ -369,7 +371,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"NATURE=NORMAL\")",""), - eq(14.0, 0.1), + eq(15.0, 0.1), "count(\"ABILITIES\",\"NATURE=NORMAL\")"); } @@ -392,7 +394,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"NAME=Improved Initiative\")",""), - eq(1.0, 0.1), + eq(2.0, 0.1), "count(\"ABILITIES\",\"NAME=Improved Initiative\")"); } @@ -419,7 +421,7 @@ final PlayerCharacter character = getCharacter(); is(character.getVariableValue("count(\"ABILITIES\",\"NAME=Skill Focus (Profession (Basket weaving))[or]CATEGORY=FEAT\")",""), - eq(6.0, 0.1), + eq(7.0, 0.1), "count(\"ABILITIES\",\"NAME=Skill Focus (Profession (Basket weaving))[or]CATEGORY=FEAT\")"); } @@ -436,6 +438,53 @@ final String s = sB.toString(); - is(character.getVariableValue(s,""), eq(5.0, 0.1), s); + is(character.getVariableValue(s,""), eq(6.0, 0.1), s); } + + public void testCountAbilities30() + { + final PlayerCharacter character = getCharacter(); + + final AbilityCategory gCat = + SettingsHandler.getGame().silentlyGetAbilityCategory("CLERICAL"); + final AbilityCategory useCat = + (gCat == null) ? new AbilityCategory("CLERICAL") : gCat; + + if (useCat != gCat) + { + SettingsHandler.getGame().addAbilityCategory(useCat); + } + + final Ability ab = + TestHelper.makeAbility("Eat Burger", "CLERICAL", "Clerical.General"); + + ab.setMultiples("YES"); + + ab.addAssociated("munch"); + + // now the tests + + final StringBuilder sB = new StringBuilder(100); + + sB.append("count(\"ABILITIES\","); + sB.append("\"NAME=Eat Burger\")"); + + final String s = sB.toString(); + + is(character.getVariableValue(s,""), eq(0.0, 0.1), s + " no choices"); + + character.addAbility(gCat, ab, null); + + is(character.getVariableValue(s,""), eq(1.0, 0.1), s + " one choice"); + + ab.addAssociated("devour"); + character.setDirty(true); + + is(character.getVariableValue(s,""), eq(2.0, 0.1), s + " two choices"); + + ab.addAssociated("nibble"); + character.setDirty(true); + + is(character.getVariableValue(s,""), eq(3.0, 0.1), s + " three choices"); + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jfr...@us...> - 2007-11-17 22:17:10
|
Revision: 4526 http://pcgen.svn.sourceforge.net/pcgen/?rev=4526&view=rev Author: jfrazierjr Date: 2007-11-17 14:17:12 -0800 (Sat, 17 Nov 2007) Log Message: ----------- Please Implement - PREHD Token Cleanup Issue#: 1810508 Modified Paths: -------------- Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreHDParser.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreHDWriter.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreHDTest.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Modified: Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreHDParser.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreHDParser.java 2007-11-17 07:19:30 UTC (rev 4525) +++ Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreHDParser.java 2007-11-17 22:17:12 UTC (rev 4526) @@ -28,11 +28,14 @@ */ package plugin.pretokens.parser; +import java.util.StringTokenizer; + import pcgen.core.prereq.Prerequisite; import pcgen.core.prereq.PrerequisiteOperator; import pcgen.persistence.PersistenceLayerException; import pcgen.persistence.lst.prereq.AbstractPrerequisiteParser; import pcgen.persistence.lst.prereq.PrerequisiteParserInterface; +import pcgen.util.Logging; /** * @author wardc @@ -54,9 +57,101 @@ Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify); + if(formula.contains("MIN") || formula.contains("MAX")) + { + StringTokenizer tok = new StringTokenizer(formula, ","); + Prerequisite maxPrereq = new Prerequisite(); + Prerequisite minPrereq = new Prerequisite(); + boolean hasMin = false; + boolean hasMax = false; + while(tok.hasMoreTokens()) + { + String value = tok.nextToken(); + String[] vals = value.split("="); + if (vals.length !=2) + { + throw new PersistenceLayerException( + "PREHD must be either 'MIN=x', 'MAX=y' or 'MIN=x,MAX=y' where 'x' and 'y' are integers. '" + + formula + "' is not valid. "); + + } + String token = vals[0]; + String hdVal = vals[1]; + try + { + Integer.parseInt(hdVal); + } + catch (NumberFormatException nfe) + { + throw new PersistenceLayerException( + "PREHD must be either 'MIN=x', 'MAX=y' or 'MIN=x,MAX=y' where 'x' and 'y' are integers. '" + + formula + "' is not valid: " + hdVal + + " is not an integer"); + } + if (token.equals("MIN")) + { + minPrereq.setKind("hd"); + minPrereq.setOperator(PrerequisiteOperator.GTEQ); + minPrereq.setOperand(hdVal); + + hasMin = true; + + } + if (token.equals("MAX")) + { + maxPrereq.setKind("hd"); + maxPrereq.setOperator(PrerequisiteOperator.LTEQ); + maxPrereq.setOperand(hdVal); + hasMax = true; + } + } + if (hasMin && hasMax) + { + prereq.setKind(null); // PREMULT + prereq.setOperand("2"); + prereq.addPrerequisite(minPrereq); + prereq.addPrerequisite(maxPrereq); + } + else if (hasMin) + { + prereq = minPrereq; + } + else if(hasMax) + { + prereq = maxPrereq; + } + + + } + else + { + processOldSyntax(formula, prereq); + } + + if (invertResult) + { + prereq.setOperator(prereq.getOperator().invert()); + } + return prereq; + } + + /** + * @param formula + * @param prereq + * @throws PersistenceLayerException + */ + private void processOldSyntax(String formula, Prerequisite prereq) + throws PersistenceLayerException { int plusLoc = formula.indexOf('+'); + + Logging.deprecationPrint("Deprecated use of PREHD found: "); + Logging.deprecationPrint("The PREHD:+ or PREHD:x-y syntax is no longer supported. " + +"The new format is 'MIN=x', 'MAX=y', or 'MIN=x,MAX=y' where x and y are integers. " + +"Passed formala was: " + formula); + if (plusLoc == -1) { + int minusLoc = formula.indexOf('-'); if (minusLoc == -1) { @@ -135,11 +230,5 @@ + " is not an integer"); } } - - if (invertResult) - { - prereq.setOperator(prereq.getOperator().invert()); - } - return prereq; } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreHDWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreHDWriter.java 2007-11-17 07:19:30 UTC (rev 4525) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreHDWriter.java 2007-11-17 22:17:12 UTC (rev 4526) @@ -76,10 +76,17 @@ { writer.write('!'); } - - writer.write("PREHD:"); - writer.write(prereq.getOperand()); - writer.write('+'); + if (prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) + { + writer.write("PREHD:MIN="); + writer.write(prereq.getOperand()); + } + else if(prereq.getOperator().equals(PrerequisiteOperator.LTEQ)) + { + writer.write("PREHD:MAX="); + writer.write(prereq.getOperand()); + } + } catch (IOException e) { @@ -122,8 +129,9 @@ writer.write('!'); } writer.write("PREHD:" + (prereq.isOverrideQualify() ? "Q:":"")); + writer.write("MIN="); writer.write(elementGTEQ.getOperand()); - writer.write('-'); + writer.write(",MAX="); writer.write(elementLTEQ.getOperand()); return true; } Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreHDTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreHDTest.java 2007-11-17 07:19:30 UTC (rev 4525) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreHDTest.java 2007-11-17 22:17:12 UTC (rev 4526) @@ -83,32 +83,32 @@ Prerequisite prereq; final PreParserFactory factory = PreParserFactory.getInstance(); - prereq = factory.parse("PREHD:4+"); + prereq = factory.parse("PREHD:MIN=4"); assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:3+"); + prereq = factory.parse("PREHD:MIN=3"); assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:1-3"); + prereq = factory.parse("PREHD:MIN=1,MAX=3"); assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:3-6"); + prereq = factory.parse("PREHD:MIN=3,MAX=6"); assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:4-7"); + prereq = factory.parse("PREHD:MIN=4,MAX=7"); assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:1-2"); + prereq = factory.parse("PREHD:MIN=1,MAX=2"); assertFalse("Character doesn't have 2 or less HD", PrereqHandler .passes(prereq, character, null)); @@ -137,32 +137,32 @@ Prerequisite prereq; final PreParserFactory factory = PreParserFactory.getInstance(); - prereq = factory.parse("PREHD:4+"); + prereq = factory.parse("PREHD:MIN=4"); assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:3+"); + prereq = factory.parse("PREHD:MIN=3"); assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:1-3"); + prereq = factory.parse("PREHD:MIN=1,MAX=3"); assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:3-6"); + prereq = factory.parse("PREHD:MIN=3,MAX=6"); assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:4-7"); + prereq = factory.parse("PREHD:MIN=4,MAX=7"); assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null)); - prereq = factory.parse("PREHD:1-2"); + prereq = factory.parse("PREHD:MIN=1,MAX=2"); assertFalse("Character doesn't have 2 or less HD", PrereqHandler .passes(prereq, character, null)); Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2007-11-17 07:19:30 UTC (rev 4525) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2007-11-17 22:17:12 UTC (rev 4526) @@ -207,8 +207,8 @@ "PREARMORTYPE:1,TYPE.Exotic", "PREARMORTYPE:1,TYPE.Exotic", "PREARMORTYPE:1,Leather%", "PREARMORTYPE:1,Leather%", "PREARMORTYPE:1,LIST", "PREARMORTYPE:1,LIST", - "PREHD:3+", "PREHD:3+", - "PREHD:3-12", "PREHD:3-12", + "PREHD:MIN=3", "PREHD:MIN=3", + "PREHD:MIN=3,MAX=12", "PREHD:MIN=3,MAX=12", "PREHP:12", "PREHP:12", "PREPOINTBUYMETHOD:Standard", "PREPOINTBUYMETHOD:Standard", "PREPOINTBUYMETHOD:Standard,High-powered", "PREPOINTBUYMETHOD:Standard,High-powered", @@ -312,8 +312,8 @@ "!PRESPELLSCHOOLSUB:Creation,3,2", "!PRESPELLSCHOOLSUB:3,Creation=2", "!PRESPELLSCHOOL:Necromancy,3,2", "!PRESPELLSCHOOL:3,Necromancy=2", "!PRESPELLTYPE:Arcane,4,5", "!PRESPELLTYPE:4,Arcane=5", - "!PREHD:3+", "!PREHD:3+", - "!PREHD:3-12", "!PREHD:3-12", + "PREHD:MIN=3", "PREHD:MIN=3", + "PREHD:MIN=3,MAX=12", "PREHD:MIN=3,MAX=12", "!PRECLASS:1,SPELLCASTER=2", "!PRECLASS:1,SPELLCASTER=2", "!PREAPPLY:ANYPC", "!PREAPPLY:ANYPC", "!PRESPELLTYPE:4,Arcane=5,Divine=2", "!PRESPELLTYPE:4,Arcane=5,Divine=2", @@ -409,7 +409,12 @@ "PRESPELLDESCRIPTOR:4,Mind-Affecting", "", // missing '=' "PRESPELLDESCRIPTOR:4", "", // missing tokens "PREHD:3-12+3", "", // too many tokens - "PREHD:should_be_numeric", "", // too many tokens + "PREHD:should_be_numeric", "", // should me numeric + "PREHD:MIN=x", "", // bad int value + "PREHD:MAX=23asdc", "", // bad int value + "PREHD:MIN=3,MAX=asdf", "", // one bad int value + + "PREVARGT:SneakAttack,Rage,4", "", // invalid # of tokens "PRESTAT:1,S=18", "", // need 3 character attribute "PRESTAT:1,STR", "", // missing '=' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jfr...@us...> - 2007-11-21 14:50:01
|
Revision: 4557 http://pcgen.svn.sourceforge.net/pcgen/?rev=4557&view=rev Author: jfrazierjr Date: 2007-11-21 06:50:01 -0800 (Wed, 21 Nov 2007) Log Message: ----------- Please Implement - PRELEVEL token cleanup Issue#: 1835442 Modified Paths: -------------- Trunk/pcgen/code/src/java/pcgen/core/PCTemplate.java Trunk/pcgen/code/src/java/pcgen/persistence/lst/prereq/PreParserFactory.java Trunk/pcgen/code/src/java/plugin/lsttokens/AbilityLst.java Trunk/pcgen/code/src/java/plugin/lsttokens/DrLst.java Trunk/pcgen/code/src/java/plugin/lsttokens/auto/FeatToken.java Trunk/pcgen/code/src/java/plugin/lsttokens/race/StartfeatsToken.java Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreLevelParser.java Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreLevelWriter.java Trunk/pcgen/code/src/test/pcgen/core/prereq/PreLevelTest.java Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java Modified: Trunk/pcgen/code/src/java/pcgen/core/PCTemplate.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/core/PCTemplate.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/java/pcgen/core/PCTemplate.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -1180,7 +1180,7 @@ try { PreParserFactory factory = PreParserFactory.getInstance(); - r = factory.parse("PRELEVEL:" + aLevel); + r = factory.parse("PRELEVEL:MIN=" + aLevel); } catch (PersistenceLayerException notUsed) { Modified: Trunk/pcgen/code/src/java/pcgen/persistence/lst/prereq/PreParserFactory.java =================================================================== --- Trunk/pcgen/code/src/java/pcgen/persistence/lst/prereq/PreParserFactory.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/java/pcgen/persistence/lst/prereq/PreParserFactory.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -214,7 +214,7 @@ throws PersistenceLayerException { PreParserFactory factory = PreParserFactory.getInstance(); - String preLevelString = "PRELEVEL:" + level; //$NON-NLS-1$ + String preLevelString = "PRELEVEL:MIN=" + level; //$NON-NLS-1$ if (obj instanceof PCClass) { // Classes handle this differently Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/AbilityLst.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/AbilityLst.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/AbilityLst.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -125,7 +125,7 @@ { PreParserFactory factory = PreParserFactory.getInstance(); - String preLevelString = "PRELEVEL:" + anInt; //$NON-NLS-1$ + String preLevelString = "PRELEVEL:MIN=" + anInt; //$NON-NLS-1$ if (anObj instanceof PCClass) { // Classes handle this differently Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/DrLst.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/DrLst.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/DrLst.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -36,7 +36,7 @@ try { PreParserFactory factory = PreParserFactory.getInstance(); - String preLevelString = "PRELEVEL:" + anInt; + String preLevelString = "PRELEVEL:MIN=" + anInt; if (obj instanceof PCClass) { // Classes handle this differently Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/auto/FeatToken.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/auto/FeatToken.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/auto/FeatToken.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -52,7 +52,7 @@ try { PreParserFactory factory = PreParserFactory.getInstance(); - String preLevelString = "PRELEVEL:" + level; //$NON-NLS-1$ + String preLevelString = "PRELEVEL:MIN=" + level; //$NON-NLS-1$ if (target instanceof PCClass) { // Classes handle this differently Modified: Trunk/pcgen/code/src/java/plugin/lsttokens/race/StartfeatsToken.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/lsttokens/race/StartfeatsToken.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/java/plugin/lsttokens/race/StartfeatsToken.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -31,7 +31,7 @@ final PreParserFactory factory = PreParserFactory.getInstance(); final StringBuffer buf = new StringBuffer(); - buf.append("PREMULT:1,[PREHD:MIN=1],[PRELEVEL:1]"); + buf.append("PREMULT:1,[PREHD:MIN=1],[PRELEVEL:MIN=1]"); final Prerequisite prereq = factory.parse(buf.toString()); bon.addPreReq(prereq); Modified: Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreLevelParser.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreLevelParser.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/java/plugin/pretokens/parser/PreLevelParser.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -28,21 +28,147 @@ */ package plugin.pretokens.parser; -import pcgen.persistence.lst.prereq.AbstractPrerequisiteIntegerParser; +import java.util.StringTokenizer; + +import pcgen.core.prereq.Prerequisite; +import pcgen.core.prereq.PrerequisiteOperator; +import pcgen.persistence.PersistenceLayerException; +import pcgen.persistence.lst.prereq.AbstractPrerequisiteParser; import pcgen.persistence.lst.prereq.PrerequisiteParserInterface; +import pcgen.util.Logging; /** * @author wardc - * + * */ -public class PreLevelParser extends AbstractPrerequisiteIntegerParser implements - PrerequisiteParserInterface +public class PreLevelParser extends AbstractPrerequisiteParser implements + PrerequisiteParserInterface { - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see pcgen.persistence.lst.prereq.PrerequisiteParserInterface#kindsHandled() */ public String[] kindsHandled() { - return new String[]{"LEVEL"}; + return new String[] + { "LEVEL" }; } + + public Prerequisite parse(String kind, String formula, + boolean invertResult, boolean overrideQualify) + throws PersistenceLayerException + { + Prerequisite prereq = super.parse(kind, formula, invertResult, + overrideQualify); + + if (formula.contains("MIN") || formula.contains("MAX")) + { + StringTokenizer tok = new StringTokenizer(formula, ","); + Prerequisite maxPrereq = new Prerequisite(); + Prerequisite minPrereq = new Prerequisite(); + boolean hasMin = false; + boolean hasMax = false; + while (tok.hasMoreTokens()) + { + String value = tok.nextToken(); + String[] vals = value.split("="); + if (vals.length != 2) + { + throw new PersistenceLayerException( + "PRELEVEL must be either 'MIN=x', 'MAX=y' or 'MIN=x,MAX=y' where 'x' and 'y' are integers. '" + + formula + "' is not valid. "); + + } + String token = vals[0]; + String hdVal = vals[1]; + try + { + Integer.parseInt(hdVal); + } + catch (NumberFormatException nfe) + { + throw new PersistenceLayerException( + "PRELEVEL must be either 'MIN=x', 'MAX=y' or 'MIN=x,MAX=y' where 'x' and 'y' are integers. '" + + formula + + "' is not valid: " + + hdVal + + " is not an integer"); + } + if (token.equals("MIN")) + { + minPrereq.setKind("level"); + minPrereq.setOperator(PrerequisiteOperator.GTEQ); + minPrereq.setOperand(hdVal); + + hasMin = true; + + } + if (token.equals("MAX")) + { + maxPrereq.setKind("level"); + maxPrereq.setOperator(PrerequisiteOperator.LTEQ); + maxPrereq.setOperand(hdVal); + hasMax = true; + } + } + if (hasMin && hasMax) + { + prereq.setKind(null); // PREMULT + prereq.setOperand("2"); + prereq.addPrerequisite(minPrereq); + prereq.addPrerequisite(maxPrereq); + } + else if (hasMin) + { + prereq = minPrereq; + } + else if (hasMax) + { + prereq = maxPrereq; + } + + } + else + { + processOldSyntax(formula, prereq); + } + + if (invertResult) + { + prereq.setOperator(prereq.getOperator().invert()); + } + return prereq; + } + + /** + * @param formula + * @param prereq + * @throws PersistenceLayerException + */ + private void processOldSyntax(String formula, Prerequisite prereq) + throws PersistenceLayerException + { + + Logging.deprecationPrint("Deprecated use of PRELEVEL found: "); + Logging + .deprecationPrint("The PRELEVEL:x syntax is no longer supported. " + + "The new format is 'MIN=x', 'MAX=y', or 'MIN=x,MAX=y' where x and y are integers. " + + "Passed formala was: " + formula); + + try + { + int min = Integer.parseInt(formula); + prereq.setKind("level"); + prereq.setOperand(Integer.toString(min)); + prereq.setOperator(PrerequisiteOperator.GTEQ); + } + catch (NumberFormatException nfe) + { + throw new PersistenceLayerException( + "PRELEVEL must be 'x' where 'x' is an integer. '" + formula + + "' is not valid: " + formula + + " is not an integer"); + } + } } Modified: Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreLevelWriter.java =================================================================== --- Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreLevelWriter.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/java/plugin/pretokens/writer/PreLevelWriter.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -36,6 +36,7 @@ import java.io.IOException; import java.io.Writer; +import java.util.List; public class PreLevelWriter extends AbstractPrerequisiteWriter implements PrerequisiteWriterInterface @@ -55,7 +56,7 @@ public PrerequisiteOperator[] operatorsHandled() { return new PrerequisiteOperator[]{PrerequisiteOperator.GTEQ, - PrerequisiteOperator.LT}; + PrerequisiteOperator.LT, PrerequisiteOperator.LTEQ,PrerequisiteOperator.GT}; } /* (non-Javadoc) @@ -71,15 +72,76 @@ if (prereq.getOperator().equals(PrerequisiteOperator.LT)) { writer.write('!'); + writer.write("PRELEVEL:" + (prereq.isOverrideQualify() ? "Q:":"") + "MIN="); + writer.write(prereq.getOperand()); } + else if(prereq.getOperator().equals(PrerequisiteOperator.GT)) + { + writer.write('!'); + writer.write("PRELEVEL:" + (prereq.isOverrideQualify() ? "Q:":"") + "MAX="); + writer.write(prereq.getOperand()); + } + else if (prereq.getOperator().equals(PrerequisiteOperator.GTEQ)) + { + writer.write("PRELEVEL:" + (prereq.isOverrideQualify() ? "Q:":"") + "MIN="); + writer.write(prereq.getOperand()); + } + else if(prereq.getOperator().equals(PrerequisiteOperator.LTEQ)) + { + writer.write("PRELEVEL:" + (prereq.isOverrideQualify() ? "Q:":"") + "MAX="); + writer.write(prereq.getOperand()); + } - writer.write("PRELEVEL:" + (prereq.isOverrideQualify() ? "Q:":"")); - writer.write(prereq.getOperand()); } catch (IOException e) { throw new PersistenceLayerException(e.getMessage()); } } + /* (non-Javadoc) + * @see pcgen.persistence.lst.output.prereq.AbstractPrerequisiteWriter#specialCase(java.io.Writer writer, pcgen.core.prereq.Prerequisite prereq) + */ + @Override + public boolean specialCase(Writer writer, Prerequisite prereq) + throws IOException + { + // + // If this is a PREMULT... + // + if (prereq.getKind() == null) + { + // + // ...with exactly 2 entries... + // + List<Prerequisite> prereqList = prereq.getPrerequisites(); + if (prereqList.size() == 2) + { + // + // ...both of which are PREHD. The first must specify >= and the second <= + // + final Prerequisite elementGTEQ = prereqList.get(0); + final Prerequisite elementLTEQ = prereqList.get(1); + if ("level".equalsIgnoreCase(elementGTEQ.getKind()) + && elementGTEQ.getOperator().equals( + PrerequisiteOperator.GTEQ) + && "level".equalsIgnoreCase(elementLTEQ.getKind()) + && elementLTEQ.getOperator().equals( + PrerequisiteOperator.LTEQ)) + { + if (prereq.getOperator().equals(PrerequisiteOperator.LT)) + { + writer.write('!'); + } + writer.write("PRELEVEL:" + (prereq.isOverrideQualify() ? "Q:":"")); + writer.write("MIN="); + writer.write(elementGTEQ.getOperand()); + writer.write(",MAX="); + writer.write(elementLTEQ.getOperand()); + return true; + } + } + } + return false; + } } Modified: Trunk/pcgen/code/src/test/pcgen/core/prereq/PreLevelTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/core/prereq/PreLevelTest.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/test/pcgen/core/prereq/PreLevelTest.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -75,15 +75,42 @@ Prerequisite prereq; final PreParserFactory factory = PreParserFactory.getInstance(); - prereq = factory.parse("PRELEVEL:2"); - + prereq = factory.parse("PRELEVEL:MIN=2"); assertFalse("Character is not 2nd level", PrereqHandler.passes(prereq, character, null)); - + character.incrementClassLevel(1, myClass, true); assertTrue("Character has 2 levels", PrereqHandler.passes(prereq, character, null)); + + character.incrementClassLevel(1, myClass, true); + prereq = factory.parse("PRELEVEL:MIN=2,MAX=3"); + assertTrue("Character is 2nd or 3rd level", PrereqHandler.passes(prereq, + character, null)); + + character.incrementClassLevel(1, myClass, true); + assertFalse("Character is not 2nd or 3rd level", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PRELEVEL:MIN=2,MAX=3"); + assertTrue("Character is 2nd or 3rd level", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PRELEVEL:MIN=4"); + assertFalse("Character is 4 or higher level", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PRELEVEL:MAX=3"); + assertTrue("Character is 3rd or higher level", PrereqHandler.passes(prereq, + character, null)); + + + + + + + } /** @@ -101,8 +128,7 @@ final PreParserFactory factory = PreParserFactory.getInstance(); - prereq = factory.parse("PRELEVEL:4"); - + prereq = factory.parse("PRELEVEL:MIN=4"); assertFalse("Character doesn't have 4 levels", PrereqHandler.passes( prereq, character, null)); @@ -110,6 +136,37 @@ assertTrue("Character has 4 levels", PrereqHandler.passes(prereq, character, null)); + + prereq = factory.parse("!PRELEVEL:MIN=5"); + assertTrue("Character doesn't have 5 or more levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("!PRELEVEL:MAX=3"); + assertTrue("Character doesn't have 3 or more levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("!PRELEVEL:MIN=6,MAX=7"); + assertTrue("Character doesn't have between 6 and 7 levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("PRELEVEL:MIN=4,MAX=6"); + assertTrue("Character doesn't have 4-6 levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("PRELEVEL:MIN=6,MAX=7"); + assertFalse("Character doesn't have 6-7 levels", PrereqHandler.passes( + prereq, character, null)); + + prereq = factory.parse("PRELEVEL:MAX=7"); + assertTrue("Character has no more than 5 levels", PrereqHandler.passes( + prereq, character, null)); + + character.incrementClassLevel(4, myClass, true); + prereq = factory.parse("PRELEVEL:MAX=7"); + assertFalse("Character has no more than 7 levels", PrereqHandler.passes( + prereq, character, null)); + + } /** @@ -129,7 +186,7 @@ final PreParserFactory factory = PreParserFactory.getInstance(); - prereq = factory.parse("PRELEVEL:6"); + prereq = factory.parse("PRELEVEL:MIN=6"); final BonusObj levelBonus = Bonus.newBonus("PCLEVEL|MY_CLASS|2"); levelBonus.setCreatorObject(myClass); @@ -138,6 +195,33 @@ assertFalse("Character has only 4 levels", PrereqHandler.passes(prereq, character, null)); + + + prereq = factory.parse("PRELEVEL:MAX=6"); + assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PRELEVEL:MAX=6"); + assertFalse("Character is less than 6 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PRELEVEL:MIN=5"); + assertTrue("Character has only 4 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("PRELEVEL:MIN=4,MAX=6"); + assertTrue("Character has 4-6 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("PRELEVEL:MIN=6,MAX=8"); + assertFalse("Character does not have 6-8 levels", PrereqHandler.passes(prereq, + character, null)); + + prereq = factory.parse("!PRELEVEL:MIN=6,MAX=8"); + assertTrue("Character is not 6-8 levels", PrereqHandler.passes(prereq, + character, null)); + + } protected void setUp() throws Exception Modified: Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java =================================================================== --- Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2007-11-21 08:19:31 UTC (rev 4556) +++ Trunk/pcgen/code/src/test/pcgen/persistence/lst/output/prereq/PrerequisiteWriterTest.java 2007-11-21 14:50:01 UTC (rev 4557) @@ -145,7 +145,9 @@ "PRELANG:2,Dwarven,Elven,Halfling", "PREMULT:2,[PRELANG:1,Dwarven],[PRELANG:1,Elven],[PRELANG:1,Halfling]", "PRELANG:3,ANY", "PRELANG:3,ANY", "PRELEGSGTEQ:4", "PRELEGSGTEQ:4", - "PRELEVEL:5", "PRELEVEL:5", + "PRELEVEL:MIN=5", "PRELEVEL:MIN=5", + "PRELEVEL:MAX=5", "PRELEVEL:MAX=5", + "PRELEVEL:MIN=4,MAX=5", "PRELEVEL:MIN=4,MAX=5", "PRELEVELMAX:10", "PRELEVELMAX:10", "PREMOVE:Walk=30,Fly=20", "PREMULT:1,[PREMOVE:1,Walk=30],[PREMOVE:1,Fly=20]", "PREMOVE:Swim=10", "PREMOVE:1,Swim=10", @@ -280,7 +282,11 @@ "!PREDEITY:Y", "!PREDEITY:1,Y", "!PREITEM:1,Sword (Long)", "!PREITEM:1,Sword (Long)", "!PRELEVELMAX:10", "!PRELEVELMAX:10", - "!PRELEVEL:5", "!PRELEVEL:5", + "!PRELEVEL:4", "!PRELEVEL:MIN=4", // New syntax... + "!PRELEVEL:MIN=4", "!PRELEVEL:MIN=4", + "!PRELEVEL:MAX=4", "!PRELEVEL:MAX=4", + "!PRELEVEL:MIN=4,MAX=6", "!PRELEVEL:MIN=4,MAX=6", + "!PREREGION:Slithe", "!PREREGION:Slithe", "!PRERULE:SYS_WTPSK", "!PRERULE:1,SYS_WTPSK", "!PRESHIELDPROF:1,Buckler", "!PRESHIELDPROF:1,Buckler", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |