mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
TreeProperties: removed unused functionality, moved the remaining class to forge.util
This commit is contained in:
7
.gitattributes
vendored
7
.gitattributes
vendored
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<PropertyElement> {
|
||||
*/
|
||||
public class TreeProperties /* implements Iterable<PropertyElement> */{
|
||||
/** Constant <code>suffixes</code>. */
|
||||
private static final Map<String, PropertyType<?>> SUFFIXES;
|
||||
/** Constant <code>types</code>. */
|
||||
@@ -328,7 +327,7 @@ public class TreeProperties implements Iterable<PropertyElement> {
|
||||
*
|
||||
* @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<PropertyElement> {
|
||||
*
|
||||
* @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<PropertyElement> {
|
||||
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<PropertyElement> iterator() {
|
||||
return iterator("");
|
||||
};
|
||||
public interface PropertyType<T> {
|
||||
/**
|
||||
* The suffix, not including "--", that identifies this content type.
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
String getSuffix();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* iterator.
|
||||
* </p>
|
||||
*
|
||||
* @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<T> getType();
|
||||
|
||||
private final class TreePropertiesIterator implements Iterator<PropertyElement> {
|
||||
private final String prefix;
|
||||
private Iterator<Entry<String, Object>> 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<File> {
|
||||
/** Constant <code>suffix="file"</code>. */
|
||||
public static final String SUFFIX = "file";
|
||||
/** Constant <code>type</code>. */
|
||||
public static final Class<File> TYPE = File.class;
|
||||
|
||||
private TreePropertiesIterator(final String prefix) {
|
||||
entries = properties.entrySet().iterator();
|
||||
this.prefix = prefix;
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>suffix</code>.
|
||||
* </p>
|
||||
*
|
||||
* @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
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>type</code>.
|
||||
* </p>
|
||||
*
|
||||
* @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<String, Object> entry = entries.next();
|
||||
final String[] parts = entry.getKey().split("--");
|
||||
final Class<?> cls;
|
||||
final Object value = entry.getValue();
|
||||
public final Class<File> 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:
|
||||
* <ul>
|
||||
* <li>A "~/" or "~\" at the beginning is replaced with the user's home
|
||||
* directory</li>
|
||||
* <li>A "$$" anywhere is replaced with a single "$"</li>
|
||||
* <li>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)}</li>
|
||||
* </ul>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package tree.properties;
|
||||
|
||||
/**
|
||||
* PropertyTypeHandler.java
|
||||
*
|
||||
* Created on 19.08.2009
|
||||
*
|
||||
* @param <T> 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 <T>
|
||||
*
|
||||
*/
|
||||
public interface PropertyType<T> {
|
||||
/**
|
||||
* 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<T> 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);
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
/** Forge Card Game. */
|
||||
package tree.properties;
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<File> {
|
||||
/** Constant <code>suffix="file"</code>. */
|
||||
public static final String SUFFIX = "file";
|
||||
/** Constant <code>type</code>. */
|
||||
public static final Class<File> TYPE = File.class;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>suffix</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
@Override
|
||||
public final String getSuffix() {
|
||||
return SUFFIX;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Getter for the field <code>type</code>.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.Class} object.
|
||||
*/
|
||||
@Override
|
||||
public final Class<File> 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:
|
||||
* <ul>
|
||||
* <li>A "~/" or "~\" at the beginning is replaced with the user's home
|
||||
* directory</li>
|
||||
* <li>A "$$" anywhere is replaced with a single "$"</li>
|
||||
* <li>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)}</li>
|
||||
* </ul>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
/** Forge Card Game. */
|
||||
package tree.properties.types;
|
||||
Reference in New Issue
Block a user