mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 04:08:01 +00:00
moved 2 files to ensure history is saved
This commit is contained in:
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Forge Team
|
||||
*
|
||||
* 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 forge.util;
|
||||
|
||||
|
||||
/**
|
||||
* AllZoneUtil contains static functions used to get CardLists of various cards
|
||||
* in various zones.
|
||||
*
|
||||
* @author dennis.r.friedrichsen (slapshot5 on slightlymagic.net)
|
||||
* @version $Id: AllZoneUtil.java 17567 2012-10-18 14:10:15Z Max mtg $
|
||||
*/
|
||||
public abstract class Expressions {
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* compare.
|
||||
* </p>
|
||||
*
|
||||
* @param leftSide
|
||||
* a int.
|
||||
* @param comp
|
||||
* a {@link java.lang.String} object.
|
||||
* @param rightSide
|
||||
* a int.
|
||||
* @return a boolean.
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static boolean compare(final int leftSide, final String comp, final int rightSide) {
|
||||
// should this function be somewhere else?
|
||||
// leftSide COMPARED to rightSide:
|
||||
if (comp.contains("LT")) {
|
||||
return leftSide < rightSide;
|
||||
} else if (comp.contains("LE")) {
|
||||
return leftSide <= rightSide;
|
||||
} else if (comp.contains("EQ")) {
|
||||
return leftSide == rightSide;
|
||||
} else if (comp.contains("GE")) {
|
||||
return leftSide >= rightSide;
|
||||
} else if (comp.contains("GT")) {
|
||||
return leftSide > rightSide;
|
||||
} else if (comp.contains("NE")) {
|
||||
return leftSide != rightSide; // not equals
|
||||
} else if (comp.contains("M2")) {
|
||||
return (leftSide % 2) == (rightSide % 2); // they are equal modulo 2
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String operatorName(final String comp) {
|
||||
// should this function be somewhere else?
|
||||
// leftSide COMPARED to rightSide:
|
||||
if (comp.contains("LT")) {
|
||||
return " less than ";
|
||||
} else if (comp.contains("LE")) {
|
||||
return " less or equal to ";
|
||||
} else if (comp.contains("EQ")) {
|
||||
return " equal to ";
|
||||
} else if (comp.contains("GT")) {
|
||||
return " greater than ";
|
||||
} else if (comp.contains("GE")) {
|
||||
return " greater or equal to ";
|
||||
} else if (comp.contains("NE")) {
|
||||
return " not equal to ";
|
||||
} else if (comp.contains("M2")) {
|
||||
return " is modulo 2 equal to"; // should not show this to players
|
||||
}
|
||||
return " ? ";
|
||||
}
|
||||
|
||||
|
||||
} // end class AllZoneUtil
|
||||
@@ -1,44 +0,0 @@
|
||||
package forge.util;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public class ReflectionUtil {
|
||||
|
||||
public static <T> T makeDefaultInstanceOf(Class<? extends T> cls) {
|
||||
if ( null == cls )
|
||||
throw new IllegalArgumentException("Class<? extends T> cls must not be null");
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Constructor<? extends T>[] cc = (Constructor<? extends T>[]) cls.getConstructors();
|
||||
for (Constructor<? extends T> c : cc) {
|
||||
Class<?>[] pp = c.getParameterTypes();
|
||||
if (pp.length == 0) {
|
||||
try {
|
||||
T res = c.newInstance();
|
||||
return res;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No default constructor found in class " + cls.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast object to a given type if possible, returning null if not possible
|
||||
* @param obj
|
||||
* @param type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T safeCast(Object obj, Class<T> type) {
|
||||
if (type.isInstance(obj)) {
|
||||
return (T) obj;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user