|
| 1 | +/* |
| 2 | + * #%L |
| 3 | + * SciJava Common shared library for SciJava software. |
| 4 | + * %% |
| 5 | + * Copyright (C) 2009 - 2015 Board of Regents of the University of |
| 6 | + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck |
| 7 | + * Institute of Molecular Cell Biology and Genetics. |
| 8 | + * %% |
| 9 | + * Redistribution and use in source and binary forms, with or without |
| 10 | + * modification, are permitted provided that the following conditions are met: |
| 11 | + * |
| 12 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 13 | + * this list of conditions and the following disclaimer. |
| 14 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 15 | + * this list of conditions and the following disclaimer in the documentation |
| 16 | + * and/or other materials provided with the distribution. |
| 17 | + * |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE |
| 22 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | + * POSSIBILITY OF SUCH DAMAGE. |
| 29 | + * #L% |
| 30 | + */ |
| 31 | + |
| 32 | +package org.scijava.convert; |
| 33 | + |
| 34 | +import java.math.BigInteger; |
| 35 | + |
| 36 | +import org.scijava.plugin.Plugin; |
| 37 | + |
| 38 | +/** |
| 39 | + * Converter plugins that convert from primitive numeric types to other |
| 40 | + * primitive numeric types. |
| 41 | + * |
| 42 | + * @author Alison Walter |
| 43 | + */ |
| 44 | +public final class NumberConverters { |
| 45 | + |
| 46 | + private NumberConverters() { |
| 47 | + // prevent instantiation of container class |
| 48 | + } |
| 49 | + |
| 50 | + //convert to short |
| 51 | + @Plugin(type = Converter.class) |
| 52 | + public static class ByteToShortConverter extends NumberToShortConverter<Byte> { |
| 53 | + @Override public Class<Byte> getInputType() { return Byte.class; } |
| 54 | + } |
| 55 | + |
| 56 | + //convert to int |
| 57 | + @Plugin(type = Converter.class) |
| 58 | + public static class ByteToIntegerConverter extends NumberToIntegerConverter<Byte> { |
| 59 | + @Override public Class<Byte> getInputType() { return Byte.class; } |
| 60 | + } |
| 61 | + |
| 62 | + @Plugin(type = Converter.class) |
| 63 | + public static class ShortToIntegerConverter extends NumberToIntegerConverter<Short> { |
| 64 | + @Override public Class<Short> getInputType() { return Short.class; } |
| 65 | + } |
| 66 | + |
| 67 | + //convert to long |
| 68 | + @Plugin(type = Converter.class) |
| 69 | + public static class ByteToLongConverter extends NumberToLongConverter<Byte> { |
| 70 | + @Override public Class<Byte> getInputType() { return Byte.class; } |
| 71 | + } |
| 72 | + |
| 73 | + @Plugin(type = Converter.class) |
| 74 | + public static class ShortToLongConverter extends NumberToLongConverter<Short> { |
| 75 | + @Override public Class<Short> getInputType() { return Short.class; } |
| 76 | + } |
| 77 | + |
| 78 | + @Plugin(type = Converter.class) |
| 79 | + public static class IntegerToLongConverter extends NumberToLongConverter<Integer> { |
| 80 | + @Override public Class<Integer> getInputType() { return Integer.class; } |
| 81 | + } |
| 82 | + |
| 83 | + //convert to float |
| 84 | + @Plugin(type = Converter.class) |
| 85 | + public static class ByteToFloatConverter extends NumberToFloatConverter<Byte> { |
| 86 | + @Override public Class<Byte> getInputType() { return Byte.class; } |
| 87 | + } |
| 88 | + |
| 89 | + @Plugin(type = Converter.class) |
| 90 | + public static class ShortToFloatConverter extends NumberToFloatConverter<Short> { |
| 91 | + @Override public Class<Short> getInputType() { return Short.class; } |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + //convert to double |
| 96 | + @Plugin(type = Converter.class) |
| 97 | + public static class ByteToDoubleConverter extends NumberToDoubleConverter<Byte> { |
| 98 | + @Override public Class<Byte> getInputType() { return Byte.class; } |
| 99 | + } |
| 100 | + |
| 101 | + @Plugin(type = Converter.class) |
| 102 | + public static class ShortToDoubleConverter extends NumberToDoubleConverter<Short> { |
| 103 | + @Override public Class<Short> getInputType() { return Short.class; } |
| 104 | + } |
| 105 | + |
| 106 | + @Plugin(type = Converter.class) |
| 107 | + public static class IntegerToDoubleConverter extends NumberToDoubleConverter<Integer> { |
| 108 | + @Override public Class<Integer> getInputType() { return Integer.class; } |
| 109 | + } |
| 110 | + |
| 111 | + @Plugin(type = Converter.class) |
| 112 | + public static class FloatToDoubleConverter extends NumberToDoubleConverter<Float> { |
| 113 | + @Override public Class<Float> getInputType() { return Float.class; } |
| 114 | + } |
| 115 | + |
| 116 | + //convert to BigInteger |
| 117 | + @Plugin(type = Converter.class) |
| 118 | + public static class ByteToBigIntegerConverter extends NumberToBigIntegerConverter<Byte> { |
| 119 | + @Override public Class<Byte> getInputType() { return Byte.class; } |
| 120 | + } |
| 121 | + |
| 122 | + @Plugin(type = Converter.class) |
| 123 | + public static class ShortToBigIntegerConverter extends NumberToBigIntegerConverter<Short> { |
| 124 | + @Override public Class<Short> getInputType() { return Short.class; } |
| 125 | + } |
| 126 | + |
| 127 | + @Plugin(type = Converter.class) |
| 128 | + public static class IntegerToBigIntegerConverter extends NumberToBigIntegerConverter<Integer> { |
| 129 | + @Override public Class<Integer> getInputType() { return Integer.class; } |
| 130 | + } |
| 131 | + |
| 132 | + @Plugin(type = Converter.class) |
| 133 | + public static class LongToBigIntegerConverter extends NumberToBigIntegerConverter<Long> { |
| 134 | + @Override public Class<Long> getInputType() { return Long.class; } |
| 135 | + } |
| 136 | + |
| 137 | + //convert to BigDecimal |
| 138 | + @Plugin(type = Converter.class) |
| 139 | + public static class ByteToBigDecimalConverter extends NumberToBigDecimalConverter<Byte> { |
| 140 | + @Override public Class<Byte> getInputType() { return Byte.class; } |
| 141 | + } |
| 142 | + |
| 143 | + @Plugin(type = Converter.class) |
| 144 | + public static class ShortToBigDecimalConverter extends NumberToBigDecimalConverter<Short> { |
| 145 | + @Override public Class<Short> getInputType() { return Short.class; } |
| 146 | + } |
| 147 | + |
| 148 | + @Plugin(type = Converter.class) |
| 149 | + public static class IntegerToBigDecimalConverter extends NumberToBigDecimalConverter<Integer> { |
| 150 | + @Override public Class<Integer> getInputType() { return Integer.class; } |
| 151 | + } |
| 152 | + |
| 153 | + @Plugin(type = Converter.class) |
| 154 | + public static class LongToBigDecimalConverter extends NumberToBigDecimalConverter<Long> { |
| 155 | + @Override public Class<Long> getInputType() { return Long.class; } |
| 156 | + } |
| 157 | + |
| 158 | + @Plugin(type = Converter.class) |
| 159 | + public static class FloatToBigDecimalConverter extends NumberToBigDecimalConverter<Float> { |
| 160 | + @Override public Class<Float> getInputType() { return Float.class; } |
| 161 | + } |
| 162 | + |
| 163 | + @Plugin(type = Converter.class) |
| 164 | + public static class DoubleToBigDecimalConverter extends NumberToBigDecimalConverter<Double> { |
| 165 | + @Override public Class<Double> getInputType() { return Double.class; } |
| 166 | + } |
| 167 | + |
| 168 | + @Plugin(type = Converter.class) |
| 169 | + public static class BigIntegerToBigDecimalConverter extends NumberToBigDecimalConverter<BigInteger> { |
| 170 | + @Override public Class<BigInteger> getInputType() { return BigInteger.class; } |
| 171 | + } |
| 172 | + |
| 173 | +} |
0 commit comments