Use ByteEnum from samskivert. This is going to break a bunch of stuff which Ray

or I will fix. Whee!
This commit is contained in:
Michael Bayne
2009-08-18 22:04:04 +00:00
parent c6ae109f19
commit 928926d5e1
6 changed files with 6 additions and 85 deletions
@@ -1,32 +0,0 @@
//
// $Id$
//
// Depot library - a Java relational persistence library
// Copyright (C) 2006-2008 Michael Bayne and Pär Winzell
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot;
/**
* An enum value can be used as a field in a persistent object if it implements this interface.
*/
public interface ByteEnum
{
/**
* Returns the byte value to which to map this enum value.
*/
public byte toByte ();
}
@@ -30,9 +30,9 @@ import java.util.Set;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.samskivert.util.ByteEnum;
import com.samskivert.util.Tuple;
import com.samskivert.depot.ByteEnum;
import com.samskivert.depot.Key;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.annotation.Computed;
@@ -32,14 +32,14 @@ import java.sql.SQLException;
import java.sql.Time;
import java.sql.Timestamp;
import com.samskivert.depot.ByteEnum;
import com.samskivert.depot.DatabaseException;
import com.samskivert.depot.annotation.Column;
import com.samskivert.depot.annotation.Computed;
import com.samskivert.depot.annotation.GeneratedValue;
import com.samskivert.depot.util.ByteEnumUtil;
import com.samskivert.jdbc.ColumnDefinition;
import com.samskivert.util.ByteEnum;
import com.samskivert.util.ByteEnumUtil;
import com.samskivert.util.StringUtil;
/**
@@ -26,10 +26,10 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import com.samskivert.depot.ByteEnum;
import com.samskivert.depot.DatabaseException;
import com.samskivert.depot.expression.ValueExp;
import com.samskivert.depot.operator.In;
import com.samskivert.util.ByteEnum;
/**
* Specializes our PostgreSQL builder for JDBC4.
@@ -27,14 +27,14 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.samskivert.jdbc.ColumnDefinition;
import com.samskivert.depot.ByteEnum;
import com.samskivert.depot.PersistenceContext;
import com.samskivert.depot.PersistentRecord;
import com.samskivert.depot.annotation.Column;
import com.samskivert.depot.annotation.FullTextIndex;
import com.samskivert.depot.annotation.GeneratedValue;
import com.samskivert.depot.clause.QueryClause;
import com.samskivert.jdbc.ColumnDefinition;
import com.samskivert.util.ByteEnum;
import static com.samskivert.depot.Log.log;
@@ -1,47 +0,0 @@
//
// $Id$
//
// Depot library - a Java relational persistence library
// Copyright (C) 2006-2009 Michael Bayne and Pär Winzell
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.samskivert.depot.util;
import java.util.EnumSet;
import com.samskivert.depot.ByteEnum;
/**
* {@link ByteEnum} utility methods.
*/
public class ByteEnumUtil
{
/**
* Returns the enum value with the specified code in the supplied enum class.
*
* @exception IllegalArgumentException thrown if the enum lacks a value that maps to the
* supplied code.
*/
public static <E extends Enum<E> & ByteEnum> E fromByte (Class<E> eclass, byte code)
{
for (E value : EnumSet.allOf(eclass)) {
if (value.toByte() == code) {
return value;
}
}
throw new IllegalArgumentException(eclass + " has no value with code " + code);
}
}