<commit_before>package ca.concordia.cssanalyser.cssmodel.selectors;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import ca.concordia.cssanalyser.cssmodel.CSSModelObject;
import ca.concordia.cssanalyser.cssmodel.CSSOrigin;
import ca.concordia.cssanalyser.cssmodel.CSSSource;
import ca.concordia.cssanalyser.cssmodel.LocationInfo;
import ca.concordia.cssanalyser.cssmodel.StyleSheet;
import ca.concordia.cssanalyser.cssmodel.declaration.Declaration;
import ca.concordia.cssanalyser.cssmodel.declaration.ShorthandDeclaration;
import ca.concordia.cssanalyser.cssmodel.declaration.value.DeclarationValue;
import ca.concordia.cssanalyser.cssmodel.media.MediaQueryList;


public abstract class Selector extends CSSModelObject  {

	private LocationInfo selectorNameLocationInfo;
	protected StyleSheet parentStyleSheet;
	protected Set<MediaQueryList> mediaQueryLists;
	protected Map<Declaration, Integer> declarations;
	protected CSSSource source = CSSSource.EXTERNAL;
	protected CSSOrigin origin = CSSOrigin.AUTHOR;
	
	public Selector() {
		this(new LocationInfo());
	}
	
	public Selector(LocationInfo locationInfo) {
		this.locationInfo = locationInfo;
		declarations = new LinkedHashMap<>();
		mediaQueryLists = new LinkedHashSet<>();
		
	}
	
	/**
	 * Gets the parent style sheet of this Selector 
	 * @return the parentStyleSheet
	 */
	public StyleSheet getParentStyleSheet() {
		return parentStyleSheet;
	}

	/** 
	 * Sets the parent style sheet of this Selector.
	 * If the selector is not currently in the StyleSheet,
	 * it will add it to the StyleSheet.
	 * @param parentStyleSheet the parentStyleSheet to set
	 */
	public void setParentStyleSheet(StyleSheet parentStyleSheet) {
		this.parentStyleSheet = parentStyleSheet;
		if (!parentStyleSheet.containsSelector(this))
			parentStyleSheet.addSelector(this);
	}
		
	public LocationInfo getSelectorNameLocationInfo() {
		return this.selectorNameLocationInfo;
	}
	
	public void setSelectorNameLocationInfo(LocationInfo locationInfo) {
		this.selectorNameLocationInfo = locationInfo;
	}
	
	public void addDeclaration(Declaration declaration) {
		if (!declarations.containsKey(declaration))
			declarations.put(declaration, declarations.size() + 1);
		declaration.setSelector(this);
	}
	
	public int getNumberOfDeclarations() {
		return declarations.size();
	}
		
	public Iterable<Declaration> getDeclarations() {
		return declarations.keySet();
	}
	
	public boolean containsDeclaration(Declaration declaration) {
		return this.declarations.containsKey(declaration);
	}	
	
	public int getDeclarationNumber(Declaration declaration) {<commit_msg>If a declaration does not exist, getDeclarationNumber now returns -1<commit_after>package ca.concordia.cssanalyser.cssmodel.selectors;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import ca.concordia.cssanalyser.cssmodel.CSSModelObject;
import ca.concordia.cssanalyser.cssmodel.CSSOrigin;
import ca.concordia.cssanalyser.cssmodel.CSSSource;
import ca.concordia.cssanalyser.cssmodel.LocationInfo;
import ca.concordia.cssanalyser.cssmodel.StyleSheet;
import ca.concordia.cssanalyser.cssmodel.declaration.Declaration;
import ca.concordia.cssanalyser.cssmodel.declaration.ShorthandDeclaration;
import ca.concordia.cssanalyser.cssmodel.declaration.value.DeclarationValue;
import ca.concordia.cssanalyser.cssmodel.media.MediaQueryList;


public abstract class Selector extends CSSModelObject  {

	private LocationInfo selectorNameLocationInfo;
	protected StyleSheet parentStyleSheet;
	protected Set<MediaQueryList> mediaQueryLists;
	protected Map<Declaration, Integer> declarations;
	protected CSSSource source = CSSSource.EXTERNAL;
	protected CSSOrigin origin = CSSOrigin.AUTHOR;
	
	public Selector() {
		this(new LocationInfo());
	}
	
	public Selector(LocationInfo locationInfo) {
		this.locationInfo = locationInfo;
		declarations = new LinkedHashMap<>();
		mediaQueryLists = new LinkedHashSet<>();
		
	}
	
	/**
	 * Gets the parent style sheet of this Selector 
	 * @return the parentStyleSheet
	 */
	public StyleSheet getParentStyleSheet() {
		return parentStyleSheet;
	}

	/** 
	 * Sets the parent style sheet of this Selector.
	 * If the selector is not currently in the StyleSheet,
	 * it will add it to the StyleSheet.
	 * @param parentStyleSheet the parentStyleSheet to set
	 */
	public void setParentStyleSheet(StyleSheet parentStyleSheet) {
		this.parentStyleSheet = parentStyleSheet;
		if (!parentStyleSheet.containsSelector(this))
			parentStyleSheet.addSelector(this);
	}
		
	public LocationInfo getSelectorNameLocationInfo() {
		return this.selectorNameLocationInfo;
	}
	
	public void setSelectorNameLocationInfo(LocationInfo locationInfo) {
		this.selectorNameLocationInfo = locationInfo;
	}
	
	public void addDeclaration(Declaration declaration) {
		if (!declarations.containsKey(declaration))
			declarations.put(declaration, declarations.size() + 1);
		declaration.setSelector(this);
	}
	
	public int getNumberOfDeclarations() {
		return declarations.size();
	}
		
	public Iterable<Declaration> getDeclarations() {
		return declarations.keySet();
	}
	
	public boolean containsDeclaration(Declaration declaration) {
		return this.declarations.containsKey(declaration);
	}	
	
	public int getDeclarationNumber(Declaration declaration) {
		if (!containsDeclaration(declaration))
			return -1;
{'fraction_non_alphanumeric': 0.08567909922589725, 'fraction_numerical': 0.0007037297677691766, 'mean_word_length': 5.680376028202115, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3833416', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1633, 'n_words': 365}