Update of /cvsroot/squirrel-sql/mavenize/thirdparty-non-maven/ilf-gpl-1.6.1/src/main/java/net/infonode/util
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv4128/thirdparty-non-maven/ilf-gpl-1.6.1/src/main/java/net/infonode/util
Added Files:
package.html Enum.java Writable.java ReleaseInfo.java
ProductVersion.java ColorUtil.java Direction.java
AntUtils.java ArrayUtil.java
Log Message:
pom and Source for thirdparty dependency. Maven central requires a valid source code repository for artifacts that it hosts. This project has none, so we host it here for the time being.
--- NEW FILE: Enum.java ---
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* 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., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
// $Id: Enum.java,v 1.1 2010/01/26 21:09:40 manningr Exp $
package net.infonode.util;
import java.io.*;
import java.util.HashMap;
/**
* Base class for enum classes.
* Each enum value contains a name and an integer identifier.
*
* @author Jesper Nordenberg
* @version $Revision: 1.1 $ $Date: 2010/01/26 21:09:40 $
*/
public class Enum implements Serializable, Writable {
private static final long serialVersionUID = 1;
private static final HashMap VALUE_MAP = new HashMap();
private int value;
private transient String name;
protected Enum(int value, String name) {
this.value = value;
this.name = name;
HashMap values = (HashMap) VALUE_MAP.get(getClass());
if (values == null) {
values = new HashMap();
VALUE_MAP.put(getClass(), values);
}
values.put(new Integer(value), this);
}
/**
* Returns the integer identifier for this enum value.
*
* @return the integer identifier for this enum value
*/
public int getValue() {
return value;
}
/**
* Return the name of this enum value.
*
* @return the name of this enum value
*/
public String getName() {
return name;
}
public String toString() {
return name;
}
public void write(ObjectOutputStream out) throws IOException {
writeObject(out);
}
protected static Object getObject(Class cl, int value) throws IOException {
HashMap map = (HashMap) VALUE_MAP.get(cl);
if (map == null)
throw new IOException("Invalid enum class '" + cl + "'!");
Object object = map.get(new Integer(value));
if (object == null)
throw new IOException("Invalid enum value '" + value + "'!");
return object;
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeShort(value);
}
private void readObject(ObjectInputStream in) throws IOException {
value = in.readShort();
}
protected static Object decode(Class cl, ObjectInputStream in) throws IOException {
return getObject(cl, in.readShort());
}
protected Object readResolve() throws ObjectStreamException {
try {
return getObject(getClass(), getValue());
}
catch (IOException e) {
return this;
}
}
}
--- NEW FILE: ReleaseInfo.java ---
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* 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., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
//$Id: ReleaseInfo.java,v 1.1 2010/01/26 21:09:40 manningr Exp $
package net.infonode.util;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
/**
* A class that represents release information for a product
*
* @author $Author: manningr $
* @version $Revision: 1.1 $
*/
public class ReleaseInfo implements Serializable {
private static final long serialVersionUID = 1;
private String productName;
private String productVendor;
private String license;
private long buildTime;
private ProductVersion productVersion;
private URL homepage;
/**
* Constructs a release info object
*
* @param name product name
* @param vendor vendor name
* @param buildTime time of nuild in millis
* @param version product version
* @param license the product license
* @param homepage URL to the product homepage
*/
public ReleaseInfo(String name,
String vendor,
long buildTime,
ProductVersion version,
String license,
String homepage) {
this.productName = name;
this.productVendor = vendor;
this.buildTime = buildTime;
this.productVersion = version;
this.license = license;
try {
this.homepage = new URL(homepage);
}
catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
/**
* Gets the product name
*
* @return Product name
*/
public String getProductName() {
return productName;
}
/**
* Gets the product vendor
*
* @return Product vendor
*/
public String getProductVendor() {
return productVendor;
}
/**
* Gets the product license
*
* @return Product license
*/
public String getLicense() {
return license;
}
/**
* Gets the build time in millis
*
* @return Build time in millis
*/
public long getBuildTime() {
return buildTime;
}
/**
* Gets the product version
*
* @return Product version
*/
public ProductVersion getProductVersion() {
return productVersion;
}
/**
* Gets the URL for the product homepage.
*
* @return the URL for the product homepage
*/
public URL getHomepage() {
return homepage;
}
}
--- NEW FILE: Direction.java ---
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* 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., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
// $Id: Direction.java,v 1.1 2010/01/26 21:09:40 manningr Exp $
package net.infonode.util;
import java.io.IOException;
import java.io.ObjectInputStream;
/**
* An enum class for directions, up, down, left, right.
*
* @author $Author: manningr $
* @version $Revision: 1.1 $
*/
final public class Direction extends Enum {
private static final long serialVersionUID = 1;
/**
* Up direction.
*/
public static final Direction UP = new Direction(0, "Up", false);
/**
* Right direction.
*/
public static final Direction RIGHT = new Direction(1, "Right", true);
/**
* Down direction.
*/
public static final Direction DOWN = new Direction(2, "Down", false);
/**
* Left direction.
*/
public static final Direction LEFT = new Direction(3, "Left", true);
/**
* Array containing all directions.
*/
public static final Direction[] DIRECTIONS = {UP, RIGHT, DOWN, LEFT};
static {
UP.rotateCW = RIGHT;
RIGHT.rotateCW = DOWN;
DOWN.rotateCW = LEFT;
LEFT.rotateCW = UP;
}
private transient Direction rotateCW;
private transient boolean isHorizontal;
private Direction(int value, String name, boolean isHorizontal) {
super(value, name);
this.isHorizontal = isHorizontal;
}
/**
* Returns the direction that is one quarter of a revolution clock wise.
*
* @return the direction that is one quarter of a revolution clock wise
*/
public Direction getNextCW() {
return rotateCW;
}
/**
* Returns the direction that is one quarter of a revolution counter clock wise.
*
* @return the direction that is one quarter of a revolution counter clock wise
*/
public Direction getNextCCW() {
return rotateCW.rotateCW.rotateCW;
}
/**
* Returns true if the direction is horizontal.
*
* @return true if the direction is horizontal
*/
public boolean isHorizontal() {
return isHorizontal;
}
/**
* Returns the opposite direction.
*
* @return the opposite direction
*/
public Direction getOpposite() {
return getNextCW().getNextCW();
}
/**
* Gets all directions.
*
* @return all directions
* @since 1.1.0
*/
public static Direction[] getDirections() {
return (Direction[]) DIRECTIONS.clone();
}
/**
* Decodes a direction from a stream.
*
* @param in the stream containing the direction
* @return the direction
* @throws IOException if there is a stream error
*/
public static Direction decode(ObjectInputStream in) throws IOException {
return (Direction) decode(Direction.class, in);
}
}
--- NEW FILE: Writable.java ---
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* 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., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
// $Id: Writable.java,v 1.1 2010/01/26 21:09:40 manningr Exp $
package net.infonode.util;
import java.io.IOException;
import java.io.ObjectOutputStream;
/**
* Interface for objects that can be written to an {@link java.io.ObjectOutputStream}.
*
* @author $Author: manningr $
* @version $Revision: 1.1 $
*/
public interface Writable {
/**
* Writes this object to an ObjectOutputStream.
*
* @param out the stream
* @throws IOException if there is a stream error
*/
void write(ObjectOutputStream out) throws IOException;
}
--- NEW FILE: package.html ---
<html>
<body>
Common utility classes
</body>
</html>
--- NEW FILE: ColorUtil.java ---
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* 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., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
// $Id: ColorUtil.java,v 1.1 2010/01/26 21:09:40 manningr Exp $
package net.infonode.util;
import java.awt.*;
public final class ColorUtil {
private ColorUtil() {
}
public static Color getOpposite(Color c) {
return isDark(c) ? Color.WHITE : Color.BLACK;
}
public static Color shade(Color c, double amount) {
return blend(c, getOpposite(c), amount);
}
public static final Color mult(Color c, double amount) {
return c == null ? null : new Color(Math.min(255, (int) (c.getRed() * amount)),
Math.min(255, (int) (c.getGreen() * amount)),
Math.min(255, (int) (c.getBlue() * amount)),
c.getAlpha());
}
public static Color setAlpha(Color c, int alpha) {
return c == null ? null : new Color(c.getRed(), c.getGreen(), c.getBlue(), alpha);
}
public static final Color add(Color c1, Color c2) {
return c1 == null ? c2 :
c2 == null ? c1 :
new Color(Math.min(255, c1.getRed() + c2.getRed()),
Math.min(255, c1.getGreen() + c2.getGreen()),
Math.min(255, c1.getBlue() + c2.getBlue()),
c1.getAlpha());
}
public static Color blend(Color c1, Color c2, double v) {
double v2 = 1 - v;
return c1 == null ? (c2 == null ? null : c2) :
c2 == null ? c1 :
new Color(Math.min(255, (int) (c1.getRed() * v2 + c2.getRed() * v)),
Math.min(255, (int) (c1.getGreen() * v2 + c2.getGreen() * v)),
Math.min(255, (int) (c1.getBlue() * v2 + c2.getBlue() * v)),
Math.min(255, (int) (c1.getAlpha() * v2 + c2.getAlpha() * v)));
}
public static boolean isDark(Color c) {
return c.getRed() + c.getGreen() + c.getBlue() < 3 * 180;
}
public static Color highlight(Color c) {
return mult(c, isDark(c) ? 1.5F : 0.67F);
}
public static Color copy(Color c) {
return c == null ? null : new Color(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha());
}
}
--- NEW FILE: ArrayUtil.java ---
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* 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., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
// $Id: ArrayUtil.java,v 1.1 2010/01/26 21:09:40 manningr Exp $
package net.infonode.util;
import java.util.ArrayList;
public class ArrayUtil {
private ArrayUtil() {
}
static final public Object[] add(Object[] objects, Object object, Object[] newObjects) {
System.arraycopy(objects, 0, newObjects, 0, objects.length);
newObjects[objects.length] = object;
return newObjects;
}
static final public byte[] part(byte[] array, int offset, int length) {
byte[] b = new byte[length];
System.arraycopy(array, offset, b, 0, length);
return b;
}
static final public int countNotNull(Object[] objects) {
int count = 0;
for (int i = 0; i < objects.length; i++)
if (objects[i] != null)
count++;
return count;
}
static final public int findSmallest(double[] items) {
int index = 0;
for (int i = 1; i < items.length; i++) {
if (items[i] < items[index]) {
index = i;
}
}
return index;
}
static final public int findSmallest(int[] items) {
int index = 0;
for (int i = 1; i < items.length; i++) {
if (items[i] < items[index]) {
index = i;
}
}
return index;
}
static final public int findLargest(float[] items) {
int index = 0;
for (int i = 1; i < items.length; i++) {
if (items[i] > items[index]) {
index = i;
}
}
return index;
}
public static float[] toFloatArray(int[] values) {
float[] floatValues = new float[values.length];
for (int i = 0; i < values.length; i++)
floatValues[i] = values[i];
return floatValues;
}
static final public int indexOf(int[] array, int value) {
for (int i = 0; i < array.length; i++)
if (array[i] == value)
return i;
return -1;
}
static final public int indexOf(byte[] array, byte value) {
for (int i = 0; i < array.length; i++)
if (array[i] == value)
return i;
return -1;
}
static final public String[] append(String[] a1, String[] a2) {
String[] n = new String[a1.length + a2.length];
System.arraycopy(a1, 0, n, 0, a1.length);
System.arraycopy(a2, 0, n, a1.length, a2.length);
return n;
}
static final public Object[] append(Object[] a1, Object[] a2, Object[] out) {
System.arraycopy(a1, 0, out, 0, a1.length);
System.arraycopy(a2, 0, out, a1.length, a2.length);
return out;
}
public static boolean equal(int[] a, int aOffset, int[] b, int bOffset, int length) {
for (int i = 0; i < length; i++)
if (a[aOffset + i] != b[bOffset + i])
return false;
return true;
}
public static boolean equal(byte[] a, int aOffset, byte[] b, int bOffset, int length) {
for (int i = 0; i < length; i++)
if (a[aOffset + i] != b[bOffset + i])
return false;
return true;
}
public static boolean contains(short[] a, short v) {
for (int i = 0; i < a.length; i++)
if (a[i] == v)
return true;
return false;
}
public static int[] range(int start, int length, int step) {
int[] a = new int[length];
for (int i = 0; i < length; i++)
a[i] = start + step * i;
return a;
}
public static boolean containsEqual(Object[] values, Object value) {
return indexOfEqual(values, value) != -1;
}
public static boolean contains(Object[] values, Object value) {
return indexOf(values, value) != -1;
}
public static int indexOf(Object[] values, Object value) {
for (int i = 0; i < values.length; i++)
if (values[i] == value)
return i;
return -1;
}
public static int indexOf(Object[] values, Object value, int startIndex, int length) {
for (int i = startIndex; i < length; i++)
if (values[i] == value)
return i;
return -1;
}
public static int indexOfEqual(Object[] values, Object value) {
for (int i = 0; i < values.length; i++)
if (values[i].equals(value))
return i;
return -1;
}
public static Object[] remove(Object[] values, Object value, Object[] newValues) {
int index = indexOf(values, value);
if (index == -1)
index = values.length;
System.arraycopy(values, 0, newValues, 0, index);
System.arraycopy(values, index + 1, newValues, index, newValues.length - index);
return newValues;
}
public static String toString(int[] a) {
StringBuffer b = new StringBuffer(a.length * 4);
for (int i = 0; i < a.length; i++) {
if (i != 0)
b.append(", ");
b.append(a[i]);
}
return b.toString();
}
public static int[] part(int[] values, int start, int length) {
int[] a = new int[length];
System.arraycopy(values, start, a, 0, length);
return a;
}
public static int sum(int[] values) {
int sum = 0;
for (int i = 0; i < values.length; i++)
sum += values[i];
return sum;
}
public static int count(int[] values, int value) {
int count = 0;
for (int i = 0; i < values.length; i++)
if (values[i] == value)
count++;
return count;
}
public static int count(boolean[] values, boolean value) {
int count = 0;
for (int i = 0; i < values.length; i++)
if (values[i] == value)
count++;
return count;
}
public static int findLargest(int[] items) {
int index = 0;
for (int i = 1; i < items.length; i++) {
if (items[i] > items[index]) {
index = i;
}
}
return index;
}
public static int[] toIntArray(ArrayList items) {
int[] result = new int[items.size()];
for (int i = 0; i < items.size(); i++)
result[i] = ((Number) items.get(i)).intValue();
return result;
}
public static boolean[] toBooleanArray(ArrayList items) {
boolean[] result = new boolean[items.size()];
for (int i = 0; i < items.size(); i++)
result[i] = ((Boolean) items.get(i)).booleanValue();
return result;
}
}
--- NEW FILE: AntUtils.java ---
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* 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., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
// $Id: AntUtils.java,v 1.1 2010/01/26 21:09:40 manningr Exp $
package net.infonode.util;
/**
* Utility functions for Ant build environment
*
* @author $Author: manningr $
* @version $Revision: 1.1 $
*/
public class AntUtils {
public static ProductVersion createProductVersion(int major, int minor, int patch) {
return new ProductVersion(major, minor, patch);
}
public static ProductVersion createProductVersion(String major, String minor, String patch) {
return createProductVersion(0, 0, 0);
}
public static long getBuildTime(long time) {
return time;
}
public static long getBuildTime(String time) {
return getBuildTime(System.currentTimeMillis());
}
}
--- NEW FILE: ProductVersion.java ---
/*
* Copyright (C) 2004 NNL Technology AB
* Visit www.infonode.net for information about InfoNode(R)
* products and how to contact NNL Technology AB.
*
* 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., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*/
//$Id: ProductVersion.java,v 1.1 2010/01/26 21:09:40 manningr Exp $
package net.infonode.util;
import java.io.Serializable;
/**
* A class that represents a product version
*
* @author $Author: manningr $
* @version $Revision: 1.1 $
*/
public class ProductVersion implements Serializable {
private static final long serialVersionUID = 1;
private int major;
private int minor;
private int patch;
/**
* Constructs a product version object
*
* @param major Major version number
* @param minor Minor version number
* @param patch Patch version number
*/
public ProductVersion(int major, int minor, int patch) {
this.major = major;
this.minor = minor;
this.patch = patch;
}
/**
* Gets the major version number, i.e.
* the number X in version X.0.0
*
* @return Major version number
*/
public int getMajor() {
return major;
}
/**
* Gets the minor version number, i.e.
* the number X in version 0.X.0
*
* @return Minor version number
*/
public int getMinor() {
return minor;
}
/**
* Gets the patch version number, i.e.
* the number X in version 0.0.X
*
* @return Minor version number
*/
public int getPatch() {
return patch;
}
/**
* Gets the version as string
*
* @return Version as string
*/
public String toString() {
return major + "." + minor + "." + patch;
}
}
|