fr.ird.observe.spi.context.OpenableDtoServiceContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit-service Show documentation
Show all versions of toolkit-service Show documentation
ObServe Toolkit Service module
The newest version!
package fr.ird.observe.spi.context;
/*-
* #%L
* ObServe Toolkit :: Service
* %%
* Copyright (C) 2017 - 2021 Ultreia.io
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
import fr.ird.observe.dto.data.OpenableDto;
import fr.ird.observe.dto.reference.DataDtoReference;
import fr.ird.observe.dto.referential.ReferentialLocale;
import fr.ird.observe.spi.ServicesProvider;
import fr.ird.observe.spi.decoration.DecoratorService;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Created on 17/10/2020.
*
* @author Tony Chemit - [email protected]
* @since 8.0.1
*/
public class OpenableDtoServiceContext {
/**
* Data type.
*/
private final Class dtoType;
/**
* Reference type.
*/
private final Class referenceType;
/**
* To sort references.
*/
private final Comparator referenceComparator;
/**
* To create a new reference.
*/
private final Supplier referenceConstructor;
public static OpenableDtoServiceContext of(Class dtoType, Class referenceType, Comparator referenceComparator, Supplier referenceConstructor) {
return new OpenableDtoServiceContext<>(dtoType, referenceType, referenceComparator, referenceConstructor);
}
public OpenableDtoServiceContext(Class dtoType, Class referenceType, Comparator referenceComparator, Supplier referenceConstructor) {
this.dtoType = Objects.requireNonNull(dtoType);
this.referenceType = Objects.requireNonNull(referenceType);
this.referenceComparator = Objects.requireNonNull(referenceComparator);
this.referenceConstructor = Objects.requireNonNull(referenceConstructor);
}
public EmptyChildrenDataReferenceSet newEmptyChildrenDataReferenceSet(String parentId, int initialCount, ServicesProvider servicesProvider, DecoratorService decoratorService) {
return new EmptyChildrenDataReferenceSet<>(parentId, initialCount, this, servicesProvider, decoratorService);
}
public Class getDtoType() {
return dtoType;
}
public Class getReferenceType() {
return referenceType;
}
public Comparator getReferenceComparator() {
return referenceComparator;
}
@SuppressWarnings("unused")
public R newReference(ReferentialLocale referentialLocale) {
return referenceConstructor.get();
}
public List sort(Stream stream) {
return stream.sorted(referenceComparator).collect(Collectors.toList());
}
// public List initChildrenDataReferenceSet(Collection children, DecoratorService decoratorService) {
// List result = new ArrayList<>(children);
// result.sort(getReferenceComparator());
// decoratorService.installDecorator(referenceType, result.stream());
// return result;
// }
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy