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

com.io7m.zeptoblog.glossary.ZGlossary Maven / Gradle / Ivy

The newest version!
package com.io7m.zeptoblog.glossary;

import io.vavr.Tuple2;
import io.vavr.collection.SortedMap;
import io.vavr.collection.TreeMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.immutables.value.Generated;

/**
 * A glossary.
 */
@Generated(from = "ZGlossaryType", generator = "Immutables")
@SuppressWarnings({"all"})
public final class ZGlossary implements ZGlossaryType {
  private final SortedMap items;

  private ZGlossary(SortedMap items) {
    this.items = items;
    this.initShim = null;
  }

  private ZGlossary(ZGlossary.Builder builder) {
    this.items = builder.items_build();
    this.initShim = null;
  }

  private static final byte STAGE_INITIALIZING = -1;
  private static final byte STAGE_UNINITIALIZED = 0;
  private static final byte STAGE_INITIALIZED = 1;
  private transient volatile InitShim initShim = new InitShim();

  @Generated(from = "ZGlossaryType", generator = "Immutables")
  private final class InitShim {
    private String formatInitCycleMessage() {
      List attributes = new ArrayList<>();
      return "Cannot build ZGlossary, attribute initializers form cycle " + attributes;
    }
  }

  /**
   * @return The glossary items, by name
   */
  @Override
  public SortedMap items() {
    return items;
  }

  /**
   * This instance is equal to all instances of {@code ZGlossary} that have equal attribute values.
   * @return {@code true} if {@code this} is equal to {@code another} instance
   */
  @Override
  public boolean equals(Object another) {
    if (this == another) return true;
    return another instanceof ZGlossary
        && equalTo(0, (ZGlossary) another);
  }

  private boolean equalTo(int synthetic, ZGlossary another) {
    return this.items().equals(another.items());
  }

  /**
   * Computes a hash code from attributes: {@code items}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + (items().hashCode());
    return h;
  }

  /**
   * Prints the immutable value {@code ZGlossary} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "ZGlossary{"
        + "items=" + (items().toString())
        + "}";
  }

  private transient volatile long lazyInitBitmap;

  private static final long ITEMS_BY_LETTER_LAZY_INIT_BIT = 0x1L;

  private transient SortedMap> itemsByLetter;

  /**
   * {@inheritDoc}
   * 

* Returns a lazily initialized value of the {@link ZGlossaryType#itemsByLetter() itemsByLetter} attribute. * Initialized once and only once and stored for subsequent access with proper synchronization. * In case of any exception or error thrown by the lazy value initializer, * the result will not be memoised (i.e. remembered) and on next call computation * will be attempted again. * @return A lazily initialized value of the {@code itemsByLetter} attribute */ @Override public SortedMap> itemsByLetter() { if ((lazyInitBitmap & ITEMS_BY_LETTER_LAZY_INIT_BIT) == 0) { synchronized (this) { if ((lazyInitBitmap & ITEMS_BY_LETTER_LAZY_INIT_BIT) == 0) { this.itemsByLetter = Objects.requireNonNull(ZGlossaryType.super.itemsByLetter(), "itemsByLetter"); lazyInitBitmap |= ITEMS_BY_LETTER_LAZY_INIT_BIT; } } } return itemsByLetter; } /** * Construct a new immutable {@code ZGlossary} instance. * @param items The value for the {@code items} attribute * @return An immutable ZGlossary instance */ public static ZGlossary of(SortedMap items) { return new ZGlossary(items); } /** * Creates a builder for {@link ZGlossary ZGlossary}. *

   * ZGlossary.builder()
   *    .setItems(io.vavr.collection.SortedMap&lt;String, ZGlossaryItem&gt;) // {@link ZGlossaryType#items() items}
   *    .build();
   * 
* @return A new ZGlossary builder */ public static ZGlossary.Builder builder() { return new ZGlossary.Builder(); } /** * Builds instances of type {@link ZGlossary ZGlossary}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "ZGlossaryType", generator = "Immutables") public static final class Builder { private SortedMap items_map = TreeMap.empty(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code ZGlossaryType} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(ZGlossaryType instance) { Objects.requireNonNull(instance, "instance"); setItems(instance.items()); return this; } public Builder putItems(String key, ZGlossaryItem value) { this.items_map = this.items_map.put(key, value); return this; } public Builder putEntryItems(Tuple2 entry) { this.items_map = this.items_map.put(entry); return this; } public Builder setItems(SortedMap elements) { this.items_map = elements; return this; } public Builder setJavaMapItems(Map in_map) { this.items_map = TreeMap.ofAll(in_map); return this; } public Builder setMapItems(io.vavr.collection.Map in_map) { this.items_map = TreeMap.ofEntries(in_map.map(x -> x)); return this; } public Builder setEntriesItems(Iterable> entries) { this.items_map = TreeMap.ofEntries(entries); return this; } /** * Builds a new {@link ZGlossary ZGlossary}. * @return An immutable instance of ZGlossary * @throws java.lang.IllegalStateException if any required attributes are missing */ public ZGlossary build() { return new ZGlossary(this); } private SortedMap items_build() { return this.items_map; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy