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

io.github.astrapi69.crypt.data.obfuscation.rules.ObfuscationRules Maven / Gradle / Ivy

Go to download

Utility project that provides data beans, writers and readers for encryption and decryption

There is a newer version: 10
Show newest version
/**
 * The MIT License
 *
 * Copyright (C) 2015 Asterios Raptis
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package io.github.astrapi69.crypt.data.obfuscation.rules;

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

import io.github.astrapi69.crypt.data.obfuscation.rule.ObfuscationRule;

/**
 * The class {@link ObfuscationRules} holds a list of obfuscation rules that will be processed with
 * an Obfusactor implementation.
 *
 * @param 
 *            the type parameter
 * @param 
 *            the type parameter
 */
public class ObfuscationRules
{

	/** The obfuscation rules. */
	private List> rules;

	/**
	 * Instantiates a new Obfuscation rules.
	 */
	public ObfuscationRules()
	{
	}

	/**
	 * Instantiates a new Obfuscation rules.
	 *
	 * @param rules
	 *            the rules
	 */
	public ObfuscationRules(List> rules)
	{
		this.rules = rules;
	}

	/**
	 * Builder obfuscation rules builder.
	 *
	 * @param 
	 *            the type parameter
	 * @param 
	 *            the type parameter
	 * @return the obfuscation rules builder
	 */
	public static  ObfuscationRulesBuilder builder()
	{
		return new ObfuscationRulesBuilder();
	}

	/**
	 * Can equal boolean.
	 *
	 * @param other
	 *            the other
	 * @return the boolean
	 */
	protected boolean canEqual(final Object other)
	{
		return other instanceof ObfuscationRules;
	}

	@Override
	public boolean equals(final Object o)
	{
		if (o == this)
			return true;
		if (!(o instanceof ObfuscationRules))
			return false;
		final ObfuscationRules other = (ObfuscationRules)o;
		if (!other.canEqual(this))
			return false;
		final Object this$rules = this.getRules();
		final Object other$rules = other.getRules();
		return this$rules == null ? other$rules == null : this$rules.equals(other$rules);
	}

	/**
	 * Gets rules.
	 *
	 * @return the rules
	 */
	public List> getRules()
	{
		return this.rules;
	}

	/**
	 * Sets rules.
	 *
	 * @param rules
	 *            the rules
	 */
	public void setRules(List> rules)
	{
		this.rules = rules;
	}

	@Override
	public int hashCode()
	{
		final int PRIME = 59;
		int result = 1;
		final Object $rules = this.getRules();
		result = result * PRIME + ($rules == null ? 43 : $rules.hashCode());
		return result;
	}

	/**
	 * To builder obfuscation rules builder.
	 *
	 * @return the obfuscation rules builder
	 */
	public ObfuscationRulesBuilder toBuilder()
	{
		return new ObfuscationRulesBuilder()
			.rules(this.rules == null ? java.util.Collections.emptyList() : this.rules);
	}

	@Override
	public String toString()
	{
		return "ObfuscationRules(rules=" + this.getRules() + ")";
	}

	/**
	 * The type Obfuscation rules builder.
	 *
	 * @param 
	 *            the type parameter
	 * @param 
	 *            the type parameter
	 */
	public static class ObfuscationRulesBuilder
	{
		private ArrayList> rules;

		/**
		 * Instantiates a new Obfuscation rules builder.
		 */
		ObfuscationRulesBuilder()
		{
		}

		/**
		 * Build obfuscation rules.
		 *
		 * @return the obfuscation rules
		 */
		public ObfuscationRules build()
		{
			List> rules;
			switch (this.rules == null ? 0 : this.rules.size())
			{
				case 0 :
					rules = java.util.Collections.emptyList();
					break;
				case 1 :
					rules = java.util.Collections.singletonList(this.rules.get(0));
					break;
				default :
					rules = java.util.Collections
						.unmodifiableList(new ArrayList>(this.rules));
			}

			return new ObfuscationRules(rules);
		}

		/**
		 * Clear rules obfuscation rules . obfuscation rules builder.
		 *
		 * @return the obfuscation rules . obfuscation rules builder
		 */
		public ObfuscationRules.ObfuscationRulesBuilder clearRules()
		{
			if (this.rules != null)
				this.rules.clear();
			return this;
		}

		/**
		 * Rule obfuscation rules . obfuscation rules builder.
		 *
		 * @param rule
		 *            the rule
		 * @return the obfuscation rules . obfuscation rules builder
		 */
		public ObfuscationRules.ObfuscationRulesBuilder rule(ObfuscationRule rule)
		{
			if (this.rules == null)
				this.rules = new ArrayList>();
			this.rules.add(rule);
			return this;
		}

		/**
		 * Rules obfuscation rules . obfuscation rules builder.
		 *
		 * @param rules
		 *            the rules
		 * @return the obfuscation rules . obfuscation rules builder
		 */
		public ObfuscationRules.ObfuscationRulesBuilder rules(
			Collection> rules)
		{
			if (this.rules == null)
				this.rules = new ArrayList>();
			this.rules.addAll(rules);
			return this;
		}

		@Override
		public String toString()
		{
			return "ObfuscationRules.ObfuscationRulesBuilder(rules=" + this.rules + ")";
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy