AbstractHead.java

  1. /*
  2.  * Copyright (C) 2008, Florian Köberle <florianskarten@web.de> and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.fnmatch;

  11. import java.util.List;

  12. import org.eclipse.jgit.internal.JGitText;

  13. abstract class AbstractHead implements Head {
  14.     private List<Head> newHeads = null;

  15.     private final boolean star;

  16.     /**
  17.      * Whether the char matches
  18.      *
  19.      * @param c
  20.      *            a char.
  21.      * @return whether the char matches
  22.      */
  23.     protected abstract boolean matches(char c);

  24.     AbstractHead(boolean star) {
  25.         this.star = star;
  26.     }

  27.     /**
  28.      * Set {@link org.eclipse.jgit.fnmatch.Head}s which will not be modified.
  29.      *
  30.      * @param newHeads
  31.      *            a list of {@link org.eclipse.jgit.fnmatch.Head}s which will
  32.      *            not be modified.
  33.      */
  34.     public final void setNewHeads(List<Head> newHeads) {
  35.         if (this.newHeads != null)
  36.             throw new IllegalStateException(JGitText.get().propertyIsAlreadyNonNull);
  37.         this.newHeads = newHeads;
  38.     }

  39.     /** {@inheritDoc} */
  40.     @Override
  41.     public List<Head> getNextHeads(char c) {
  42.         if (matches(c)) {
  43.             return newHeads;
  44.         }
  45.         return FileNameMatcher.EMPTY_HEAD_LIST;
  46.     }

  47.     boolean isStar() {
  48.         return star;
  49.     }
  50. }