001/*-------------------------------------------------------------------------+ 002| | 003| Copyright 2005-2011 the ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016+-------------------------------------------------------------------------*/ 017package org.conqat.lib.commons.serialization.classes; 018 019import java.io.DataInputStream; 020import java.io.DataOutputStream; 021import java.io.IOException; 022 023import org.conqat.lib.commons.serialization.SerializedEntityParser; 024import org.conqat.lib.commons.serialization.SerializedEntityPool; 025import org.conqat.lib.commons.serialization.SerializedEntitySerializer; 026 027/** 028 * Field for double. 029 */ 030public class SerializedDoubleField extends SerializedPrimitiveFieldBase { 031 032 /** The type code. */ 033 public static final char TYPE_CODE = 'D'; 034 035 /** Constructor. */ 036 public SerializedDoubleField(String name) { 037 super(name); 038 } 039 040 /** {@inheritDoc} */ 041 @Override 042 public Object readValue(DataInputStream din, SerializedEntityParser parser) throws IOException { 043 return din.readDouble(); 044 } 045 046 /** {@inheritDoc} */ 047 @Override 048 public void writeValue(Object value, SerializedEntityPool pool, DataOutputStream dos, 049 SerializedEntitySerializer serializer) throws IOException { 050 dos.writeDouble(ensureType(value, Double.class)); 051 } 052 053 /** {@inheritDoc} */ 054 @Override 055 protected char getTypeCode() { 056 return TYPE_CODE; 057 } 058}