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

org.carrot2.attrs.Attr Maven / Gradle / Ivy

There is a newer version: 4.6.0
Show newest version
/*
 * Carrot2 project.
 *
 * Copyright (C) 2002-2021, Dawid Weiss, Stanisław Osiński.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the repository checkout or at:
 * https://www.carrot2.org/carrot2.LICENSE
 */
package org.carrot2.attrs;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public abstract class Attr implements AttrMetadata {
  private final String label;
  private final List> constraints;

  T value;

  public Attr(T defaultValue, String label, List> constraints) {
    this.label = label;
    this.constraints = constraints;
    this.value = defaultValue;
  }

  public final String getDescription() {
    return label;
  }

  public T get() {
    return value;
  }

  public void set(T value) {
    constraints.forEach(c -> c.accept(value));
    this.value = value;
  }

  public List> getConstraints() {
    return Collections.unmodifiableList(constraints);
  }

  protected static class BuilderScaffold {
    protected List> constraints = new ArrayList<>();
    protected String label;

    protected void addConstraint(Constraint c) {
      constraints.add(c);
    }

    protected List> getConstraint() {
      return constraints;
    }

    public BuilderScaffold label(String label) {
      this.label = label;
      return this;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy