
tools.dynamia.web.util.EntityWrapperController Maven / Gradle / Ivy
/*
* Copyright (C) 2021 Dynamia Soluciones IT S.A.S - NIT 900302344-1
* Colombia / South America
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package tools.dynamia.web.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
*
* @author Ing. Mario Serrano Leones
*/
public class EntityWrapperController {
private EntityWrapperController() {
throw new IllegalAccessError("Private Constructor");
}
public static List> wrap(Collection entities) {
List> result = new ArrayList<>();
for (T entity : entities) {
result.add(new EntityWrapper<>(entity));
}
return result;
}
public static EntityWrapper wrap(T entity) {
return new EntityWrapper<>(entity);
}
public static EntityWrapper find(T entity, List extends EntityWrapper> wrappedEntities) {
if (wrappedEntities != null && entity != null) {
for (EntityWrapper entityWrapper : wrappedEntities) {
if (entityWrapper.getEntity().equals(entity)) {
return entityWrapper;
}
}
}
return null;
}
public static T getFirstSelected(List extends EntityWrapper> wrappedEntities) {
if (wrappedEntities != null) {
for (EntityWrapper entityWrapper : wrappedEntities) {
if (entityWrapper.isSelected()) {
return entityWrapper.getEntity();
}
}
}
return null;
}
public static List getAllSelected(List extends EntityWrapper> wrappedEntities) {
List selectedList = new ArrayList<>();
if (wrappedEntities != null) {
for (EntityWrapper entityWrapper : wrappedEntities) {
if (entityWrapper.isSelected()) {
selectedList.add(entityWrapper.getEntity());
}
}
}
return selectedList;
}
public static void setSelected(T entity, List extends EntityWrapper> wrappedEntities) {
if (wrappedEntities != null && entity != null) {
for (EntityWrapper entityWrapper : wrappedEntities) {
entityWrapper.setSelected(entityWrapper.getEntity().equals(entity));
}
}
}
public static void selectAll(List entities, List extends EntityWrapper> wrappedEntities) {
if (entities != null && wrappedEntities != null) {
for (EntityWrapper entityWrapper : wrappedEntities) {
if (entities.contains(entityWrapper.getEntity())) {
entityWrapper.setSelected(true);
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy