All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mapstruct.Condition Maven / Gradle / Ivy

There is a newer version: 1.6.3
Show newest version
/*
 * Copyright MapStruct Authors.
 *
 * Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
 */
package org.mapstruct;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * This annotation marks a method as a presence check method to check check for presence in beans.
 * 

* By default bean properties are checked against {@code null} or using a presence check method in the source bean. * If a presence check method is available then it will be used instead. *

* Presence check methods have to return {@code boolean}. * The following parameters are accepted for the presence check methods: *

    *
  • The parameter with the value of the source property. * e.g. the value given by calling {@code getName()} for the name property of the source bean
  • *
  • The mapping source parameter
  • *
  • {@code @}{@link Context} parameter
  • *
* * Note: The usage of this annotation is mandatory * for a method to be considered as a presence check method. * *

 * public class PresenceCheckUtils {
 *
 *   @Condition
 *   public static boolean isNotEmpty(String value) {
 *      return value != null && !value.isEmpty();
 *   }
 * }
 *
 * @Mapper(uses = PresenceCheckUtils.class)
 * public interface MovieMapper {
 *
 *     MovieDto map(Movie movie);
 * }
 * 
* * The following implementation of {@code MovieMapper} will be generated: * *
 * 
 * public class MovieMapperImpl implements MovieMapper {
 *
 *     @Override
 *     public MovieDto map(Movie movie) {
 *         if ( movie == null ) {
 *             return null;
 *         }
 *
 *         MovieDto movieDto = new MovieDto();
 *
 *         if ( PresenceCheckUtils.isNotEmpty( movie.getTitle() ) ) {
 *             movieDto.setTitle( movie.getTitle() );
 *         }
 *
 *         return movieDto;
 *     }
 * }
 * 
 * 
* * @author Filip Hrisafov * @since 1.5 */ @Target({ ElementType.METHOD }) @Retention(RetentionPolicy.CLASS) public @interface Condition { }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy