All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.openlca.io.oneclick.PackagingMatcher Maven / Gradle / Ivy

There is a newer version: 2.2.1
Show newest version
package org.openlca.io.oneclick;

import org.openlca.core.model.descriptors.Descriptor;
import org.openlca.util.Strings;

import java.util.Locale;
import java.util.regex.Pattern;

public class PackagingMatcher {

	private final Pattern pattern;

	private PackagingMatcher(String p) {
		pattern = Pattern.compile(p);
	}

	public static PackagingMatcher createDefault() {
		var pattern = ".*\\b(" +
			"packaging" +
			"|packing" +
			"|core board production" +
			"|kraft paper production" +
			"|wood wool production" +
			")\\b.*";
		return new PackagingMatcher(pattern);
	}

	public static PackagingMatcher create(String pattern) {
		return new PackagingMatcher(pattern);
	}

	public String pattern() {
		return pattern.pattern();
	}

	public boolean matches(String label) {
		if (Strings.nullOrEmpty(label))
			return false;
		var s = label.strip().toLowerCase(Locale.US);
		return pattern.matcher(s).matches();
	}

	public boolean matches(Descriptor d) {
		return d != null && matches(d.name);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy