
br.com.objectos.css.io.ClassSelector 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 ClassSelector implements AbstractSelector {
private static final SelectorAction ACTION = SingleSelectorAction.of('.', ClassSelector::parse);
private final String clazz;
public ClassSelector(String clazz) {
this.clazz = clazz;
}
public static SelectorAction action() {
return ACTION;
}
public static Selector parse(CodeReader reader) {
while (reader.hasNext()) {
reader.consume();
if (!CssKeywords.identifierChar().peek(reader)) {
break;
}
}
String clazz = reader.get();
return new ClassSelector(clazz);
}
@Override
public final boolean equals(Object obj) {
if (!(obj instanceof ClassSelector)) {
return false;
}
return ((ClassSelector) obj).clazz.equals(clazz);
}
@Override
public final int hashCode() {
return clazz.hashCode();
}
@Override
public boolean matches(Selectable element) {
String attributeValue = element.attributeValue("class");
return Objects.equals(attributeValue, clazz);
}
@Override
public final String toString() {
return "." + clazz;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy