io.github.nichetoolkit.mybatis.defaults.DefaultColumnFactoryChain Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mybatis-toolkit-context Show documentation
Show all versions of mybatis-toolkit-context Show documentation
Mybatis toolkit context project for Spring Boot
The newest version!
package io.github.nichetoolkit.mybatis.defaults;
import io.github.nichetoolkit.mybatis.MybatisColumn;
import io.github.nichetoolkit.mybatis.MybatisColumnFactory;
import io.github.nichetoolkit.mybatis.MybatisField;
import io.github.nichetoolkit.mybatis.MybatisTable;
import org.springframework.lang.NonNull;
import java.util.List;
import java.util.Optional;
/**
* DefaultColumnFactoryChain
* The default column factory chain class.
* @author Cyan ([email protected])
* @see io.github.nichetoolkit.mybatis.MybatisColumnFactory.Chain
* @since Jdk1.8
*/
public class DefaultColumnFactoryChain implements MybatisColumnFactory.Chain {
/**
* factories
* {@link java.util.List} The factories
field.
* @see java.util.List
*/
private final List factories;
/**
* next
* {@link io.github.nichetoolkit.mybatis.defaults.DefaultColumnFactoryChain} The next
field.
*/
private final DefaultColumnFactoryChain next;
/**
* index
* The index
field.
*/
private final int index;
/**
* DefaultColumnFactoryChain
* Instantiates a new default column factory chain.
* @param factories {@link java.util.List} The factories parameter is List
type.
* @see java.util.List
*/
public DefaultColumnFactoryChain(List factories) {
this(factories, 0);
}
/**
* DefaultColumnFactoryChain
* Instantiates a new default column factory chain.
* @param factories {@link java.util.List} The factories parameter is List
type.
* @param index int The index parameter is int
type.
* @see java.util.List
*/
private DefaultColumnFactoryChain(List factories, int index) {
this.factories = factories;
this.index = index;
if (this.index < this.factories.size()) {
this.next = new DefaultColumnFactoryChain(factories, this.index + 1);
} else {
this.next = null;
}
}
@Override
public Optional> createColumn(@NonNull MybatisTable mybatisTable,@NonNull MybatisField mybatisField) {
if (index < factories.size()) {
MybatisColumnFactory mybatisColumnFactory = factories.get(index);
if (mybatisColumnFactory.supports(mybatisTable,mybatisField)) {
return mybatisColumnFactory.createColumn(mybatisTable, mybatisField, next);
}
}
return Optional.empty();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy