
br.com.objectos.css.io.AttributeSelector Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2016 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.css.io;
import java.util.Objects;
import br.com.objectos.codereader.CodeReader;
import br.com.objectos.css.Selectable;
import br.com.objectos.css.Selector;
/**
* @author [email protected] (Marcio Endo)
*/
class AttributeSelector implements AbstractSelector {
private static final SelectorAction ACTION = SingleSelectorAction.of('[', AttributeSelector::parse);
private final String attribute;
private final String value;
private final AttributeOperator operator;
public AttributeSelector(String attribute, String value, AttributeOperator operator) {
this.attribute = attribute;
this.value = value;
this.operator = operator;
}
public static SelectorAction action() {
return ACTION;
}
public static Selector parse(CodeReader reader) {
return new AttributeSelectorParser(reader).parse();
}
@Override
public final boolean equals(Object obj) {
if (!(obj instanceof AttributeSelector)) {
return false;
}
AttributeSelector that = (AttributeSelector) obj;
return attribute.equals(that.attribute)
&& value.equals(that.value)
&& operator.equals(that.operator);
}
@Override
public final int hashCode() {
return Objects.hash(attribute, value, operator);
}
@Override
public boolean matches(Selectable element) {
String actualValue = element.attributeValue(attribute);
return operator.matches(value, actualValue);
}
@Override
public final String toString() {
return "[" + attribute + operator + value + "]";
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy