001/* 002 * This file is part of OCaml-Java runtime. 003 * Copyright (C) 2007-2013 Xavier Clerc. 004 * 005 * OCaml-Java runtime is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation; either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * OCaml-Java runtime is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.ocamljava.runtime.wrappers; 020 021import org.ocamljava.runtime.values.Value; 022 023/** 024 * The {@code OCamlInt64} class is the wrapper class for OCaml values of 025 * type {@code int64}. 026 * 027 * @author <a href="mailto:xclerc@ocamljava.org">Xavier Clerc</a> 028 * @version 2.0 029 * @since 2.0 030 */ 031public final class OCamlInt64 extends OCamlValue implements OCamlNumber { 032 033 /** Wrapper for {@code OCamlInt64} values. */ 034 public static final Wrapper<OCamlInt64> WRAPPER = new SimpleWrapper<OCamlInt64>() { 035 036 /** 037 * {@inheritDoc} 038 */ 039 @Override 040 public OCamlInt64 wrap(final Value v) { 041 return new OCamlInt64(v); 042 } // end method 'wrap(Value)' 043 044 }; // end anonymous inner-class 045 046 /** 047 * Constructs a new instance wrapping the passed value. 048 * @param v value to wrap - should not be {@code null} 049 */ 050 private OCamlInt64(final Value v) { 051 super(v); 052 } // end constructor(Value) 053 054 /** 055 * {@inheritDoc} 056 */ 057 @Override 058 public Wrapper<? extends OCamlInt64> getWrapper() { 059 return OCamlInt64.WRAPPER; 060 } // end method 'getWrapper()' 061 062 /** 063 * {@inheritDoc} 064 */ 065 @Override 066 public Wrapper<? extends OCamlValue> getWrapper(final int idx) { 067 return OCamlUnit.WRAPPER; 068 } // end method 'getWrapper(int)' 069 070 /** 071 * {@inheritDoc} 072 */ 073 @Override 074 public byte byteValue() { 075 return (byte) this.value.asInt64(); 076 } // end method 'byteValue()' 077 078 /** 079 * {@inheritDoc} 080 */ 081 @Override 082 public double doubleValue() { 083 return (double) this.value.asInt64(); 084 } // end method 'doubleValue()' 085 086 /** 087 * {@inheritDoc} 088 */ 089 @Override 090 public float floatValue() { 091 return (float) this.value.asInt64(); 092 } // end method 'floatValue()' 093 094 /** 095 * {@inheritDoc} 096 */ 097 @Override 098 public int intValue() { 099 return (int) this.value.asInt64(); 100 } // end method 'intValue()' 101 102 /** 103 * {@inheritDoc} 104 */ 105 @Override 106 public long longValue() { 107 return this.value.asInt64(); 108 } // end method 'longValue()' 109 110 /** 111 * {@inheritDoc} 112 */ 113 @Override 114 public short shortValue() { 115 return (short) this.value.asInt64(); 116 } // end method 'shortValue()' 117 118 /** 119 * {@inheritDoc} 120 */ 121 @Override 122 public int hashCode() { 123 return (int) this.value.asInt64(); 124 } // end method 'hashCode()' 125 126 /** 127 * {@inheritDoc} 128 */ 129 @Override 130 public boolean equals(final Object obj) { 131 if (obj instanceof OCamlInt64) { 132 final OCamlInt64 that = (OCamlInt64) obj; 133 return this.value.asInt64() == that.value.asInt64(); 134 } else { 135 return false; 136 } // end if/else 137 } // end method 'equals(Object)' 138 139 /** 140 * {@inheritDoc} 141 */ 142 @Override 143 public String toString() { 144 final StringBuilder sb = new StringBuilder(); 145 sb.append("OCamlInt64("); 146 sb.append(this.value.asInt64()); 147 sb.append(")"); 148 return sb.toString(); 149 } // end method 'toString()' 150 151 /** 152 * Constructs a new {@code int64} value, and wraps it. 153 * @param v value to wrap 154 * @return a new {@code OCamlInt64} instance wrapping the passed value 155 */ 156 public static OCamlInt64 create(final long v) { 157 return new OCamlInt64(Value.createInt64(v)); 158 } // end method 'create(long)' 159 160 /** 161 * Wraps the passed value. 162 * @param v value to wrap - should not be {@code null} 163 * @return a new {@code OCamlInt64} instance wrapping the passed value 164 */ 165 public static OCamlInt64 wrap(final Value v) { 166 assert v != null : "null v"; 167 return new OCamlInt64(v); 168 } // end method 'wrap(Value)' 169 170 /** 171 * Returns a wrapper for {@code OCamlInt64} values. 172 * @return a wrapper for {@code OCamlInt64} values 173 */ 174 public static Wrapper<? extends OCamlInt64> wrapper() { 175 return OCamlInt64.WRAPPER; 176 } // end method 'wrapper()' 177 178} // end class 'OCamlInt64'