com.sigpwned.emoji4j.maven.DataLine Maven / Gradle / Ivy
The newest version!
/*-
* =================================LICENSE_START==================================
* emoji4j-maven-plugin
* ====================================SECTION=====================================
* Copyright (C) 2022 Andy Boothe
* ====================================SECTION=====================================
* 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.
* ==================================LICENSE_END===================================
*/
package com.sigpwned.emoji4j.maven;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.toList;
import java.util.List;
import java.util.regex.Pattern;
/**
* A single line read from a file in the Unicode standard
*/
public class DataLine {
public static final DataLine BLANK = new DataLine(emptyList());
private static final Pattern SEMICOLON = Pattern.compile(";");
public static DataLine fromString(String s) {
s = s.trim();
if (s.isEmpty())
return BLANK;
int index = s.indexOf('#');
if (index == 0)
return BLANK;
if (index != -1)
s = s.substring(0, index).trim();
return new DataLine(SEMICOLON.splitAsStream(s).map(String::trim).collect(toList()));
}
private final List fields;
public DataLine(List fields) {
this.fields = unmodifiableList(fields);
}
public boolean isBlank() {
return getFields().isEmpty();
}
public String getField(int index) {
return getFields().get(index);
}
public int size() {
return getFields().size();
}
/**
* @return the fields
*/
private List getFields() {
return fields;
}
}