package mapper; import api.v1.CoordinateFormat; import api.v1.UserPreferences; import models.UserPreferenceModel; public class UserPrefsMapper { public UserPreferences mapToApi(UserPreferenceModel userPreferenceModel) { UserPreferences prefs = new UserPreferences(); switch (userPreferenceModel.coordinateFormat){ case DECIMAL_DEGREES: prefs.coordinateFormat = CoordinateFormat.DECIMAL_DEGREES; break; case DEGREES_MINUTES_SECONDS: prefs.coordinateFormat = CoordinateFormat.DEGREES_MINUTES_SECONDS; break; case UTM: prefs.coordinateFormat = CoordinateFormat.UTM; break; } prefs.showGrid= userPreferenceModel.showGrid; return prefs; } public UserPreferenceModel mapToModel(UserPreferences prefs, UserPreferenceModel model) { if (model == null) model = new UserPreferenceModel(); switch (prefs.coordinateFormat){ case DECIMAL_DEGREES: model.coordinateFormat = models.CoordinateFormat.DECIMAL_DEGREES; break; case DEGREES_MINUTES_SECONDS: model.coordinateFormat = models.CoordinateFormat.DEGREES_MINUTES_SECONDS; break; case UTM: model.coordinateFormat = models.CoordinateFormat.UTM; break; } model.showGrid= prefs.showGrid; return model; } public UserPreferenceModel mapToModel(UserPreferenceModel prefs) { UserPreferenceModel model = new UserPreferenceModel(); switch (prefs.coordinateFormat){ case DECIMAL_DEGREES: model.coordinateFormat = models.CoordinateFormat.DECIMAL_DEGREES; break; case DEGREES_MINUTES_SECONDS: model.coordinateFormat = models.CoordinateFormat.DEGREES_MINUTES_SECONDS; break; case UTM: model.coordinateFormat = models.CoordinateFormat.UTM; break; } model.showGrid= prefs.showGrid; return model; } }