org.modelmapper.protobuf.primitive.DoubleConverters Maven / Gradle / Ivy
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.modelmapper.protobuf.primitive;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.Int64Value;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;
/**
* Converters for double.
*
* @author Chun Han Hsiao
*/
public class DoubleConverters {
public static final Converter BUILDER_TO_DOUBLE = new Converter() {
@Override
public Double convert(MappingContext context) {
if (context.getSource() != null)
return context.getSource().getValue();
return null;
}
};
public static final Converter DOUBLE_VALUE_TO_DOUBLE = new Converter() {
@Override
public Double convert(MappingContext context) {
if (context.getSource() != null)
return context.getSource().getValue();
return null;
}
};
public static final Converter DOUBLE_TO_BUILDER = new Converter() {
@Override
public DoubleValue.Builder convert(MappingContext context) {
if (context.getSource() != null)
return DoubleValue.newBuilder().setValue(context.getSource());
return null;
}
};
public static final Converter DOUBLE_TO_DOUBLE_VALUE = new Converter() {
@Override
public DoubleValue convert(MappingContext context) {
if (context.getSource() != null)
return DoubleValue.of(context.getSource());
return null;
}
};
}