org.modelmapper.protobuf.primitive.IntConverters 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.Int32Value;
import com.google.protobuf.Int64Value;
import org.modelmapper.Converter;
import org.modelmapper.spi.MappingContext;
/**
* Converters for bool.
*
* @author Chun Han Hsiao
*/
public class IntConverters {
public static final Converter BUILDER_TO_INT = new Converter() {
@Override
public Integer convert(MappingContext context) {
if (context.getSource() != null)
return context.getSource().getValue();
return null;
}
};
public static final Converter BUILDER_TO_LONG = new Converter() {
@Override
public Long convert(MappingContext context) {
if (context.getSource() != null)
return context.getSource().getValue();
return null;
}
};
public static final Converter INT_VALUE_TO_INT = new Converter() {
@Override
public Integer convert(MappingContext context) {
if (context.getSource() != null)
return context.getSource().getValue();
return null;
}
};
public static final Converter LONG_VALUE_TO_LONG = new Converter() {
@Override
public Long convert(MappingContext context) {
if (context.getSource() != null)
return context.getSource().getValue();
return null;
}
};
public static final Converter INT_TO_BUILDER = new Converter() {
@Override
public Int32Value.Builder convert(MappingContext context) {
if (context.getSource() != null)
return Int32Value.newBuilder().setValue(context.getSource());
return null;
}
};
public static final Converter LONG_TO_BUILDER = new Converter() {
@Override
public Int64Value.Builder convert(MappingContext context) {
if (context.getSource() != null)
return Int64Value.newBuilder().setValue(context.getSource());
return null;
}
};
public static final Converter INT_TO_INT_VALUE = new Converter() {
@Override
public Int32Value convert(MappingContext context) {
if (context.getSource() != null)
return Int32Value.of(context.getSource());
return null;
}
};
public static final Converter LONG_TO_LONG_VALUE = new Converter() {
@Override
public Int64Value convert(MappingContext context) {
if (context.getSource() != null)
return Int64Value.of(context.getSource());
return null;
}
};
}