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

nosi.core.webapp.helpers.CheckBoxHelper Maven / Gradle / Ivy

Go to download

IGRP Framework is a powerful and highly customizable platform developed by the Operational Nucleus for the Information Society (NOSi) to create web applications, it provides out of box, several modules to make easy to create stand-alone, production-grade web applications: authentication and access-control, business processes automation, reporting, page builder with automatic code generation and incorporation of the Once-Only-Principle, written in Java. IGRP Framework WAR - Contains some keys resources that give UI to IGRP Framework and others supports files.

There is a newer version: 2.0.0.241121-RCM
Show newest version
package nosi.core.webapp.helpers;

import java.util.ArrayList;
import java.util.List;

import nosi.core.gui.fields.Field;
import nosi.core.webapp.Core;

/**
 * Emanuel 5 Feb 2019
 */

public class CheckBoxHelper {

	private final List chekedIds;
	private final List uncheckedIds;

	private CheckBoxHelper(String[] allValues, String[] checkedValues) {
		this.chekedIds = new ArrayList<>();
		this.uncheckedIds = new ArrayList<>();
		this.extract(allValues, checkedValues);
	}

	public static CheckBoxHelper of(String[] allValues, String[] checkedValues) {
		return new CheckBoxHelper(allValues, checkedValues);
	}

	public static CheckBoxHelper of(Field field) {
		final String[] allValues = Core.getParamArray(field.getParamTag().concat("_fk"));
		final String[] checkedValues = Core.getParamArray(field.getParamTag().concat("_check_fk"));
		return CheckBoxHelper.of(allValues, checkedValues);
	}

	private void extract(String[] allValues, String[] checkedValues) {
		if (!Core.isNotNullMultiple(allValues, checkedValues)) 
			throw new NullPointerException("The values are null...");
			
		
		if (!Core.isArraySameSize(allValues, checkedValues))
			throw new IllegalArgumentException("The arrays provided are not the same...");

		for (int i = 0; i < allValues.length; i++) {
			if (allValues[i].compareTo(checkedValues[i]) == 0) {
				this.chekedIds.add(allValues[i]);
				continue;
			}
			this.uncheckedIds.add(allValues[i]);
		}
	}

	public List getChekedIds() {
		return this.chekedIds;
	}

	public List getUncheckedIds() {
		return this.uncheckedIds;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy