//# 0 errors, 172 messages
//#
/*
    //#RegexStringList.java:1:1: class: com.dmdirc.parser.irc.RegexStringList
    //#RegexStringList.java:1:1: method: com.dmdirc.parser.irc.RegexStringList.com.dmdirc.parser.irc.RegexStringList__static_init
 * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
 *
 * 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 com.dmdirc.parser.irc;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.PatternSyntaxException;

/**
 * IRC Parser Ignore list.
 *
 * @author Shane Mc Cormack
 */
public class RegexStringList {

	/** Arraylist storing ignore patterns. */
	protected final List<String> ignoreInfo = new ArrayList<String>();

	/**
	 * Creates a new instance of RegexStringList.
	 */
	public RegexStringList() {
    //#RegexStringList.java:42: method: void com.dmdirc.parser.irc.RegexStringList.com.dmdirc.parser.irc.RegexStringList()
    //#input(void com.dmdirc.parser.irc.RegexStringList()): this
    //#output(void com.dmdirc.parser.irc.RegexStringList()): new ArrayList(RegexStringList#1) num objects
    //#output(void com.dmdirc.parser.irc.RegexStringList()): this.ignoreInfo
    //#new obj(void com.dmdirc.parser.irc.RegexStringList()): new ArrayList(RegexStringList#1)
    //#post(void com.dmdirc.parser.irc.RegexStringList()): this.ignoreInfo == &new ArrayList(RegexStringList#1)
    //#post(void com.dmdirc.parser.irc.RegexStringList()): new ArrayList(RegexStringList#1) num objects == 1
		// Do nothing
	}
    //#RegexStringList.java:44: end of method: void com.dmdirc.parser.irc.RegexStringList.com.dmdirc.parser.irc.RegexStringList()

	/**
	 * Creates a new instance of RegexStringList, with the specified items.
	 *
	 * @param items Items to add to this RegexStringList
	 */
	public RegexStringList(final List<String> items) {
    //#RegexStringList.java:51: method: void com.dmdirc.parser.irc.RegexStringList.com.dmdirc.parser.irc.RegexStringList(List)
    //#input(void com.dmdirc.parser.irc.RegexStringList(List)): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList]
    //#input(void com.dmdirc.parser.irc.RegexStringList(List)): __Descendant_Table[others]
    //#input(void com.dmdirc.parser.irc.RegexStringList(List)): __Dispatch_Table.add(Ljava/lang/String;)V
    //#input(void com.dmdirc.parser.irc.RegexStringList(List)): __Dispatch_Table.addAll(Ljava/util/List;)V
    //#input(void com.dmdirc.parser.irc.RegexStringList(List)): items
    //#input(void com.dmdirc.parser.irc.RegexStringList(List)): this
    //#input(void com.dmdirc.parser.irc.RegexStringList(List)): this.__Tag
    //#output(void com.dmdirc.parser.irc.RegexStringList(List)): new ArrayList(RegexStringList#1) num objects
    //#output(void com.dmdirc.parser.irc.RegexStringList(List)): this.ignoreInfo
    //#new obj(void com.dmdirc.parser.irc.RegexStringList(List)): new ArrayList(RegexStringList#1)
    //#pre[1] (void com.dmdirc.parser.irc.RegexStringList(List)): items != null
    //#pre[3] (void com.dmdirc.parser.irc.RegexStringList(List)): (soft) this.__Tag == com/dmdirc/parser/irc/RegexStringList
    //#post(void com.dmdirc.parser.irc.RegexStringList(List)): this.ignoreInfo == &new ArrayList(RegexStringList#1)
    //#post(void com.dmdirc.parser.irc.RegexStringList(List)): new ArrayList(RegexStringList#1) num objects == 1
    //#unanalyzed(void com.dmdirc.parser.irc.RegexStringList(List)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(void com.dmdirc.parser.irc.RegexStringList(List)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void com.dmdirc.parser.irc.RegexStringList(List)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void com.dmdirc.parser.irc.RegexStringList(List)): Effects-of-calling:java.lang.String:equalsIgnoreCase
    //#unanalyzed(void com.dmdirc.parser.irc.RegexStringList(List)): Effects-of-calling:java.util.List:add
		addAll(items);
	}
    //#RegexStringList.java:53: end of method: void com.dmdirc.parser.irc.RegexStringList.com.dmdirc.parser.irc.RegexStringList(List)

	/**
	 * Add a new ignore pattern to the ignore list.
	 *
	 * @param pattern Regex syntax for the ignore (Pattern is matched case-insensitively as ^pattern$)
	 */
	public void add(final String pattern) {
		for (String target : ignoreInfo) {
    //#RegexStringList.java:61: method: void com.dmdirc.parser.irc.RegexStringList.add(String)
    //#input(void add(String)): pattern
    //#input(void add(String)): this
    //#input(void add(String)): this.ignoreInfo
    //#pre[3] (void add(String)): this.ignoreInfo != null
    //#pre[1] (void add(String)): (soft) pattern != null
    //#test_vector(void add(String)): java.lang.String:equalsIgnoreCase(...)@62: {0}, {1}
    //#test_vector(void add(String)): java.util.Iterator:hasNext(...)@61: {0}, {1}
			if (pattern.equalsIgnoreCase(target)) {
				return;
			}
		}

		ignoreInfo.add(pattern);
	}
    //#RegexStringList.java:68: end of method: void com.dmdirc.parser.irc.RegexStringList.add(String)

	/**
	 * Adds a set of patterns to the list.
	 *
	 * @param patterns A list of patterns to be added
	 */
	public void addAll(final List<String> patterns) {
		for (String pattern : patterns) {
    //#RegexStringList.java:76: method: void com.dmdirc.parser.irc.RegexStringList.addAll(List)
    //#input(void addAll(List)): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList]
    //#input(void addAll(List)): __Descendant_Table[others]
    //#input(void addAll(List)): __Dispatch_Table.add(Ljava/lang/String;)V
    //#input(void addAll(List)): patterns
    //#input(void addAll(List)): this
    //#input(void addAll(List)): this.__Tag
    //#input(void addAll(List)): this.ignoreInfo
    //#pre[1] (void addAll(List)): patterns != null
    //#pre[3] (void addAll(List)): (soft) this.__Tag == com/dmdirc/parser/irc/RegexStringList
    //#pre[4] (void addAll(List)): (soft) this.ignoreInfo != null
    //#presumption(void addAll(List)): java.util.Iterator:next(...)@76 != null
    //#unanalyzed(void addAll(List)): Effects-of-calling:java.util.List:iterator
    //#unanalyzed(void addAll(List)): Effects-of-calling:java.util.Iterator:hasNext
    //#unanalyzed(void addAll(List)): Effects-of-calling:java.util.Iterator:next
    //#unanalyzed(void addAll(List)): Effects-of-calling:java.lang.String:equalsIgnoreCase
    //#unanalyzed(void addAll(List)): Effects-of-calling:java.util.List:add
    //#test_vector(void addAll(List)): java.util.Iterator:hasNext(...)@76: {0}, {1}
			add(pattern);
		}
	}
    //#RegexStringList.java:79: end of method: void com.dmdirc.parser.irc.RegexStringList.addAll(List)

	/**
	 * Delete an ignore from the list.
	 *
	 * @param position Position in the list to remove
	 */
	public void remove(final int position) {
		if (position < this.count()) {
    //#RegexStringList.java:87: method: void com.dmdirc.parser.irc.RegexStringList.remove(int)
    //#input(void remove(int)): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList]
    //#input(void remove(int)): __Descendant_Table[others]
    //#input(void remove(int)): __Dispatch_Table.count()I
    //#input(void remove(int)): position
    //#input(void remove(int)): this
    //#input(void remove(int)): this.__Tag
    //#input(void remove(int)): this.ignoreInfo
    //#pre[3] (void remove(int)): this.__Tag == com/dmdirc/parser/irc/RegexStringList
    //#pre[4] (void remove(int)): this.ignoreInfo != null
    //#unanalyzed(void remove(int)): Effects-of-calling:java.util.List:size
			ignoreInfo.remove(position);
		}
	}
    //#RegexStringList.java:90: end of method: void com.dmdirc.parser.irc.RegexStringList.remove(int)

