<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FJ2EE%2FJDO</id>
		<title>Java/J2EE/JDO - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java%2FJ2EE%2FJDO"/>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/J2EE/JDO&amp;action=history"/>
		<updated>2026-04-18T23:11:05Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/J2EE/JDO&amp;diff=7673&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/J2EE/JDO&amp;diff=7673&amp;oldid=prev"/>
				<updated>2010-06-01T06:49:33Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 06:49, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://www.jexp.ru/index.php?title=Java/J2EE/JDO&amp;diff=7672&amp;oldid=prev</id>
		<title> в 18:01, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.jexp.ru/index.php?title=Java/J2EE/JDO&amp;diff=7672&amp;oldid=prev"/>
				<updated>2010-05-31T18:01:45Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Contains static methods related to Java and JDO type conversions ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
  &lt;br /&gt;
/*&lt;br /&gt;
 * Copyright 2005 (C) TJDO.&lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 *&lt;br /&gt;
 * This software is distributed under the terms of the TJDO License version 1.0.&lt;br /&gt;
 * See the terms of the TJDO License in the documentation provided with this software.&lt;br /&gt;
 *&lt;br /&gt;
 * $Id: Types.java,v 1.1 2005/12/13 20:46:16 jackknifebarber Exp $&lt;br /&gt;
 */&lt;br /&gt;
&lt;br /&gt;
import java.math.BigDecimal;&lt;br /&gt;
import java.math.BigInteger;&lt;br /&gt;
import java.util.HashMap;&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Contains static methods related to Java and JDO type conversions.&lt;br /&gt;
 *&lt;br /&gt;
 * @author &lt;br /&gt;
 * @version $Revision: 1.1 $&lt;br /&gt;
 */&lt;br /&gt;
public final class Types&lt;br /&gt;
{&lt;br /&gt;
    private Types()&lt;br /&gt;
    {&lt;br /&gt;
    }&lt;br /&gt;
    private static final HashMap WRAPPERS_BY_PRIMITIVE = new HashMap(9);&lt;br /&gt;
    private static final HashMap PRIMITIVES_BY_WRAPPER = new HashMap(9);&lt;br /&gt;
    static&lt;br /&gt;
    {&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Boolean.TYPE,   Boolean.class);&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Byte.TYPE,      Byte.class);&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Character.TYPE, Character.class);&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Short.TYPE,     Short.class);&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Integer.TYPE,   Integer.class);&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Long.TYPE,      Long.class);&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Float.TYPE,     Float.class);&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Double.TYPE,    Double.class);&lt;br /&gt;
        WRAPPERS_BY_PRIMITIVE.put(Void.TYPE,      Void.class);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Boolean.class,   Boolean.TYPE);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Byte.class,      Byte.TYPE);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Character.class, Character.TYPE);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Short.class,     Short.TYPE);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Integer.class,   Integer.TYPE);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Long.class,      Long.TYPE);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Float.class,     Float.TYPE);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Double.class,    Double.TYPE);&lt;br /&gt;
        PRIMITIVES_BY_WRAPPER.put(Void.class,      Void.TYPE);&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Performs a boxing conversion, if applicable.&lt;br /&gt;
     * If the type is a Java primitive type it&amp;quot;s equivalent wrapper class is&lt;br /&gt;
     * returned.&lt;br /&gt;
     * Otherwise the type itself is returned.&lt;br /&gt;
     *&lt;br /&gt;
     * @param c&lt;br /&gt;
     *      the type to be boxed, or &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @return&lt;br /&gt;
     *      The boxed equivalent, or the type itself if not applicable.&lt;br /&gt;
     *      &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; is returned if the argument was null.&lt;br /&gt;
     */&lt;br /&gt;
    public static Class box(Class c)&lt;br /&gt;
    {&lt;br /&gt;
        Class boxed = (Class)WRAPPERS_BY_PRIMITIVE.get(c);&lt;br /&gt;
        return boxed == null ? c : boxed;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Performs an unboxing conversion, if applicable.&lt;br /&gt;
     * If the type is a Java primitive wrapper class it&amp;quot;s equivalent primitive&lt;br /&gt;
     * type is returned.&lt;br /&gt;
     * Otherwise the type itself is returned.&lt;br /&gt;
     *&lt;br /&gt;
     * @param c&lt;br /&gt;
     *      the type to be unboxed, or &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @return&lt;br /&gt;
     *      The unboxed equivalent, or the type itself if not applicable.&lt;br /&gt;
     *      &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; is returned if the argument was null.&lt;br /&gt;
     */&lt;br /&gt;
    public static Class unbox(Class c)&lt;br /&gt;
    {&lt;br /&gt;
        Class unboxed = (Class)PRIMITIVES_BY_WRAPPER.get(c);&lt;br /&gt;
        return unboxed == null ? c : unboxed;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Performs a boxing conversion on multiple classes.&lt;br /&gt;
     * The returned array contains the results of calling {@link #box(Class)}&lt;br /&gt;
     * on every class in the argument array.&lt;br /&gt;
     *&lt;br /&gt;
     * @param c&lt;br /&gt;
     *      the types to be boxed&lt;br /&gt;
     *&lt;br /&gt;
     * @return&lt;br /&gt;
     *      the boxed equivalent of all the types in &amp;lt;var&amp;gt;c&amp;lt;/var&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    public static Class[] box(Class[] c)&lt;br /&gt;
    {&lt;br /&gt;
        int n = c.length;&lt;br /&gt;
        Class[] boxed = new Class[n];&lt;br /&gt;
        for (int i = 0; i &amp;lt; n; ++i)&lt;br /&gt;
            boxed[i] = box(c[i]);&lt;br /&gt;
        return boxed;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Performs an unboxing conversion on multiple classes.&lt;br /&gt;
     * The returned array contains the results of calling {@link #unbox(Class)}&lt;br /&gt;
     * on every class in the argument array.&lt;br /&gt;
     *&lt;br /&gt;
     * @param c&lt;br /&gt;
     *      the types to be unboxed&lt;br /&gt;
     *&lt;br /&gt;
     * @return&lt;br /&gt;
     *      the unboxed equivalent of all the types in &amp;lt;var&amp;gt;c&amp;lt;/var&amp;gt;&lt;br /&gt;
     */&lt;br /&gt;
    public static Class[] unbox(Class[] c)&lt;br /&gt;
    {&lt;br /&gt;
        int n = c.length;&lt;br /&gt;
        Class[] unboxed = new Class[n];&lt;br /&gt;
        for (int i = 0; i &amp;lt; n; ++i)&lt;br /&gt;
            unboxed[i] = unbox(c[i]);&lt;br /&gt;
        return unboxed;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Tests if a set of parameters types are all assignable from a given set of&lt;br /&gt;
     * argument types.&lt;br /&gt;
     * Returns true iff the number of types match and each parameter type is&lt;br /&gt;
     * assignable from its corresponding argument type.&lt;br /&gt;
     * &amp;quot;Assignable&amp;quot; is defined by &amp;lt;code&amp;gt;Class.isAssignableFrom()&amp;lt;/code&amp;gt;.&lt;br /&gt;
     * &amp;lt;p&amp;gt;&lt;br /&gt;
     * All classes in the parameter type array and the argument type array must&lt;br /&gt;
     * already be boxed.&lt;br /&gt;
     *&lt;br /&gt;
     * @param boxedParamTypes&lt;br /&gt;
     *      the parameter types&lt;br /&gt;
     * @param boxedArgTypes&lt;br /&gt;
     *      the argument types&lt;br /&gt;
     *&lt;br /&gt;
     * @return&lt;br /&gt;
     *      &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; if the all the parameter types are assignable from&lt;br /&gt;
     *      the argument types.&lt;br /&gt;
     */&lt;br /&gt;
    public static boolean areAssignableFrom(Class[] boxedParamTypes, Class[] boxedArgTypes)&lt;br /&gt;
    {&lt;br /&gt;
        int n = boxedParamTypes.length;&lt;br /&gt;
        if (n != boxedArgTypes.length)&lt;br /&gt;
            return false;&lt;br /&gt;
        for (int i = 0; i &amp;lt; n; ++i)&lt;br /&gt;
        {&lt;br /&gt;
            if (!boxedParamTypes[i].isAssignableFrom(boxedArgTypes[i]))&lt;br /&gt;
                return false;&lt;br /&gt;
        }&lt;br /&gt;
        return true;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Performs &amp;lt;dfn&amp;gt;unary numeric promotion&amp;lt;/dfn&amp;gt; on the given type.&lt;br /&gt;
     * Unary numeric promotion is as defined in &amp;amp;sect;5.6.1 of the Java Language&lt;br /&gt;
     * Specification.&lt;br /&gt;
     *&lt;br /&gt;
     * @param operandType&lt;br /&gt;
     *      the type to be promoted, or &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt;&lt;br /&gt;
     *&lt;br /&gt;
     * @return&lt;br /&gt;
     *      The promoted type, or &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; if the argument was null.&lt;br /&gt;
     */&lt;br /&gt;
    public static Class unaryNumericPromotion(Class operandType)&lt;br /&gt;
    {&lt;br /&gt;
        operandType = box(operandType);&lt;br /&gt;
        if (operandType == Byte.class || operandType == Character.class || operandType == Short.class)&lt;br /&gt;
            return Integer.class;&lt;br /&gt;
        else&lt;br /&gt;
            return operandType;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Performs &amp;lt;dfn&amp;gt;binary numeric promotion&amp;lt;/dfn&amp;gt; on a set of input types.&lt;br /&gt;
     * Binary numeric promotion is as defined in &amp;amp;sect;14.6.2 of the JDO 2.0&lt;br /&gt;
     * spec.&lt;br /&gt;
     *&lt;br /&gt;
     * @param types&lt;br /&gt;
     *      The input types to be promoted.  If more than two types are present&lt;br /&gt;
     *      then the first two are promoted, then the promoted type and the&lt;br /&gt;
     *      third type are promoted, and so on for all the types.&lt;br /&gt;
     *&lt;br /&gt;
     * @return&lt;br /&gt;
     *      The promoted type.  Returns &amp;lt;code&amp;gt;null&amp;lt;/code&amp;gt; if the input array&lt;br /&gt;
     *      is empty.  Returns the first type if the input array has only one&lt;br /&gt;
     *      type.&lt;br /&gt;
     *&lt;br /&gt;
     * @exception IllegalArgumentException&lt;br /&gt;
     *      if any argument type is not a subclass of java.lang.Number&lt;br /&gt;
     */&lt;br /&gt;
    public static Class binaryNumericPromotion(Class[] types)&lt;br /&gt;
    {&lt;br /&gt;
        Class promoted = null;&lt;br /&gt;
        int n = types.length;&lt;br /&gt;
        if (n &amp;gt; 0)&lt;br /&gt;
            promoted = types[0];&lt;br /&gt;
        for (int i = 1; i &amp;lt; n; ++i)&lt;br /&gt;
            promoted = binaryNumericPromotion(promoted, types[i]);&lt;br /&gt;
        return promoted;&lt;br /&gt;
    }&lt;br /&gt;
    /**&lt;br /&gt;
     * Performs &amp;lt;dfn&amp;gt;binary numeric promotion&amp;lt;/dfn&amp;gt; on a pair of types.&lt;br /&gt;
     * Binary numeric promotion is as defined in &amp;amp;sect;14.6.2 of the JDO 2.0&lt;br /&gt;
     * spec.&lt;br /&gt;
     *&lt;br /&gt;
     * @param operand1Type&lt;br /&gt;
     *      the first type in the pair.&lt;br /&gt;
     * @param operand2Type&lt;br /&gt;
     *      the other type in the pair.&lt;br /&gt;
     *&lt;br /&gt;
     * @return&lt;br /&gt;
     *      The promoted type.&lt;br /&gt;
     *&lt;br /&gt;
     * @exception IllegalArgumentException&lt;br /&gt;
     *      if either argument type is not a subclass of java.lang.Number&lt;br /&gt;
     */&lt;br /&gt;
    public static Class binaryNumericPromotion(Class operand1Type, Class operand2Type)&lt;br /&gt;
    {&lt;br /&gt;
        operand1Type = box(operand1Type);&lt;br /&gt;
        operand2Type = box(operand2Type);&lt;br /&gt;
        if (operand1Type == BigDecimal.class || operand2Type == BigDecimal.class)&lt;br /&gt;
            return BigDecimal.class;&lt;br /&gt;
        if (isBigIntegerVsFloating(operand1Type, operand2Type) || isBigIntegerVsFloating(operand2Type, operand1Type))&lt;br /&gt;
            return BigDecimal.class;&lt;br /&gt;
        if (operand1Type == BigInteger.class || operand2Type == BigInteger.class)&lt;br /&gt;
            return BigInteger.class;&lt;br /&gt;
        if (operand1Type == Double.class || operand2Type == Double.class)&lt;br /&gt;
            return Double.class;&lt;br /&gt;
        if (operand1Type == Float.class || operand2Type == Float.class)&lt;br /&gt;
            return Float.class;&lt;br /&gt;
        if (operand1Type == Long.class || operand2Type == Long.class)&lt;br /&gt;
            return Long.class;&lt;br /&gt;
        if (!Number.class.isAssignableFrom(operand1Type) || !Number.class.isAssignableFrom(operand2Type))&lt;br /&gt;
            throw new IllegalArgumentException(&amp;quot;No defined numeric promotion for operands of type &amp;quot; + operand1Type.getName() + &amp;quot; and &amp;quot; + operand2Type.getName());&lt;br /&gt;
        return Integer.class;&lt;br /&gt;
    }&lt;br /&gt;
    private static boolean isBigIntegerVsFloating(Class c1, Class c2)&lt;br /&gt;
    {&lt;br /&gt;
        return c1 == BigInteger.class &amp;amp;&amp;amp; (c2 == Float.class || c2 == Double.class);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>