org.entur.gbfs.mapper.SystemInformationAdditionalMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gbfs-mapper-java Show documentation
Show all versions of gbfs-mapper-java Show documentation
Enables mapping between different versions of GBFS (bidirectional)
package org.entur.gbfs.mapper;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import java.util.List;
@Mapper(imports = {List.class})
public abstract class SystemInformationAdditionalMapper {
@SystemInformationDataMapper
@Mapping(target = "languages", expression = "java(List.of(language))")
abstract org.mobilitydata.gbfs.v3_0.system_information.GBFSData mapData(org.mobilitydata.gbfs.v2_3.system_information.GBFSData source, @Context String language);
@SystemInformationDataMapper
@Mapping(target = "language", expression = "java(language)")
abstract org.mobilitydata.gbfs.v2_3.system_information.GBFSData mapDataInverse(org.mobilitydata.gbfs.v3_0.system_information.GBFSData source, @Context String language);
List mapName(String value, @Context String language) {
if (value == null) {
return null;
}
return List.of(
new org.mobilitydata.gbfs.v3_0.system_information.GBFSName()
.withText(value)
.withLanguage(language)
);
}
String mapNameInverse(List values, @Context String language) {
if (values == null) {
return null;
}
return values.stream()
.filter(name -> name.getLanguage().equals(language))
.map(org.mobilitydata.gbfs.v3_0.system_information.GBFSName::getText)
.findFirst().orElse(null);
}
List mapShortName(String value, @Context String language) {
if (value == null) {
return null;
}
return List.of(
new org.mobilitydata.gbfs.v3_0.system_information.GBFSShortName()
.withText(value)
.withLanguage(language)
);
}
String mapShortNameInverse(List values, @Context String language) {
if (values == null) {
return null;
}
return values.stream()
.filter(name -> name.getLanguage().equals(language))
.map(org.mobilitydata.gbfs.v3_0.system_information.GBFSShortName::getText)
.findFirst().orElse(null);
}
List mapOperator(String operator, @Context String language) {
if (operator == null) {
return null;
}
return List.of(
new org.mobilitydata.gbfs.v3_0.system_information.GBFSOperator()
.withText(operator)
.withLanguage(language)
);
}
String mapOperatorInverse(List values, @Context String language) {
if (values == null) {
return null;
}
return values.stream()
.filter(name -> name.getLanguage().equals(language))
.map(org.mobilitydata.gbfs.v3_0.system_information.GBFSOperator::getText)
.findFirst().orElse(null);
}
List mapTermsUrl(String termsUrl, @Context String language) {
if (termsUrl == null) {
return null;
}
return List.of(
new org.mobilitydata.gbfs.v3_0.system_information.GBFSTermsUrl()
.withText(termsUrl)
.withLanguage(language)
);
}
String mapTermsUrlInverse(List values, @Context String language) {
if (values == null) {
return null;
}
return values.stream()
.filter(name -> name.getLanguage().equals(language))
.map(org.mobilitydata.gbfs.v3_0.system_information.GBFSTermsUrl::getText)
.findFirst().orElse(null);
}
List mapPrivacyUrl(String privacyUrl, @Context String language) {
if (privacyUrl == null) {
return null;
}
return List.of(
new org.mobilitydata.gbfs.v3_0.system_information.GBFSPrivacyUrl()
.withText(privacyUrl)
.withLanguage(language)
);
}
String mapPrivacyUrlInverse(List values, @Context String language) {
if (values == null) {
return null;
}
return values.stream()
.filter(name -> name.getLanguage().equals(language))
.map(org.mobilitydata.gbfs.v3_0.system_information.GBFSPrivacyUrl::getText)
.findFirst().orElse(null);
}
}