diff --git a/.gitattributes b/.gitattributes index 76a450ca1ea..3d4e8849c6b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12922,6 +12922,7 @@ src/main/java/forge/util/StorageReaderFolder.java -text src/main/java/forge/util/StorageView.java -text src/main/java/forge/util/TextUtil.java -text src/main/java/forge/util/ThreadUtil.java svneol=native#text/plain +src/main/java/forge/util/TreeProperties.java svneol=native#text/plain src/main/java/forge/util/XmlUtil.java -text src/main/java/forge/util/package-info.java -text src/main/java/forge/view/ButtonUtil.java svneol=native#text/plain @@ -12944,12 +12945,6 @@ src/main/java/forge/view/arcane/util/ImageUtil.java svneol=native#text/plain src/main/java/forge/view/arcane/util/UI.java svneol=native#text/plain src/main/java/forge/view/arcane/util/package-info.java svneol=native#text/plain src/main/java/forge/view/package-info.java svneol=native#text/plain -src/main/java/tree/properties/PropertyElement.java svneol=native#text/plain -src/main/java/tree/properties/PropertyType.java svneol=native#text/plain -src/main/java/tree/properties/TreeProperties.java svneol=native#text/plain -src/main/java/tree/properties/package-info.java svneol=native#text/plain -src/main/java/tree/properties/types/FileType.java svneol=native#text/plain -src/main/java/tree/properties/types/package-info.java svneol=native#text/plain src/main/resources/proxy-template.ftl -text src/site/apt/index.apt -text src/test/java/forge/BoosterDraft1Test.java svneol=native#text/plain diff --git a/src/main/java/forge/properties/ForgeProps.java b/src/main/java/forge/properties/ForgeProps.java index 2151d9151a1..b04ef164eee 100644 --- a/src/main/java/forge/properties/ForgeProps.java +++ b/src/main/java/forge/properties/ForgeProps.java @@ -27,8 +27,8 @@ import java.io.File; import java.io.IOException; import java.util.Locale; -import tree.properties.TreeProperties; import forge.error.ErrorViewer; +import forge.util.TreeProperties; /** * The class ForgeProps. Wrapper around TreeProperties to support the uses in @@ -56,7 +56,7 @@ public class ForgeProps { /** * Returns the tree properties of forge. * - * @return a {@link tree.properties.TreeProperties} object. + * @return a {@link forge.util.TreeProperties} object. */ public static TreeProperties getProperties() { return ForgeProps.PROPERTIES; diff --git a/src/main/java/tree/properties/TreeProperties.java b/src/main/java/forge/util/TreeProperties.java similarity index 78% rename from src/main/java/tree/properties/TreeProperties.java rename to src/main/java/forge/util/TreeProperties.java index 14e9d958093..98418b1e074 100644 --- a/src/main/java/tree/properties/TreeProperties.java +++ b/src/main/java/forge/util/TreeProperties.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package tree.properties; +package forge.util; /** * TreeProperties.java @@ -33,15 +33,14 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.NoSuchElementException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.Properties; import java.util.Set; -import tree.properties.types.FileType; /** * The class TreeProperties. This class allows for a tree-like structure of @@ -112,8 +111,8 @@ import tree.properties.types.FileType; * @author Clemens Koza * @version V0.0 19.08.2009 * @see Properties - */ -public class TreeProperties implements Iterable { + */ +public class TreeProperties /* implements Iterable */{ /** Constant suffixes. */ private static final Map> SUFFIXES; /** Constant types. */ @@ -328,7 +327,7 @@ public class TreeProperties implements Iterable { * * @param key * a {@link java.lang.String} object. - * @return a {@link tree.properties.TreeProperties} object. + * @return a {@link forge.util.TreeProperties} object. */ public final TreeProperties getChildProperties(final String key) { return (TreeProperties) getProperty(key, "--" + CHILD, true); @@ -339,7 +338,7 @@ public class TreeProperties implements Iterable { * * @param key * a {@link java.lang.String} object. - * @return a {@link tree.properties.TreeProperties} object. + * @return a {@link forge.util.TreeProperties} object. */ public final TreeProperties getTransparentProperties(final String key) { return (TreeProperties) getProperty(key, "--" + TRANSPARENT, true); @@ -426,115 +425,107 @@ public class TreeProperties implements Iterable { return null; } - /** - * Returns an iterator over all the regular entries of this object. That - * means that transparent or child tree properties are not included. - * - * @return a {@link java.util.Iterator} object. - */ - @Override - public final Iterator iterator() { - return iterator(""); - }; + public interface PropertyType { + /** + * The suffix, not including "--", that identifies this content type. + * + * @return a {@link java.lang.String} object. + */ + String getSuffix(); - /** - *

- * iterator. - *

- * - * @param prefix - * a {@link java.lang.String} object. - * @return a {@link tree.properties.TreeProperties.TreePropertiesIterator} - * object. - */ - private TreePropertiesIterator iterator(final String prefix) { - return new TreePropertiesIterator(prefix); - } + /** + * The class that identifies this content type. + * + * @return a {@link java.lang.Class} object. + */ + Class getType(); - private final class TreePropertiesIterator implements Iterator { - private final String prefix; - private Iterator> entries; - private TreePropertiesIterator child; - private PropertyElement next; + /** + * Returns an object for the specified value, in the context of a + * TreeProperties. + * + * @param p + * a {@link forge.util.TreeProperties} object. + * @param s + * a {@link java.lang.String} object. + * @return a T object. + */ + T toObject(TreeProperties p, String s); + } + + public static class FileType implements PropertyType { + /** Constant suffix="file". */ + public static final String SUFFIX = "file"; + /** Constant type. */ + public static final Class TYPE = File.class; - private TreePropertiesIterator(final String prefix) { - entries = properties.entrySet().iterator(); - this.prefix = prefix; + /** + *

+ * Getter for the field suffix. + *

+ * + * @return a {@link java.lang.String} object. + */ + @Override + public final String getSuffix() { + return SUFFIX; } - // After this call, the next element is determined, or the child - // iterator has next - + /** + *

+ * Getter for the field type. + *

+ * + * @return a {@link java.lang.Class} object. + */ @Override - public boolean hasNext() { - if (next != null) { - return true; - } else if (child != null && child.hasNext()) { - return true; - } else if (entries.hasNext()) { - Entry entry = entries.next(); - final String[] parts = entry.getKey().split("--"); - final Class cls; - final Object value = entry.getValue(); + public final Class getType() { + return TYPE; + } - if (parts.length == 1) { - cls = String.class; - } else if (parts[1].equals(TRANSPARENT)) { - child = ((TreeProperties) entry.getValue()).iterator(prefix); - // recursive, for the case that the child iterator is empty - return hasNext(); - } else if (parts[1].equals(TreeProperties.CHILD)) { - child = ((TreeProperties) entry.getValue()).iterator(prefix + parts[0] + "/"); - // recursive, for the case that the child iterator is empty - return hasNext(); + /** {@inheritDoc} */ + @Override + public final File toObject(final TreeProperties p, final String s) { + String path = getPath(s); + File f = new File(path); + if (f.isAbsolute()) { + return f; + } else { + return new File(p.getPath(), path); + } + } + + /** + * Returns a path path from a property value. Three substitutions are + * applied: + *
    + *
  • A "~/" or "~\" at the beginning is replaced with the user's home + * directory
  • + *
  • A "$$" anywhere is replaced with a single "$"
  • + *
  • A "${*}", where * is any string without "}", is replaced by + * + * @param s a {@link java.lang.String} object. + * @return a {@link java.lang.String} object. + * {@link System#getProperty(String)}
  • + *
+ */ + public static String getPath(String s) { + if (s.startsWith("~/")) { + s = System.getProperty("user.home") + "/" + s.substring(2); + } else if (s.startsWith("~\\")) { + s = System.getProperty("user.home") + "\\" + s.substring(2); + } + Matcher m = Pattern.compile("\\$\\$|\\$\\{([^\\}]*)\\}").matcher(s); + StringBuffer result = new StringBuffer(); + while (m.find()) { + if (m.group().equals("$$")) { + m.appendReplacement(result, Matcher.quoteReplacement("$")); } else { - // class is determined by the content type - PropertyType t = instanceSuffixes.get(parts[1]); - cls = t.getType(); + m.appendReplacement(result, Matcher.quoteReplacement(System.getProperty(m.group(1)))); } - next = new PropertyElement() { - - @Override - public String getKey() { - return prefix + parts[0]; - } - - @Override - public Class getType() { - return cls; - } - - @Override - public Object getValue() { - return value; - } - - @Override - public void setValue(final String value) { - } - }; - return true; - } else { - return false; } - } - - @Override - public PropertyElement next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } else if (next != null) { - PropertyElement next = this.next; - this.next = null; - return next; - } else { - return child.next(); - } - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); + m.appendTail(result); + return result.toString(); } } } diff --git a/src/main/java/tree/properties/PropertyElement.java b/src/main/java/tree/properties/PropertyElement.java deleted file mode 100644 index 4693148c7f2..00000000000 --- a/src/main/java/tree/properties/PropertyElement.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2009 Clemens Koza - * - * 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 3 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, see . - */ -package tree.properties; - -/** - * The class PropertyElement. - * - * @author Clemens Koza - * @version V0.0 19.08.2009 - */ -public interface PropertyElement { - /** - * Returns the key of the property in the TreeProperties. - * - * @return a {@link java.lang.String} object. - */ - String getKey(); - - /** - * Returns the type of the element. - * - * @return a {@link java.lang.Class} object. - */ - Class getType(); - - /** - * Returns the value of the element. - * - * @return a {@link java.lang.Object} object. - */ - Object getValue(); - - /** - * Sets the property value as a string. - * - * @param value - * a {@link java.lang.String} object. - */ - void setValue(String value); -} diff --git a/src/main/java/tree/properties/PropertyType.java b/src/main/java/tree/properties/PropertyType.java deleted file mode 100644 index 3d483ba4618..00000000000 --- a/src/main/java/tree/properties/PropertyType.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2009 Clemens Koza - * - * 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 3 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, see . - */ -package tree.properties; - -/** - * PropertyTypeHandler.java - * - * Created on 19.08.2009 - * - * @param the generic type - */ - -/** - * The class PropertyType. A property type is used to process special, suffixed - * entries in a {@link TreeProperties} ' properties-file - * - * @author Clemens Koza - * @version V0.0 19.08.2009 - * - * @param - * - */ -public interface PropertyType { - /** - * The suffix, not including "--", that identifies this content type. - * - * @return a {@link java.lang.String} object. - */ - String getSuffix(); - - /** - * The class that identifies this content type. - * - * @return a {@link java.lang.Class} object. - */ - Class getType(); - - /** - * Returns an object for the specified value, in the context of a - * TreeProperties. - * - * @param p - * a {@link tree.properties.TreeProperties} object. - * @param s - * a {@link java.lang.String} object. - * @return a T object. - */ - T toObject(TreeProperties p, String s); -} diff --git a/src/main/java/tree/properties/package-info.java b/src/main/java/tree/properties/package-info.java deleted file mode 100644 index f3b15e72e4a..00000000000 --- a/src/main/java/tree/properties/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -/** Forge Card Game. */ -package tree.properties; diff --git a/src/main/java/tree/properties/types/FileType.java b/src/main/java/tree/properties/types/FileType.java deleted file mode 100644 index bad2e7426fa..00000000000 --- a/src/main/java/tree/properties/types/FileType.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2009 Clemens Koza - * - * 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 3 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, see . - */ - -package tree.properties.types; - -import java.io.File; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import tree.properties.PropertyType; -import tree.properties.TreeProperties; - -/** - * The class FileType. - * - * @author Clemens Koza - * @version V0.0 19.08.2009 - */ -public class FileType implements PropertyType { - /** Constant suffix="file". */ - public static final String SUFFIX = "file"; - /** Constant type. */ - public static final Class TYPE = File.class; - - /** - *

- * Getter for the field suffix. - *

- * - * @return a {@link java.lang.String} object. - */ - @Override - public final String getSuffix() { - return SUFFIX; - } - - /** - *

- * Getter for the field type. - *

- * - * @return a {@link java.lang.Class} object. - */ - @Override - public final Class getType() { - return TYPE; - } - - /** {@inheritDoc} */ - @Override - public final File toObject(final TreeProperties p, final String s) { - String path = getPath(s); - File f = new File(path); - if (f.isAbsolute()) { - return f; - } else { - return new File(p.getPath(), path); - } - } - - /** - * Returns a path path from a property value. Three substitutions are - * applied: - *
    - *
  • A "~/" or "~\" at the beginning is replaced with the user's home - * directory
  • - *
  • A "$$" anywhere is replaced with a single "$"
  • - *
  • A "${*}", where * is any string without "}", is replaced by - * - * @param s a {@link java.lang.String} object. - * @return a {@link java.lang.String} object. - * {@link System#getProperty(String)}
  • - *
- */ - public static String getPath(String s) { - if (s.startsWith("~/")) { - s = System.getProperty("user.home") + "/" + s.substring(2); - } else if (s.startsWith("~\\")) { - s = System.getProperty("user.home") + "\\" + s.substring(2); - } - Matcher m = Pattern.compile("\\$\\$|\\$\\{([^\\}]*)\\}").matcher(s); - StringBuffer result = new StringBuffer(); - while (m.find()) { - if (m.group().equals("$$")) { - m.appendReplacement(result, Matcher.quoteReplacement("$")); - } else { - m.appendReplacement(result, Matcher.quoteReplacement(System.getProperty(m.group(1)))); - } - } - m.appendTail(result); - return result.toString(); - } -} diff --git a/src/main/java/tree/properties/types/package-info.java b/src/main/java/tree/properties/types/package-info.java deleted file mode 100644 index a72843489d1..00000000000 --- a/src/main/java/tree/properties/types/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -/** Forge Card Game. */ -package tree.properties.types;