001/*
002 * Copyright (C) 2012 Facebook, Inc.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may
005 * not use this file except in compliance with the License. You may obtain
006 * a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013 * License for the specific language governing permissions and limitations
014 * under the License.
015 */
016package com.facebook.swift.codec.internal.coercion;
017
018import javax.annotation.concurrent.Immutable;
019import java.nio.ByteBuffer;
020
021import static com.google.common.base.Charsets.UTF_8;
022
023@Immutable
024public final class DefaultJavaCoercions
025{
026    private DefaultJavaCoercions()
027    {
028    }
029
030    @FromThrift
031    public static Boolean booleanToBoxedBoolean(boolean value)
032    {
033        return value;
034    }
035
036    @ToThrift
037    public static boolean boxedBooleanToBoolean(Boolean value)
038    {
039        return value;
040    }
041
042    @FromThrift
043    public static Byte byteToBoxedByte(byte value)
044    {
045        return value;
046    }
047
048    @ToThrift
049    public static byte boxedByteToByte(Byte value)
050    {
051        return value;
052    }
053
054    @FromThrift
055    public static Short shortToBoxedShort(short value)
056    {
057        return value;
058    }
059
060    @ToThrift
061    public static short boxedShortToShort(Short value)
062    {
063        return value;
064    }
065
066    @FromThrift
067    public static Integer integerToBoxedInteger(int value)
068    {
069        return value;
070    }
071
072    @ToThrift
073    public static int boxedIntegerToInteger(Integer value)
074    {
075        return value;
076    }
077
078    @FromThrift
079    public static Long longToBoxedLong(long value)
080    {
081        return value;
082    }
083
084    @ToThrift
085    public static long boxedLongToLong(Long value)
086    {
087        return value;
088    }
089
090    @FromThrift
091    public static float doubleToPrimitiveFloat(double value)
092    {
093        return (float) value;
094    }
095
096    @ToThrift
097    public static double primitiveFloatToDouble(float value)
098    {
099        return value;
100    }
101
102    @FromThrift
103    public static Float doubleToBoxedFloat(double value)
104    {
105        return (float) value;
106    }
107
108    @ToThrift
109    public static double boxedFloatToDouble(Float value)
110    {
111        return value;
112    }
113
114    @FromThrift
115    public static Double doubleToBoxedDouble(double value)
116    {
117        return value;
118    }
119
120    @ToThrift
121    public static double boxedDoubleToDouble(Double value)
122    {
123        return value;
124    }
125
126    @FromThrift
127    public static byte[] byteBufferToByteArray(ByteBuffer buffer)
128    {
129        byte[] result = new byte[buffer.remaining()];
130        buffer.duplicate().get(result);
131        return result;
132    }
133
134    @ToThrift
135    public static ByteBuffer byteArrayToByteBuffer(byte[] value)
136    {
137        return ByteBuffer.wrap(value);
138    }
139}