<commit_before>/*
 * Copyright (C) 2016 <NAME>
 *
 * 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.
 */

package com.github.sormuras.listing;

import static java.util.Objects.requireNonNull;

import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;
import javax.lang.model.element.Modifier;

/** Default {@link Modifier} support. */
public interface Modifiable {

  default void addModifier(Modifier modifier) {
    validateModifiers(modifier);
    getModifiers().add(modifier);
  }

  default void addModifiers(Collection<Modifier> modifiers) {
    validateModifiers(modifiers.toArray(new Modifier[modifiers.size()]));
    getModifiers().addAll(modifiers);
  }

  default void addModifiers(int mod) {
    addModifiers(Tool.modifiers(mod));
  }

  default void addModifiers(Modifier... modifiers) {
    validateModifiers(modifiers);
    getModifiers().addAll(Arrays.asList(modifiers));
  }

  Set<Modifier> getModifiers(boolean readonly);

  /**
   * Returns all applied modifiers.
   *
   * @return Applied modifiers.
   */
  default Set<Modifier> getModifiers() {
    return getModifiers(false);
  }

  /**
   * Returns all modifiers that are applicable to this element kind.
   *
   * @return All modifiers defined in {@link Modifier}.
   */
  default Set<Modifier> getModifierValidationSet() {
    return EnumSet.allOf(Modifier.class);
  }

  default boolean isModified() {
    return !getModifiers(true).isEmpty();
  }

  default boolean isPublic() {
    return getModifiers().contains(Modifier.PUBLIC);
  }

  default boolean isStatic() {
    return getModifiers(true).contains(Modifier.STATIC);
  }

  default void setModifiers(int mod) {
    getModifiers().clear();
    addModifiers(mod);
  }

  default void setModifiers(Modifier... modifiers) {
    getModifiers().clear();
    addModifiers(modifiers);
  }

  default Listable toModifiersListable() {<commit_msg>Javadoc and read-only accessor used.<commit_after>/*
 * Copyright (C) 2016 <NAME>
 *
 * 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.
 */

package com.github.sormuras.listing;

import static java.util.Objects.requireNonNull;

import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;
import javax.lang.model.element.Modifier;

/** Default {@link Modifier} set support. */
public interface Modifiable {

  /** Add modifier to the set. */
  default void addModifier(Modifier modifier) {
    validateModifiers(modifier);
    getModifiers().add(modifier);
  }

  /** Add collection of modifiers to the set. */
  default void addModifiers(Collection<Modifier> modifiers) {
    validateModifiers(modifiers.toArray(new Modifier[modifiers.size()]));
    getModifiers().addAll(modifiers);
  }

  /** Add collection of modifiers to the set. */
  default void addModifiers(int mod) {
    addModifiers(Tool.modifiers(mod));
  }

  /** Add variable array of modifiers to the set. */
  default void addModifiers(Modifier... modifiers) {
    validateModifiers(modifiers);
    getModifiers().addAll(Arrays.asList(modifiers));
  }

  /** Return set of modifiers indicating if the caller will mutate the set. */
  Set<Modifier> getModifiers(boolean readonly);

  /**
   * Returns all applied modifiers.
   *
   * @return Applied modifiers.
   */
  default Set<Modifier> getModifiers() {
    return getModifiers(false);
  }

  /**
   * Returns all modifiers that are applicable to this element kind.
   *
   * @return All modifiers defined in {@link Modifier}.
   */
  default Set<Modifier> getModifierValidationSet() {
    return EnumSet.allOf(Modifier.class);
  }

  /** Return {@code true} if modifier set is not empty, else {@code false}. */
  default boolean isModified() {
    return !getModifiers(true).isEmpty();
  }

  /** Return {@code true} if {@link Modifier#PUBLIC} is part of modifier set, else {@code false}. */
  default boolean isPublic() {
    return getModifiers(true).contains(Modifier.PUBLIC);
  }

  /** Return {@code true} if {@link Modifier#STATIC} is part of modifier set, else {@code false}. */
  default boolean isStatic() {
    return getModifiers(true).contains(Modifier.STATIC);
  }

  /** Replace current modifiers by with new ones. */
  default void setModifiers(int mod) {
    getModifiers().clear();
    addModifiers(mod);
  }

  /** Replace current modifiers by with new ones. */
  default void setModifiers(Modifier... modifiers) {
    getModifiers().clear();
    addModifiers(modifiers);
  }

  /** Return modifiers as an inline listable. */
  default Listable toModifiersListable() {
{'fraction_non_alphanumeric': 0.11147127678732217, 'fraction_numerical': 0.002881325409688457, 'mean_word_length': 3.8804920913884007, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623743', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1586, 'n_words': 496}