From: <aki...@us...> - 2009-12-03 20:59:34
|
Revision: 7304 http://gridarta.svn.sourceforge.net/gridarta/?rev=7304&view=rev Author: akirschbaum Date: 2009-12-03 20:59:23 +0000 (Thu, 03 Dec 2009) Log Message: ----------- Move AttributeListUtils to archetype package. Modified Paths: -------------- trunk/src/app/net/sf/gridarta/gui/gameobjecttexteditor/GameObjectTextEditor.java trunk/src/app/net/sf/gridarta/model/archetype/AbstractArchetypeParser.java Added Paths: ----------- trunk/src/app/net/sf/gridarta/model/archetype/AttributeListUtils.java trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java Removed Paths: ------------- trunk/src/app/net/sf/gridarta/model/gameobject/AttributeListUtils.java trunk/src/test/net/sf/gridarta/model/gameobject/AttributeListUtilsTest.java Modified: trunk/src/app/net/sf/gridarta/gui/gameobjecttexteditor/GameObjectTextEditor.java =================================================================== --- trunk/src/app/net/sf/gridarta/gui/gameobjecttexteditor/GameObjectTextEditor.java 2009-12-03 20:49:33 UTC (rev 7303) +++ trunk/src/app/net/sf/gridarta/gui/gameobjecttexteditor/GameObjectTextEditor.java 2009-12-03 20:59:23 UTC (rev 7304) @@ -29,7 +29,7 @@ import javax.swing.text.MutableAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; -import net.sf.gridarta.model.gameobject.AttributeListUtils; +import net.sf.gridarta.model.archetype.AttributeListUtils; import net.sf.gridarta.model.gameobject.GameObject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; Modified: trunk/src/app/net/sf/gridarta/model/archetype/AbstractArchetypeParser.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/archetype/AbstractArchetypeParser.java 2009-12-03 20:49:33 UTC (rev 7303) +++ trunk/src/app/net/sf/gridarta/model/archetype/AbstractArchetypeParser.java 2009-12-03 20:59:23 UTC (rev 7304) @@ -32,7 +32,6 @@ import net.sf.gridarta.model.errorview.ErrorViewCategory; import net.sf.gridarta.model.errorview.ErrorViewCollector; import net.sf.gridarta.model.gameobject.ArchetypeCollector; -import net.sf.gridarta.model.gameobject.AttributeListUtils; import net.sf.gridarta.model.gameobject.GameObject; import net.sf.gridarta.model.io.PathManager; import net.sf.gridarta.model.map.maparchobject.MapArchObject; Copied: trunk/src/app/net/sf/gridarta/model/archetype/AttributeListUtils.java (from rev 7302, trunk/src/app/net/sf/gridarta/model/gameobject/AttributeListUtils.java) =================================================================== --- trunk/src/app/net/sf/gridarta/model/archetype/AttributeListUtils.java (rev 0) +++ trunk/src/app/net/sf/gridarta/model/archetype/AttributeListUtils.java 2009-12-03 20:59:23 UTC (rev 7304) @@ -0,0 +1,112 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.model.archetype; + +import net.sf.gridarta.model.gameobject.GameObject; +import net.sf.gridarta.utils.StringUtils; +import org.jetbrains.annotations.NotNull; + +/** + * Utility class for archetype attribute related functions. + * @author Andreas Kirschbaum + */ +public class AttributeListUtils { + + /** + * Private constructor to prevent instantiation. + */ + private AttributeListUtils() { + } + + /** + * Removes an attribute from an attribute list. + * @param attributeList the attribute list to modify + * @param key the attribute key to remove + * @return the attribute list with the given key removed + */ + public static String removeAttribute(@NotNull final String attributeList, @NotNull final String key) { + if (attributeList.length() <= 0) { + return attributeList; + } + + final String prefix = key + " "; + + final String[] lines = StringUtils.PATTERN_END_OF_LINE.split(attributeList, -1); + + final StringBuilder sb = new StringBuilder(); + for (final String line : lines) { + if (line.length() > 0 && !line.startsWith(prefix)) { + sb.append(line); + sb.append('\n'); + } + } + return sb.toString(); + } + + /** + * Returns all attributes from the given game object that don't exist in an + * archetype. Ignores the values; compares only keys. + * @param gameObject the game object + * @param archetype the archetype + * @return all attributes from the archetype that don't occur in the game + * object + */ + @NotNull + public static String diffArchTextKeys(@NotNull final GameObject<?, ?, ?> gameObject, @NotNull final Archetype<?, ?, ?> archetype) { + final CharSequence oldObjectText = gameObject.getObjectText(); + final StringBuilder result = new StringBuilder(); + for (final String line : StringUtils.PATTERN_END_OF_LINE.split(archetype.getObjectText(), 0)) { + final int spaceIndex = line.indexOf(' '); + if (line.length() > 0 && spaceIndex > 0 && StringUtils.diffTextString(oldObjectText, line.substring(0, spaceIndex + 1), true) == null) { + result.append(line).append('\n'); + } + } + return result.toString(); + } + + /** + * Get all entries from the given attributes that don't exist in an + * archetype. + * @param attributes the attributes + * @param archetype the game object + * @return All lines from 'atxt' that don't occur in this GameObject. + */ + @NotNull + public static String diffArchTextValues(@NotNull final Archetype<?, ?, ?> archetype, @NotNull final CharSequence attributes) { + final CharSequence oldObjectText = archetype.getObjectText(); + final StringBuilder result = new StringBuilder(); + for (final String line : StringUtils.PATTERN_END_OF_LINE.split(attributes, 0)) { + try { + final CharSequence test = StringUtils.diffTextString(oldObjectText, line, false); + char c = '\n'; + if (test != null) { + c = test.charAt(0); + } + if (line.length() > 0 && (test == null || c == '\n')) { + result.append(line).append('\n'); + } + } catch (final StringIndexOutOfBoundsException e) { + // ignore + } + } + return result.toString(); + } + +} // class AttributeListUtils Property changes on: trunk/src/app/net/sf/gridarta/model/archetype/AttributeListUtils.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/src/app/net/sf/gridarta/model/gameobject/AttributeListUtils.java =================================================================== --- trunk/src/app/net/sf/gridarta/model/gameobject/AttributeListUtils.java 2009-12-03 20:49:33 UTC (rev 7303) +++ trunk/src/app/net/sf/gridarta/model/gameobject/AttributeListUtils.java 2009-12-03 20:59:23 UTC (rev 7304) @@ -1,112 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.model.gameobject; - -import net.sf.gridarta.model.archetype.Archetype; -import net.sf.gridarta.utils.StringUtils; -import org.jetbrains.annotations.NotNull; - -/** - * Utility class for archetype attribute related functions. - * @author Andreas Kirschbaum - */ -public class AttributeListUtils { - - /** - * Private constructor to prevent instantiation. - */ - private AttributeListUtils() { - } - - /** - * Removes an attribute from an attribute list. - * @param attributeList the attribute list to modify - * @param key the attribute key to remove - * @return the attribute list with the given key removed - */ - public static String removeAttribute(@NotNull final String attributeList, @NotNull final String key) { - if (attributeList.length() <= 0) { - return attributeList; - } - - final String prefix = key + " "; - - final String[] lines = StringUtils.PATTERN_END_OF_LINE.split(attributeList, -1); - - final StringBuilder sb = new StringBuilder(); - for (final String line : lines) { - if (line.length() > 0 && !line.startsWith(prefix)) { - sb.append(line); - sb.append('\n'); - } - } - return sb.toString(); - } - - /** - * Returns all attributes from the given game object that don't exist in an - * archetype. Ignores the values; compares only keys. - * @param gameObject the game object - * @param archetype the archetype - * @return all attributes from the archetype that don't occur in the game - * object - */ - @NotNull - public static String diffArchTextKeys(@NotNull final GameObject<?, ?, ?> gameObject, @NotNull final Archetype<?, ?, ?> archetype) { - final CharSequence oldObjectText = gameObject.getObjectText(); - final StringBuilder result = new StringBuilder(); - for (final String line : StringUtils.PATTERN_END_OF_LINE.split(archetype.getObjectText(), 0)) { - final int spaceIndex = line.indexOf(' '); - if (line.length() > 0 && spaceIndex > 0 && StringUtils.diffTextString(oldObjectText, line.substring(0, spaceIndex + 1), true) == null) { - result.append(line).append('\n'); - } - } - return result.toString(); - } - - /** - * Get all entries from the given attributes that don't exist in an - * archetype. - * @param attributes the attributes - * @param archetype the game object - * @return All lines from 'atxt' that don't occur in this GameObject. - */ - @NotNull - public static String diffArchTextValues(@NotNull final Archetype<?, ?, ?> archetype, @NotNull final CharSequence attributes) { - final CharSequence oldObjectText = archetype.getObjectText(); - final StringBuilder result = new StringBuilder(); - for (final String line : StringUtils.PATTERN_END_OF_LINE.split(attributes, 0)) { - try { - final CharSequence test = StringUtils.diffTextString(oldObjectText, line, false); - char c = '\n'; - if (test != null) { - c = test.charAt(0); - } - if (line.length() > 0 && (test == null || c == '\n')) { - result.append(line).append('\n'); - } - } catch (final StringIndexOutOfBoundsException e) { - // ignore - } - } - return result.toString(); - } - -} // class AttributeListUtils Copied: trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java (from rev 7296, trunk/src/test/net/sf/gridarta/model/gameobject/AttributeListUtilsTest.java) =================================================================== --- trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java (rev 0) +++ trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java 2009-12-03 20:59:23 UTC (rev 7304) @@ -0,0 +1,58 @@ +/* + * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. + * Copyright (C) 2000-2007 The Gridarta Developers. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package net.sf.gridarta.model.archetype; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for {@link AttributeListUtils}. + * @author Andreas Kirschbaum + */ +@SuppressWarnings({ "FeatureEnvy" }) +// This is a test. It has feature envy by definition. +public class AttributeListUtilsTest { + + /** Test case for {@link AttributeListUtils#removeAttribute(String, String)}. */ + @Test + public void testRemoveAttribute() { + checkRemoveAttribute("", "abc", ""); + + checkRemoveAttribute("abc def\n", "abc", ""); + checkRemoveAttribute("abc def\n", "ab", "abc def\n"); + checkRemoveAttribute("abc def\n", "abcd", "abc def\n"); + + checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "abc", "ghi jkl\nmno pqr\n"); + checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "def", "abc def\nghi jkl\nmno pqr\n"); + checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "ghi", "abc def\nmno pqr\n"); + checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "mno", "abc def\nghi jkl\n"); + + checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "Abc", "abc def\nghi jkl\nmno pqr\n"); + + checkRemoveAttribute("abc def\n\nghi jkl\n\n", "xyz", "abc def\nghi jkl\n"); + checkRemoveAttribute("\n\nabc def\n\n", "ghi", "abc def\n"); + checkRemoveAttribute("\n\nabc def\n\n", "abc", ""); + } + + private static void checkRemoveAttribute(final String attributeList, final String key, final String expectedResult) { + Assert.assertEquals(expectedResult, AttributeListUtils.removeAttribute(attributeList, key)); + } + +} // class AttributeListUtilsTest Property changes on: trunk/src/test/net/sf/gridarta/model/archetype/AttributeListUtilsTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Added: svn:eol-style + LF Deleted: trunk/src/test/net/sf/gridarta/model/gameobject/AttributeListUtilsTest.java =================================================================== --- trunk/src/test/net/sf/gridarta/model/gameobject/AttributeListUtilsTest.java 2009-12-03 20:49:33 UTC (rev 7303) +++ trunk/src/test/net/sf/gridarta/model/gameobject/AttributeListUtilsTest.java 2009-12-03 20:59:23 UTC (rev 7304) @@ -1,58 +0,0 @@ -/* - * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. - * Copyright (C) 2000-2007 The Gridarta Developers. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -package net.sf.gridarta.model.gameobject; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Test for {@link AttributeListUtils}. - * @author Andreas Kirschbaum - */ -@SuppressWarnings({ "FeatureEnvy" }) -// This is a test. It has feature envy by definition. -public class AttributeListUtilsTest { - - /** Test case for {@link AttributeListUtils#removeAttribute(String, String)}. */ - @Test - public void testRemoveAttribute() { - checkRemoveAttribute("", "abc", ""); - - checkRemoveAttribute("abc def\n", "abc", ""); - checkRemoveAttribute("abc def\n", "ab", "abc def\n"); - checkRemoveAttribute("abc def\n", "abcd", "abc def\n"); - - checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "abc", "ghi jkl\nmno pqr\n"); - checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "def", "abc def\nghi jkl\nmno pqr\n"); - checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "ghi", "abc def\nmno pqr\n"); - checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "mno", "abc def\nghi jkl\n"); - - checkRemoveAttribute("abc def\nghi jkl\nmno pqr\n", "Abc", "abc def\nghi jkl\nmno pqr\n"); - - checkRemoveAttribute("abc def\n\nghi jkl\n\n", "xyz", "abc def\nghi jkl\n"); - checkRemoveAttribute("\n\nabc def\n\n", "ghi", "abc def\n"); - checkRemoveAttribute("\n\nabc def\n\n", "abc", ""); - } - - private static void checkRemoveAttribute(final String attributeList, final String key, final String expectedResult) { - Assert.assertEquals(expectedResult, AttributeListUtils.removeAttribute(attributeList, key)); - } - -} // class AttributeListUtilsTest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |