com.metreeca.tree.shapes.MaxLength Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metreeca-tree Show documentation
Show all versions of metreeca-tree Show documentation
A shape-based linked data modelling framework.
/*
* Copyright © 2013-2019 Metreeca srl. All rights reserved.
*
* This file is part of Metreeca/Link.
*
* Metreeca/Link is free software: you can redistribute it and/or modify it under the terms
* of the GNU Affero General Public License as published by the Free Software Foundation,
* either version 3 of the License, or(at your option) any later version.
*
* Metreeca/Link is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License along with Metreeca/Link.
* If not, see .
*/
package com.metreeca.tree.shapes;
import com.metreeca.tree.Shape;
/**
* Lexical maximum length constraint.
*
* States that the length of the lexical representation of each term in the focus set is less than or equal to the
* given maximum value.
*/
public final class MaxLength implements Shape {
public static MaxLength maxLength(final int limit) {
return new MaxLength(limit);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
private final int limit;
private MaxLength(final int limit) {
if ( limit < 1 ) {
throw new IllegalArgumentException("illegal limit ["+limit+"]");
}
this.limit=limit;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public int getLimit() {
return limit;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Override public T map(final Probe probe) {
if ( probe == null ) {
throw new NullPointerException("null probe");
}
return probe.probe(this);
}
@Override public boolean equals(final Object object) {
return this == object || object instanceof MaxLength
&& limit == ((MaxLength)object).limit;
}
@Override public int hashCode() {
return Integer.hashCode(limit);
}
@Override public String toString() {
return "maxLength("+limit+")";
}
}