	/**
	 * Clear the ignore list.
	 */
	public void clear() {
		ignoreInfo.clear();
    //#RegexStringList.java:96: method: void com.dmdirc.parser.irc.RegexStringList.clear()
    //#input(void clear()): this
    //#input(void clear()): this.ignoreInfo
    //#pre[2] (void clear()): this.ignoreInfo != null
	}
    //#RegexStringList.java:97: end of method: void com.dmdirc.parser.irc.RegexStringList.clear()

	/**
	 * Check if a string matches any of the ignores in the list.
	 *
	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
	 * @return integer showing the position of the first match in the ignore list (-1 if none)
	 * @throws PatternSyntaxException if one of the items in the list is an invalid regex
	 */
	public int matches(final String check) throws PatternSyntaxException {
		for (int i = 0; i < this.count(); ++i) {
    //#RegexStringList.java:107: method: int com.dmdirc.parser.irc.RegexStringList.matches(String)
    //#input(int matches(String)): ""._tainted
    //#input(int matches(String)): "(?i)"._tainted
    //#input(int matches(String)): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList]
    //#input(int matches(String)): __Descendant_Table[others]
    //#input(int matches(String)): __Dispatch_Table.count()I
    //#input(int matches(String)): __Dispatch_Table.get(I)Ljava/lang/String;
    //#input(int matches(String)): check
    //#input(int matches(String)): this
    //#input(int matches(String)): this.__Tag
    //#input(int matches(String)): this.ignoreInfo
    //#output(int matches(String)): return_value
    //#pre[3] (int matches(String)): this.__Tag == com/dmdirc/parser/irc/RegexStringList
    //#pre[4] (int matches(String)): this.ignoreInfo != null
    //#pre[1] (int matches(String)): (soft) check != null
    //#post(int matches(String)): return_value in {-1..4_294_967_294}
    //#unanalyzed(int matches(String)): Effects-of-calling:java.util.List:size
    //#unanalyzed(int matches(String)): Effects-of-calling:java.util.List:get
    //#test_vector(int matches(String)): java.lang.String:matches(...)@108: {0}, {1}
			if (check.matches("(?i)"+this.get(i))) {
				return i;
			}
		}
		return -1;
    //#RegexStringList.java:112: end of method: int com.dmdirc.parser.irc.RegexStringList.matches(String)
	}

	/**
	 * Check if a string matches a specific ignore in the list.
	 *
	 * @param position Position to check
	 * @param check String to check (Patterns are matched case-insensitively as ^pattern$)
	 * @return boolean true/false
	 * @throws PatternSyntaxException if the item is an invalid regex
	 */
	public boolean matches(final int position, final String check) throws PatternSyntaxException {
		if (position < this.count()) {
    //#RegexStringList.java:124: method: bool com.dmdirc.parser.irc.RegexStringList.matches(int, String)
    //#input(bool matches(int, String)): ""._tainted
    //#input(bool matches(int, String)): "(?i)"._tainted
    //#input(bool matches(int, String)): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList]
    //#input(bool matches(int, String)): __Descendant_Table[others]
    //#input(bool matches(int, String)): __Dispatch_Table.count()I
    //#input(bool matches(int, String)): __Dispatch_Table.get(I)Ljava/lang/String;
    //#input(bool matches(int, String)): check
    //#input(bool matches(int, String)): position
    //#input(bool matches(int, String)): this
    //#input(bool matches(int, String)): this.__Tag
    //#input(bool matches(int, String)): this.ignoreInfo
    //#output(bool matches(int, String)): return_value
    //#pre[4] (bool matches(int, String)): this.__Tag == com/dmdirc/parser/irc/RegexStringList
    //#pre[5] (bool matches(int, String)): this.ignoreInfo != null
    //#pre[1] (bool matches(int, String)): (soft) check != null
    //#post(bool matches(int, String)): init'ed(return_value)
    //#unanalyzed(bool matches(int, String)): Effects-of-calling:java.util.List:size
    //#unanalyzed(bool matches(int, String)): Effects-of-calling:java.util.List:get
			return check.matches("(?i)"+this.get(position));
		} else {
			return false;
    //#RegexStringList.java:127: end of method: bool com.dmdirc.parser.irc.RegexStringList.matches(int, String)
		}
	}

	/**
	 * Get the ignore pattern in a given position in the list.
	 *
	 * @param position Position to check
	 * @return String showing the pattern. ("" if position isn't valid)
	 */
	public String get(final int position) {
		if (position < this.count()) {
    //#RegexStringList.java:138: method: String com.dmdirc.parser.irc.RegexStringList.get(int)
    //#input(String get(int)): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList]
    //#input(String get(int)): __Descendant_Table[others]
    //#input(String get(int)): __Dispatch_Table.count()I
    //#input(String get(int)): position
    //#input(String get(int)): this
    //#input(String get(int)): this.__Tag
    //#input(String get(int)): this.ignoreInfo
    //#output(String get(int)): return_value
    //#pre[3] (String get(int)): this.__Tag == com/dmdirc/parser/irc/RegexStringList
    //#pre[4] (String get(int)): this.ignoreInfo != null
    //#post(String get(int)): init'ed(return_value)
    //#unanalyzed(String get(int)): Effects-of-calling:java.util.List:size
			return ignoreInfo.get(position);
		} else {
			return "";
    //#RegexStringList.java:141: end of method: String com.dmdirc.parser.irc.RegexStringList.get(int)
		}
	}

	/**
	 * Change the ignore pattern in a given position in the list.
	 *
	 * @param position Position to change
	 * @param pattern New pattern
	 */
	public void set(final int position, final String pattern) {
		if (position < this.count()) {
    //#RegexStringList.java:152: method: void com.dmdirc.parser.irc.RegexStringList.set(int, String)
    //#input(void set(int, String)): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList]
    //#input(void set(int, String)): __Descendant_Table[others]
    //#input(void set(int, String)): __Dispatch_Table.count()I
    //#input(void set(int, String)): pattern
    //#input(void set(int, String)): position
    //#input(void set(int, String)): this
    //#input(void set(int, String)): this.__Tag
    //#input(void set(int, String)): this.ignoreInfo
    //#pre[4] (void set(int, String)): this.__Tag == com/dmdirc/parser/irc/RegexStringList
    //#pre[5] (void set(int, String)): this.ignoreInfo != null
    //#unanalyzed(void set(int, String)): Effects-of-calling:java.util.List:size
			ignoreInfo.set(position, pattern);
		}
	}
    //#RegexStringList.java:155: end of method: void com.dmdirc.parser.irc.RegexStringList.set(int, String)

	/**
	 * Get the amount of ignores in the list.
	 *
	 * @return int showing the number of ignores
	 */
	public int count() {
		return ignoreInfo.size();
    //#RegexStringList.java:163: method: int com.dmdirc.parser.irc.RegexStringList.count()
    //#input(int count()): this
    //#input(int count()): this.ignoreInfo
    //#output(int count()): return_value
    //#pre[2] (int count()): this.ignoreInfo != null
    //#post(int count()): init'ed(return_value)
    //#RegexStringList.java:163: end of method: int com.dmdirc.parser.irc.RegexStringList.count()
	}

}
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList]
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.add(Ljava/lang/String;)V
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.addAll(Ljava/util/List;)V
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.clear()V
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.count()I
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.get(I)Ljava/lang/String;
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.matches(ILjava/lang/String;)Z
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.matches(Ljava/lang/String;)I
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.remove(I)V
    //#output(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.set(ILjava/lang/String;)V
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Descendant_Table[com/dmdirc/parser/irc/RegexStringList] == &__Dispatch_Table
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.add(Ljava/lang/String;)V == &add
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.addAll(Ljava/util/List;)V == &addAll
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.clear()V == &clear
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.count()I == &count
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.get(I)Ljava/lang/String; == &get
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.matches(ILjava/lang/String;)Z == &matches
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.matches(Ljava/lang/String;)I == &matches
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.remove(I)V == &remove
    //#post(com.dmdirc.parser.irc.RegexStringList__static_init): __Dispatch_Table.set(ILjava/lang/String;)V == &set
    //#RegexStringList.java:: end of method: com.dmdirc.parser.irc.RegexStringList.com.dmdirc.parser.irc.RegexStringList__static_init
    //#RegexStringList.java:: end of class: com.dmdirc.parser.irc.RegexStringList
