Advertisement
NLinker

Immutable class with Builder generated by immutables fw

Nov 29th, 2016
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 39.91 KB | None | 0 0
  1. package com.vertigo.resolver.apple.entity;
  2.  
  3. import java.time.LocalDate;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Objects;
  7. import java.util.Optional;
  8. import javax.annotation.Generated;
  9.  
  10. /**
  11.  * Corresponds to {@code vertigo_apple_epf_db.public.song}
  12.  */
  13. @SuppressWarnings({"all"})
  14. @Generated({"Immutables.generator", "AbstractSong"})
  15. public final class Song implements AbstractSong {
  16.   private final SongId songId;
  17.   private final String name;
  18.   private final String titleVersion;
  19.   private final String searchTerms;
  20.   private final Integer parentalAdvisoryId;
  21.   private final String artistDisplayName;
  22.   private final String collectionDisplayName;
  23.   private final String viewUrl;
  24.   private final LocalDate originalReleaseDate;
  25.   private final LocalDate itunesReleaseDate;
  26.   private final String trackLength;
  27.   private final String copyright;
  28.   private final String pLine;
  29.   private final String previewUrl;
  30.   private final String previewLength;
  31.   private final Long exportDate;
  32.  
  33.   private Song(
  34.       SongId songId,
  35.       String name,
  36.       String titleVersion,
  37.       String searchTerms,
  38.       Integer parentalAdvisoryId,
  39.       String artistDisplayName,
  40.       String collectionDisplayName,
  41.       String viewUrl,
  42.       LocalDate originalReleaseDate,
  43.       LocalDate itunesReleaseDate,
  44.       String trackLength,
  45.       String copyright,
  46.       String pLine,
  47.       String previewUrl,
  48.       String previewLength,
  49.       Long exportDate) {
  50.     this.songId = songId;
  51.     this.name = name;
  52.     this.titleVersion = titleVersion;
  53.     this.searchTerms = searchTerms;
  54.     this.parentalAdvisoryId = parentalAdvisoryId;
  55.     this.artistDisplayName = artistDisplayName;
  56.     this.collectionDisplayName = collectionDisplayName;
  57.     this.viewUrl = viewUrl;
  58.     this.originalReleaseDate = originalReleaseDate;
  59.     this.itunesReleaseDate = itunesReleaseDate;
  60.     this.trackLength = trackLength;
  61.     this.copyright = copyright;
  62.     this.pLine = pLine;
  63.     this.previewUrl = previewUrl;
  64.     this.previewLength = previewLength;
  65.     this.exportDate = exportDate;
  66.   }
  67.  
  68.   /**
  69.    * @return The value of the {@code songId} attribute
  70.    */
  71.   @Override
  72.   public SongId songId() {
  73.     return songId;
  74.   }
  75.  
  76.   /**
  77.    * @return The value of the {@code name} attribute
  78.    */
  79.   @Override
  80.   public String name() {
  81.     return name;
  82.   }
  83.  
  84.   /**
  85.    * @return The value of the {@code titleVersion} attribute
  86.    */
  87.   @Override
  88.   public Optional<String> titleVersion() {
  89.     return Optional.ofNullable(titleVersion);
  90.   }
  91.  
  92.   /**
  93.    * @return The value of the {@code searchTerms} attribute
  94.    */
  95.   @Override
  96.   public Optional<String> searchTerms() {
  97.     return Optional.ofNullable(searchTerms);
  98.   }
  99.  
  100.   /**
  101.    * @return The value of the {@code parentalAdvisoryId} attribute
  102.    */
  103.   @Override
  104.   public Integer parentalAdvisoryId() {
  105.     return parentalAdvisoryId;
  106.   }
  107.  
  108.   /**
  109.    * @return The value of the {@code artistDisplayName} attribute
  110.    */
  111.   @Override
  112.   public String artistDisplayName() {
  113.     return artistDisplayName;
  114.   }
  115.  
  116.   /**
  117.    * @return The value of the {@code collectionDisplayName} attribute
  118.    */
  119.   @Override
  120.   public String collectionDisplayName() {
  121.     return collectionDisplayName;
  122.   }
  123.  
  124.   /**
  125.    * @return The value of the {@code viewUrl} attribute
  126.    */
  127.   @Override
  128.   public String viewUrl() {
  129.     return viewUrl;
  130.   }
  131.  
  132.   /**
  133.    * @return The value of the {@code originalReleaseDate} attribute
  134.    */
  135.   @Override
  136.   public LocalDate originalReleaseDate() {
  137.     return originalReleaseDate;
  138.   }
  139.  
  140.   /**
  141.    * @return The value of the {@code itunesReleaseDate} attribute
  142.    */
  143.   @Override
  144.   public LocalDate itunesReleaseDate() {
  145.     return itunesReleaseDate;
  146.   }
  147.  
  148.   /**
  149.    * @return The value of the {@code trackLength} attribute
  150.    */
  151.   @Override
  152.   public String trackLength() {
  153.     return trackLength;
  154.   }
  155.  
  156.   /**
  157.    * @return The value of the {@code copyright} attribute
  158.    */
  159.   @Override
  160.   public String copyright() {
  161.     return copyright;
  162.   }
  163.  
  164.   /**
  165.    * @return The value of the {@code pLine} attribute
  166.    */
  167.   @Override
  168.   public String pLine() {
  169.     return pLine;
  170.   }
  171.  
  172.   /**
  173.    * @return The value of the {@code previewUrl} attribute
  174.    */
  175.   @Override
  176.   public String previewUrl() {
  177.     return previewUrl;
  178.   }
  179.  
  180.   /**
  181.    * @return The value of the {@code previewLength} attribute
  182.    */
  183.   @Override
  184.   public String previewLength() {
  185.     return previewLength;
  186.   }
  187.  
  188.   /**
  189.    * @return The value of the {@code exportDate} attribute
  190.    */
  191.   @Override
  192.   public Long exportDate() {
  193.     return exportDate;
  194.   }
  195.  
  196.   /**
  197.    * Copy the current immutable object by setting a value for the {@link AbstractSong#songId() songId} attribute.
  198.    * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
  199.    * @param value A new value for songId
  200.    * @return A modified copy of the {@code this} object
  201.    */
  202.   public final Song withSongId(SongId value) {
  203.     if (this.songId == value) return this;
  204.     SongId newValue = Objects.requireNonNull(value, "songId");
  205.     return new Song(
  206.         newValue,
  207.         this.name,
  208.         this.titleVersion,
  209.         this.searchTerms,
  210.         this.parentalAdvisoryId,
  211.         this.artistDisplayName,
  212.         this.collectionDisplayName,
  213.         this.viewUrl,
  214.         this.originalReleaseDate,
  215.         this.itunesReleaseDate,
  216.         this.trackLength,
  217.         this.copyright,
  218.         this.pLine,
  219.         this.previewUrl,
  220.         this.previewLength,
  221.         this.exportDate);
  222.   }
  223.  
  224.   /**
  225.    * Copy the current immutable object by setting a value for the {@link AbstractSong#name() name} attribute.
  226.    * An equals check used to prevent copying of the same value by returning {@code this}.
  227.    * @param value A new value for name
  228.    * @return A modified copy of the {@code this} object
  229.    */
  230.   public final Song withName(String value) {
  231.     if (this.name.equals(value)) return this;
  232.     String newValue = Objects.requireNonNull(value, "name");
  233.     return new Song(
  234.         this.songId,
  235.         newValue,
  236.         this.titleVersion,
  237.         this.searchTerms,
  238.         this.parentalAdvisoryId,
  239.         this.artistDisplayName,
  240.         this.collectionDisplayName,
  241.         this.viewUrl,
  242.         this.originalReleaseDate,
  243.         this.itunesReleaseDate,
  244.         this.trackLength,
  245.         this.copyright,
  246.         this.pLine,
  247.         this.previewUrl,
  248.         this.previewLength,
  249.         this.exportDate);
  250.   }
  251.  
  252.   /**
  253.    * Copy the current immutable object by setting a <i>present</i> value for the optional {@link AbstractSong#titleVersion() titleVersion} attribute.
  254.    * @param value The value for titleVersion
  255.    * @return A modified copy of {@code this} object
  256.    */
  257.   public final Song withTitleVersion(String value) {
  258.     String newValue = Objects.requireNonNull(value, "titleVersion");
  259.     if (Objects.equals(this.titleVersion, newValue)) return this;
  260.     return new Song(
  261.         this.songId,
  262.         this.name,
  263.         newValue,
  264.         this.searchTerms,
  265.         this.parentalAdvisoryId,
  266.         this.artistDisplayName,
  267.         this.collectionDisplayName,
  268.         this.viewUrl,
  269.         this.originalReleaseDate,
  270.         this.itunesReleaseDate,
  271.         this.trackLength,
  272.         this.copyright,
  273.         this.pLine,
  274.         this.previewUrl,
  275.         this.previewLength,
  276.         this.exportDate);
  277.   }
  278.  
  279.   /**
  280.    * Copy the current immutable object by setting an optional value for the {@link AbstractSong#titleVersion() titleVersion} attribute.
  281.    * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
  282.    * @param optional A value for titleVersion
  283.    * @return A modified copy of {@code this} object
  284.    */
  285.   public final Song withTitleVersion(Optional<String> optional) {
  286.     String value = optional.orElse(null);
  287.     if (Objects.equals(this.titleVersion, value)) return this;
  288.     return new Song(
  289.         this.songId,
  290.         this.name,
  291.         value,
  292.         this.searchTerms,
  293.         this.parentalAdvisoryId,
  294.         this.artistDisplayName,
  295.         this.collectionDisplayName,
  296.         this.viewUrl,
  297.         this.originalReleaseDate,
  298.         this.itunesReleaseDate,
  299.         this.trackLength,
  300.         this.copyright,
  301.         this.pLine,
  302.         this.previewUrl,
  303.         this.previewLength,
  304.         this.exportDate);
  305.   }
  306.  
  307.   /**
  308.    * Copy the current immutable object by setting a <i>present</i> value for the optional {@link AbstractSong#searchTerms() searchTerms} attribute.
  309.    * @param value The value for searchTerms
  310.    * @return A modified copy of {@code this} object
  311.    */
  312.   public final Song withSearchTerms(String value) {
  313.     String newValue = Objects.requireNonNull(value, "searchTerms");
  314.     if (Objects.equals(this.searchTerms, newValue)) return this;
  315.     return new Song(
  316.         this.songId,
  317.         this.name,
  318.         this.titleVersion,
  319.         newValue,
  320.         this.parentalAdvisoryId,
  321.         this.artistDisplayName,
  322.         this.collectionDisplayName,
  323.         this.viewUrl,
  324.         this.originalReleaseDate,
  325.         this.itunesReleaseDate,
  326.         this.trackLength,
  327.         this.copyright,
  328.         this.pLine,
  329.         this.previewUrl,
  330.         this.previewLength,
  331.         this.exportDate);
  332.   }
  333.  
  334.   /**
  335.    * Copy the current immutable object by setting an optional value for the {@link AbstractSong#searchTerms() searchTerms} attribute.
  336.    * An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
  337.    * @param optional A value for searchTerms
  338.    * @return A modified copy of {@code this} object
  339.    */
  340.   public final Song withSearchTerms(Optional<String> optional) {
  341.     String value = optional.orElse(null);
  342.     if (Objects.equals(this.searchTerms, value)) return this;
  343.     return new Song(
  344.         this.songId,
  345.         this.name,
  346.         this.titleVersion,
  347.         value,
  348.         this.parentalAdvisoryId,
  349.         this.artistDisplayName,
  350.         this.collectionDisplayName,
  351.         this.viewUrl,
  352.         this.originalReleaseDate,
  353.         this.itunesReleaseDate,
  354.         this.trackLength,
  355.         this.copyright,
  356.         this.pLine,
  357.         this.previewUrl,
  358.         this.previewLength,
  359.         this.exportDate);
  360.   }
  361.  
  362.   /**
  363.    * Copy the current immutable object by setting a value for the {@link AbstractSong#parentalAdvisoryId() parentalAdvisoryId} attribute.
  364.    * An equals check used to prevent copying of the same value by returning {@code this}.
  365.    * @param value A new value for parentalAdvisoryId
  366.    * @return A modified copy of the {@code this} object
  367.    */
  368.   public final Song withParentalAdvisoryId(Integer value) {
  369.     if (this.parentalAdvisoryId.equals(value)) return this;
  370.     Integer newValue = Objects.requireNonNull(value, "parentalAdvisoryId");
  371.     return new Song(
  372.         this.songId,
  373.         this.name,
  374.         this.titleVersion,
  375.         this.searchTerms,
  376.         newValue,
  377.         this.artistDisplayName,
  378.         this.collectionDisplayName,
  379.         this.viewUrl,
  380.         this.originalReleaseDate,
  381.         this.itunesReleaseDate,
  382.         this.trackLength,
  383.         this.copyright,
  384.         this.pLine,
  385.         this.previewUrl,
  386.         this.previewLength,
  387.         this.exportDate);
  388.   }
  389.  
  390.   /**
  391.    * Copy the current immutable object by setting a value for the {@link AbstractSong#artistDisplayName() artistDisplayName} attribute.
  392.    * An equals check used to prevent copying of the same value by returning {@code this}.
  393.    * @param value A new value for artistDisplayName
  394.    * @return A modified copy of the {@code this} object
  395.    */
  396.   public final Song withArtistDisplayName(String value) {
  397.     if (this.artistDisplayName.equals(value)) return this;
  398.     String newValue = Objects.requireNonNull(value, "artistDisplayName");
  399.     return new Song(
  400.         this.songId,
  401.         this.name,
  402.         this.titleVersion,
  403.         this.searchTerms,
  404.         this.parentalAdvisoryId,
  405.         newValue,
  406.         this.collectionDisplayName,
  407.         this.viewUrl,
  408.         this.originalReleaseDate,
  409.         this.itunesReleaseDate,
  410.         this.trackLength,
  411.         this.copyright,
  412.         this.pLine,
  413.         this.previewUrl,
  414.         this.previewLength,
  415.         this.exportDate);
  416.   }
  417.  
  418.   /**
  419.    * Copy the current immutable object by setting a value for the {@link AbstractSong#collectionDisplayName() collectionDisplayName} attribute.
  420.    * An equals check used to prevent copying of the same value by returning {@code this}.
  421.    * @param value A new value for collectionDisplayName
  422.    * @return A modified copy of the {@code this} object
  423.    */
  424.   public final Song withCollectionDisplayName(String value) {
  425.     if (this.collectionDisplayName.equals(value)) return this;
  426.     String newValue = Objects.requireNonNull(value, "collectionDisplayName");
  427.     return new Song(
  428.         this.songId,
  429.         this.name,
  430.         this.titleVersion,
  431.         this.searchTerms,
  432.         this.parentalAdvisoryId,
  433.         this.artistDisplayName,
  434.         newValue,
  435.         this.viewUrl,
  436.         this.originalReleaseDate,
  437.         this.itunesReleaseDate,
  438.         this.trackLength,
  439.         this.copyright,
  440.         this.pLine,
  441.         this.previewUrl,
  442.         this.previewLength,
  443.         this.exportDate);
  444.   }
  445.  
  446.   /**
  447.    * Copy the current immutable object by setting a value for the {@link AbstractSong#viewUrl() viewUrl} attribute.
  448.    * An equals check used to prevent copying of the same value by returning {@code this}.
  449.    * @param value A new value for viewUrl
  450.    * @return A modified copy of the {@code this} object
  451.    */
  452.   public final Song withViewUrl(String value) {
  453.     if (this.viewUrl.equals(value)) return this;
  454.     String newValue = Objects.requireNonNull(value, "viewUrl");
  455.     return new Song(
  456.         this.songId,
  457.         this.name,
  458.         this.titleVersion,
  459.         this.searchTerms,
  460.         this.parentalAdvisoryId,
  461.         this.artistDisplayName,
  462.         this.collectionDisplayName,
  463.         newValue,
  464.         this.originalReleaseDate,
  465.         this.itunesReleaseDate,
  466.         this.trackLength,
  467.         this.copyright,
  468.         this.pLine,
  469.         this.previewUrl,
  470.         this.previewLength,
  471.         this.exportDate);
  472.   }
  473.  
  474.   /**
  475.    * Copy the current immutable object by setting a value for the {@link AbstractSong#originalReleaseDate() originalReleaseDate} attribute.
  476.    * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
  477.    * @param value A new value for originalReleaseDate
  478.    * @return A modified copy of the {@code this} object
  479.    */
  480.   public final Song withOriginalReleaseDate(LocalDate value) {
  481.     if (this.originalReleaseDate == value) return this;
  482.     LocalDate newValue = Objects.requireNonNull(value, "originalReleaseDate");
  483.     return new Song(
  484.         this.songId,
  485.         this.name,
  486.         this.titleVersion,
  487.         this.searchTerms,
  488.         this.parentalAdvisoryId,
  489.         this.artistDisplayName,
  490.         this.collectionDisplayName,
  491.         this.viewUrl,
  492.         newValue,
  493.         this.itunesReleaseDate,
  494.         this.trackLength,
  495.         this.copyright,
  496.         this.pLine,
  497.         this.previewUrl,
  498.         this.previewLength,
  499.         this.exportDate);
  500.   }
  501.  
  502.   /**
  503.    * Copy the current immutable object by setting a value for the {@link AbstractSong#itunesReleaseDate() itunesReleaseDate} attribute.
  504.    * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
  505.    * @param value A new value for itunesReleaseDate
  506.    * @return A modified copy of the {@code this} object
  507.    */
  508.   public final Song withItunesReleaseDate(LocalDate value) {
  509.     if (this.itunesReleaseDate == value) return this;
  510.     LocalDate newValue = Objects.requireNonNull(value, "itunesReleaseDate");
  511.     return new Song(
  512.         this.songId,
  513.         this.name,
  514.         this.titleVersion,
  515.         this.searchTerms,
  516.         this.parentalAdvisoryId,
  517.         this.artistDisplayName,
  518.         this.collectionDisplayName,
  519.         this.viewUrl,
  520.         this.originalReleaseDate,
  521.         newValue,
  522.         this.trackLength,
  523.         this.copyright,
  524.         this.pLine,
  525.         this.previewUrl,
  526.         this.previewLength,
  527.         this.exportDate);
  528.   }
  529.  
  530.   /**
  531.    * Copy the current immutable object by setting a value for the {@link AbstractSong#trackLength() trackLength} attribute.
  532.    * An equals check used to prevent copying of the same value by returning {@code this}.
  533.    * @param value A new value for trackLength
  534.    * @return A modified copy of the {@code this} object
  535.    */
  536.   public final Song withTrackLength(String value) {
  537.     if (this.trackLength.equals(value)) return this;
  538.     String newValue = Objects.requireNonNull(value, "trackLength");
  539.     return new Song(
  540.         this.songId,
  541.         this.name,
  542.         this.titleVersion,
  543.         this.searchTerms,
  544.         this.parentalAdvisoryId,
  545.         this.artistDisplayName,
  546.         this.collectionDisplayName,
  547.         this.viewUrl,
  548.         this.originalReleaseDate,
  549.         this.itunesReleaseDate,
  550.         newValue,
  551.         this.copyright,
  552.         this.pLine,
  553.         this.previewUrl,
  554.         this.previewLength,
  555.         this.exportDate);
  556.   }
  557.  
  558.   /**
  559.    * Copy the current immutable object by setting a value for the {@link AbstractSong#copyright() copyright} attribute.
  560.    * An equals check used to prevent copying of the same value by returning {@code this}.
  561.    * @param value A new value for copyright
  562.    * @return A modified copy of the {@code this} object
  563.    */
  564.   public final Song withCopyright(String value) {
  565.     if (this.copyright.equals(value)) return this;
  566.     String newValue = Objects.requireNonNull(value, "copyright");
  567.     return new Song(
  568.         this.songId,
  569.         this.name,
  570.         this.titleVersion,
  571.         this.searchTerms,
  572.         this.parentalAdvisoryId,
  573.         this.artistDisplayName,
  574.         this.collectionDisplayName,
  575.         this.viewUrl,
  576.         this.originalReleaseDate,
  577.         this.itunesReleaseDate,
  578.         this.trackLength,
  579.         newValue,
  580.         this.pLine,
  581.         this.previewUrl,
  582.         this.previewLength,
  583.         this.exportDate);
  584.   }
  585.  
  586.   /**
  587.    * Copy the current immutable object by setting a value for the {@link AbstractSong#pLine() pLine} attribute.
  588.    * An equals check used to prevent copying of the same value by returning {@code this}.
  589.    * @param value A new value for pLine
  590.    * @return A modified copy of the {@code this} object
  591.    */
  592.   public final Song withPLine(String value) {
  593.     if (this.pLine.equals(value)) return this;
  594.     String newValue = Objects.requireNonNull(value, "pLine");
  595.     return new Song(
  596.         this.songId,
  597.         this.name,
  598.         this.titleVersion,
  599.         this.searchTerms,
  600.         this.parentalAdvisoryId,
  601.         this.artistDisplayName,
  602.         this.collectionDisplayName,
  603.         this.viewUrl,
  604.         this.originalReleaseDate,
  605.         this.itunesReleaseDate,
  606.         this.trackLength,
  607.         this.copyright,
  608.         newValue,
  609.         this.previewUrl,
  610.         this.previewLength,
  611.         this.exportDate);
  612.   }
  613.  
  614.   /**
  615.    * Copy the current immutable object by setting a value for the {@link AbstractSong#previewUrl() previewUrl} attribute.
  616.    * An equals check used to prevent copying of the same value by returning {@code this}.
  617.    * @param value A new value for previewUrl
  618.    * @return A modified copy of the {@code this} object
  619.    */
  620.   public final Song withPreviewUrl(String value) {
  621.     if (this.previewUrl.equals(value)) return this;
  622.     String newValue = Objects.requireNonNull(value, "previewUrl");
  623.     return new Song(
  624.         this.songId,
  625.         this.name,
  626.         this.titleVersion,
  627.         this.searchTerms,
  628.         this.parentalAdvisoryId,
  629.         this.artistDisplayName,
  630.         this.collectionDisplayName,
  631.         this.viewUrl,
  632.         this.originalReleaseDate,
  633.         this.itunesReleaseDate,
  634.         this.trackLength,
  635.         this.copyright,
  636.         this.pLine,
  637.         newValue,
  638.         this.previewLength,
  639.         this.exportDate);
  640.   }
  641.  
  642.   /**
  643.    * Copy the current immutable object by setting a value for the {@link AbstractSong#previewLength() previewLength} attribute.
  644.    * An equals check used to prevent copying of the same value by returning {@code this}.
  645.    * @param value A new value for previewLength
  646.    * @return A modified copy of the {@code this} object
  647.    */
  648.   public final Song withPreviewLength(String value) {
  649.     if (this.previewLength.equals(value)) return this;
  650.     String newValue = Objects.requireNonNull(value, "previewLength");
  651.     return new Song(
  652.         this.songId,
  653.         this.name,
  654.         this.titleVersion,
  655.         this.searchTerms,
  656.         this.parentalAdvisoryId,
  657.         this.artistDisplayName,
  658.         this.collectionDisplayName,
  659.         this.viewUrl,
  660.         this.originalReleaseDate,
  661.         this.itunesReleaseDate,
  662.         this.trackLength,
  663.         this.copyright,
  664.         this.pLine,
  665.         this.previewUrl,
  666.         newValue,
  667.         this.exportDate);
  668.   }
  669.  
  670.   /**
  671.    * Copy the current immutable object by setting a value for the {@link AbstractSong#exportDate() exportDate} attribute.
  672.    * An equals check used to prevent copying of the same value by returning {@code this}.
  673.    * @param value A new value for exportDate
  674.    * @return A modified copy of the {@code this} object
  675.    */
  676.   public final Song withExportDate(Long value) {
  677.     if (this.exportDate.equals(value)) return this;
  678.     Long newValue = Objects.requireNonNull(value, "exportDate");
  679.     return new Song(
  680.         this.songId,
  681.         this.name,
  682.         this.titleVersion,
  683.         this.searchTerms,
  684.         this.parentalAdvisoryId,
  685.         this.artistDisplayName,
  686.         this.collectionDisplayName,
  687.         this.viewUrl,
  688.         this.originalReleaseDate,
  689.         this.itunesReleaseDate,
  690.         this.trackLength,
  691.         this.copyright,
  692.         this.pLine,
  693.         this.previewUrl,
  694.         this.previewLength,
  695.         newValue);
  696.   }
  697.  
  698.   /**
  699.    * This instance is equal to all instances of {@code Song} that have equal attribute values.
  700.    * @return {@code true} if {@code this} is equal to {@code another} instance
  701.    */
  702.   @Override
  703.   public boolean equals(Object another) {
  704.     if (this == another) return true;
  705.     return another instanceof Song
  706.         && equalTo((Song) another);
  707.   }
  708.  
  709.   private boolean equalTo(Song another) {
  710.     return songId.equals(another.songId)
  711.         && name.equals(another.name)
  712.         && Objects.equals(titleVersion, another.titleVersion)
  713.         && Objects.equals(searchTerms, another.searchTerms)
  714.         && parentalAdvisoryId.equals(another.parentalAdvisoryId)
  715.         && artistDisplayName.equals(another.artistDisplayName)
  716.         && collectionDisplayName.equals(another.collectionDisplayName)
  717.         && viewUrl.equals(another.viewUrl)
  718.         && originalReleaseDate.equals(another.originalReleaseDate)
  719.         && itunesReleaseDate.equals(another.itunesReleaseDate)
  720.         && trackLength.equals(another.trackLength)
  721.         && copyright.equals(another.copyright)
  722.         && pLine.equals(another.pLine)
  723.         && previewUrl.equals(another.previewUrl)
  724.         && previewLength.equals(another.previewLength)
  725.         && exportDate.equals(another.exportDate);
  726.   }
  727.  
  728.   /**
  729.    * Computes a hash code from attributes: {@code songId}, {@code name}, {@code titleVersion}, {@code searchTerms}, {@code parentalAdvisoryId}, {@code artistDisplayName}, {@code collectionDisplayName}, {@code viewUrl}, {@code originalReleaseDate}, {@code itunesReleaseDate}, {@code trackLength}, {@code copyright}, {@code pLine}, {@code previewUrl}, {@code previewLength}, {@code exportDate}.
  730.    * @return hashCode value
  731.    */
  732.   @Override
  733.   public int hashCode() {
  734.     int h = 31;
  735.     h = h * 17 + songId.hashCode();
  736.     h = h * 17 + name.hashCode();
  737.     h = h * 17 + Objects.hashCode(titleVersion);
  738.     h = h * 17 + Objects.hashCode(searchTerms);
  739.     h = h * 17 + parentalAdvisoryId.hashCode();
  740.     h = h * 17 + artistDisplayName.hashCode();
  741.     h = h * 17 + collectionDisplayName.hashCode();
  742.     h = h * 17 + viewUrl.hashCode();
  743.     h = h * 17 + originalReleaseDate.hashCode();
  744.     h = h * 17 + itunesReleaseDate.hashCode();
  745.     h = h * 17 + trackLength.hashCode();
  746.     h = h * 17 + copyright.hashCode();
  747.     h = h * 17 + pLine.hashCode();
  748.     h = h * 17 + previewUrl.hashCode();
  749.     h = h * 17 + previewLength.hashCode();
  750.     h = h * 17 + exportDate.hashCode();
  751.     return h;
  752.   }
  753.  
  754.   /**
  755.    * Prints the immutable value {@code Song} with attribute values.
  756.    * @return A string representation of the value
  757.    */
  758.   @Override
  759.   public String toString() {
  760.     StringBuilder builder = new StringBuilder("Song{");
  761.     builder.append("songId=").append(songId);
  762.     builder.append(", ");
  763.     builder.append("name=").append(name);
  764.     if (titleVersion != null) {
  765.       builder.append(", ");
  766.       builder.append("titleVersion=").append(titleVersion);
  767.     }
  768.     if (searchTerms != null) {
  769.       builder.append(", ");
  770.       builder.append("searchTerms=").append(searchTerms);
  771.     }
  772.     builder.append(", ");
  773.     builder.append("parentalAdvisoryId=").append(parentalAdvisoryId);
  774.     builder.append(", ");
  775.     builder.append("artistDisplayName=").append(artistDisplayName);
  776.     builder.append(", ");
  777.     builder.append("collectionDisplayName=").append(collectionDisplayName);
  778.     builder.append(", ");
  779.     builder.append("viewUrl=").append(viewUrl);
  780.     builder.append(", ");
  781.     builder.append("originalReleaseDate=").append(originalReleaseDate);
  782.     builder.append(", ");
  783.     builder.append("itunesReleaseDate=").append(itunesReleaseDate);
  784.     builder.append(", ");
  785.     builder.append("trackLength=").append(trackLength);
  786.     builder.append(", ");
  787.     builder.append("copyright=").append(copyright);
  788.     builder.append(", ");
  789.     builder.append("pLine=").append(pLine);
  790.     builder.append(", ");
  791.     builder.append("previewUrl=").append(previewUrl);
  792.     builder.append(", ");
  793.     builder.append("previewLength=").append(previewLength);
  794.     builder.append(", ");
  795.     builder.append("exportDate=").append(exportDate);
  796.     return builder.append("}").toString();
  797.   }
  798.  
  799.   /**
  800.    * Creates an immutable copy of a {@link AbstractSong} value.
  801.    * Uses accessors to get values to initialize the new immutable instance.
  802.    * If an instance is already immutable, it is returned as is.
  803.    * @param instance The instance to copy
  804.    * @return A copied immutable Song instance
  805.    */
  806.   public static Song copy(AbstractSong instance) {
  807.     if (instance instanceof Song) {
  808.       return (Song) instance;
  809.     }
  810.     return Song.builder()
  811.         .from(instance)
  812.         .build();
  813.   }
  814.  
  815.   /**
  816.    * Creates a builder for {@link Song Song}.
  817.    * @return A new Song builder
  818.    */
  819.   public static Song.Builder builder() {
  820.     return new Song.Builder();
  821.   }
  822.  
  823.   /**
  824.    * Builds instances of type {@link Song Song}.
  825.    * Initialize attributes and then invoke the {@link #build()} method to create an
  826.    * immutable instance.
  827.    * <p><em>{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
  828.    * but instead used immediately to create instances.</em>
  829.    */
  830.   public static final class Builder {
  831.     private static final long INIT_BIT_SONG_ID = 0x1L;
  832.     private static final long INIT_BIT_NAME = 0x2L;
  833.     private static final long INIT_BIT_PARENTAL_ADVISORY_ID = 0x4L;
  834.     private static final long INIT_BIT_ARTIST_DISPLAY_NAME = 0x8L;
  835.     private static final long INIT_BIT_COLLECTION_DISPLAY_NAME = 0x10L;
  836.     private static final long INIT_BIT_VIEW_URL = 0x20L;
  837.     private static final long INIT_BIT_ORIGINAL_RELEASE_DATE = 0x40L;
  838.     private static final long INIT_BIT_ITUNES_RELEASE_DATE = 0x80L;
  839.     private static final long INIT_BIT_TRACK_LENGTH = 0x100L;
  840.     private static final long INIT_BIT_COPYRIGHT = 0x200L;
  841.     private static final long INIT_BIT_P_LINE = 0x400L;
  842.     private static final long INIT_BIT_PREVIEW_URL = 0x800L;
  843.     private static final long INIT_BIT_PREVIEW_LENGTH = 0x1000L;
  844.     private static final long INIT_BIT_EXPORT_DATE = 0x2000L;
  845.     private long initBits = 0x3fffL;
  846.  
  847.     private SongId songId;
  848.     private String name;
  849.     private String titleVersion;
  850.     private String searchTerms;
  851.     private Integer parentalAdvisoryId;
  852.     private String artistDisplayName;
  853.     private String collectionDisplayName;
  854.     private String viewUrl;
  855.     private LocalDate originalReleaseDate;
  856.     private LocalDate itunesReleaseDate;
  857.     private String trackLength;
  858.     private String copyright;
  859.     private String pLine;
  860.     private String previewUrl;
  861.     private String previewLength;
  862.     private Long exportDate;
  863.  
  864.     private Builder() {
  865.     }
  866.  
  867.     /**
  868.      * Fill a builder with attribute values from the provided {@code AbstractSong} instance.
  869.      * Regular attribute values will be replaced with those from the given instance.
  870.      * Absent optional values will not replace present values.
  871.      * @param instance The instance from which to copy values
  872.      * @return {@code this} builder for use in a chained invocation
  873.      */
  874.     public final Builder from(AbstractSong instance) {
  875.       Objects.requireNonNull(instance, "instance");
  876.       songId(instance.songId());
  877.       name(instance.name());
  878.       Optional<String> titleVersionOptional = instance.titleVersion();
  879.       if (titleVersionOptional.isPresent()) {
  880.         titleVersion(titleVersionOptional);
  881.       }
  882.       Optional<String> searchTermsOptional = instance.searchTerms();
  883.       if (searchTermsOptional.isPresent()) {
  884.         searchTerms(searchTermsOptional);
  885.       }
  886.       parentalAdvisoryId(instance.parentalAdvisoryId());
  887.       artistDisplayName(instance.artistDisplayName());
  888.       collectionDisplayName(instance.collectionDisplayName());
  889.       viewUrl(instance.viewUrl());
  890.       originalReleaseDate(instance.originalReleaseDate());
  891.       itunesReleaseDate(instance.itunesReleaseDate());
  892.       trackLength(instance.trackLength());
  893.       copyright(instance.copyright());
  894.       pLine(instance.pLine());
  895.       previewUrl(instance.previewUrl());
  896.       previewLength(instance.previewLength());
  897.       exportDate(instance.exportDate());
  898.       return this;
  899.     }
  900.  
  901.     /**
  902.      * Initializes the value for the {@link AbstractSong#songId() songId} attribute.
  903.      * @param songId The value for songId
  904.      * @return {@code this} builder for use in a chained invocation
  905.      */
  906.     public final Builder songId(SongId songId) {
  907.       this.songId = Objects.requireNonNull(songId, "songId");
  908.       initBits &= ~INIT_BIT_SONG_ID;
  909.       return this;
  910.     }
  911.  
  912.     /**
  913.      * Initializes the value for the {@link AbstractSong#name() name} attribute.
  914.      * @param name The value for name
  915.      * @return {@code this} builder for use in a chained invocation
  916.      */
  917.     public final Builder name(String name) {
  918.       this.name = Objects.requireNonNull(name, "name");
  919.       initBits &= ~INIT_BIT_NAME;
  920.       return this;
  921.     }
  922.  
  923.     /**
  924.      * Initializes the optional value {@link AbstractSong#titleVersion() titleVersion} to titleVersion.
  925.      * @param titleVersion The value for titleVersion
  926.      * @return {@code this} builder for chained invocation
  927.      */
  928.     public final Builder titleVersion(String titleVersion) {
  929.       this.titleVersion = Objects.requireNonNull(titleVersion, "titleVersion");
  930.       return this;
  931.     }
  932.  
  933.     /**
  934.      * Initializes the optional value {@link AbstractSong#titleVersion() titleVersion} to titleVersion.
  935.      * @param titleVersion The value for titleVersion
  936.      * @return {@code this} builder for use in a chained invocation
  937.      */
  938.     public final Builder titleVersion(Optional<String> titleVersion) {
  939.       this.titleVersion = titleVersion.orElse(null);
  940.       return this;
  941.     }
  942.  
  943.     /**
  944.      * Initializes the optional value {@link AbstractSong#searchTerms() searchTerms} to searchTerms.
  945.      * @param searchTerms The value for searchTerms
  946.      * @return {@code this} builder for chained invocation
  947.      */
  948.     public final Builder searchTerms(String searchTerms) {
  949.       this.searchTerms = Objects.requireNonNull(searchTerms, "searchTerms");
  950.       return this;
  951.     }
  952.  
  953.     /**
  954.      * Initializes the optional value {@link AbstractSong#searchTerms() searchTerms} to searchTerms.
  955.      * @param searchTerms The value for searchTerms
  956.      * @return {@code this} builder for use in a chained invocation
  957.      */
  958.     public final Builder searchTerms(Optional<String> searchTerms) {
  959.       this.searchTerms = searchTerms.orElse(null);
  960.       return this;
  961.     }
  962.  
  963.     /**
  964.      * Initializes the value for the {@link AbstractSong#parentalAdvisoryId() parentalAdvisoryId} attribute.
  965.      * @param parentalAdvisoryId The value for parentalAdvisoryId
  966.      * @return {@code this} builder for use in a chained invocation
  967.      */
  968.     public final Builder parentalAdvisoryId(Integer parentalAdvisoryId) {
  969.       this.parentalAdvisoryId = Objects.requireNonNull(parentalAdvisoryId, "parentalAdvisoryId");
  970.       initBits &= ~INIT_BIT_PARENTAL_ADVISORY_ID;
  971.       return this;
  972.     }
  973.  
  974.     /**
  975.      * Initializes the value for the {@link AbstractSong#artistDisplayName() artistDisplayName} attribute.
  976.      * @param artistDisplayName The value for artistDisplayName
  977.      * @return {@code this} builder for use in a chained invocation
  978.      */
  979.     public final Builder artistDisplayName(String artistDisplayName) {
  980.       this.artistDisplayName = Objects.requireNonNull(artistDisplayName, "artistDisplayName");
  981.       initBits &= ~INIT_BIT_ARTIST_DISPLAY_NAME;
  982.       return this;
  983.     }
  984.  
  985.     /**
  986.      * Initializes the value for the {@link AbstractSong#collectionDisplayName() collectionDisplayName} attribute.
  987.      * @param collectionDisplayName The value for collectionDisplayName
  988.      * @return {@code this} builder for use in a chained invocation
  989.      */
  990.     public final Builder collectionDisplayName(String collectionDisplayName) {
  991.       this.collectionDisplayName = Objects.requireNonNull(collectionDisplayName, "collectionDisplayName");
  992.       initBits &= ~INIT_BIT_COLLECTION_DISPLAY_NAME;
  993.       return this;
  994.     }
  995.  
  996.     /**
  997.      * Initializes the value for the {@link AbstractSong#viewUrl() viewUrl} attribute.
  998.      * @param viewUrl The value for viewUrl
  999.      * @return {@code this} builder for use in a chained invocation
  1000.      */
  1001.     public final Builder viewUrl(String viewUrl) {
  1002.       this.viewUrl = Objects.requireNonNull(viewUrl, "viewUrl");
  1003.       initBits &= ~INIT_BIT_VIEW_URL;
  1004.       return this;
  1005.     }
  1006.  
  1007.     /**
  1008.      * Initializes the value for the {@link AbstractSong#originalReleaseDate() originalReleaseDate} attribute.
  1009.      * @param originalReleaseDate The value for originalReleaseDate
  1010.      * @return {@code this} builder for use in a chained invocation
  1011.      */
  1012.     public final Builder originalReleaseDate(LocalDate originalReleaseDate) {
  1013.       this.originalReleaseDate = Objects.requireNonNull(originalReleaseDate, "originalReleaseDate");
  1014.       initBits &= ~INIT_BIT_ORIGINAL_RELEASE_DATE;
  1015.       return this;
  1016.     }
  1017.  
  1018.     /**
  1019.      * Initializes the value for the {@link AbstractSong#itunesReleaseDate() itunesReleaseDate} attribute.
  1020.      * @param itunesReleaseDate The value for itunesReleaseDate
  1021.      * @return {@code this} builder for use in a chained invocation
  1022.      */
  1023.     public final Builder itunesReleaseDate(LocalDate itunesReleaseDate) {
  1024.       this.itunesReleaseDate = Objects.requireNonNull(itunesReleaseDate, "itunesReleaseDate");
  1025.       initBits &= ~INIT_BIT_ITUNES_RELEASE_DATE;
  1026.       return this;
  1027.     }
  1028.  
  1029.     /**
  1030.      * Initializes the value for the {@link AbstractSong#trackLength() trackLength} attribute.
  1031.      * @param trackLength The value for trackLength
  1032.      * @return {@code this} builder for use in a chained invocation
  1033.      */
  1034.     public final Builder trackLength(String trackLength) {
  1035.       this.trackLength = Objects.requireNonNull(trackLength, "trackLength");
  1036.       initBits &= ~INIT_BIT_TRACK_LENGTH;
  1037.       return this;
  1038.     }
  1039.  
  1040.     /**
  1041.      * Initializes the value for the {@link AbstractSong#copyright() copyright} attribute.
  1042.      * @param copyright The value for copyright
  1043.      * @return {@code this} builder for use in a chained invocation
  1044.      */
  1045.     public final Builder copyright(String copyright) {
  1046.       this.copyright = Objects.requireNonNull(copyright, "copyright");
  1047.       initBits &= ~INIT_BIT_COPYRIGHT;
  1048.       return this;
  1049.     }
  1050.  
  1051.     /**
  1052.      * Initializes the value for the {@link AbstractSong#pLine() pLine} attribute.
  1053.      * @param pLine The value for pLine
  1054.      * @return {@code this} builder for use in a chained invocation
  1055.      */
  1056.     public final Builder pLine(String pLine) {
  1057.       this.pLine = Objects.requireNonNull(pLine, "pLine");
  1058.       initBits &= ~INIT_BIT_P_LINE;
  1059.       return this;
  1060.     }
  1061.  
  1062.     /**
  1063.      * Initializes the value for the {@link AbstractSong#previewUrl() previewUrl} attribute.
  1064.      * @param previewUrl The value for previewUrl
  1065.      * @return {@code this} builder for use in a chained invocation
  1066.      */
  1067.     public final Builder previewUrl(String previewUrl) {
  1068.       this.previewUrl = Objects.requireNonNull(previewUrl, "previewUrl");
  1069.       initBits &= ~INIT_BIT_PREVIEW_URL;
  1070.       return this;
  1071.     }
  1072.  
  1073.     /**
  1074.      * Initializes the value for the {@link AbstractSong#previewLength() previewLength} attribute.
  1075.      * @param previewLength The value for previewLength
  1076.      * @return {@code this} builder for use in a chained invocation
  1077.      */
  1078.     public final Builder previewLength(String previewLength) {
  1079.       this.previewLength = Objects.requireNonNull(previewLength, "previewLength");
  1080.       initBits &= ~INIT_BIT_PREVIEW_LENGTH;
  1081.       return this;
  1082.     }
  1083.  
  1084.     /**
  1085.      * Initializes the value for the {@link AbstractSong#exportDate() exportDate} attribute.
  1086.      * @param exportDate The value for exportDate
  1087.      * @return {@code this} builder for use in a chained invocation
  1088.      */
  1089.     public final Builder exportDate(Long exportDate) {
  1090.       this.exportDate = Objects.requireNonNull(exportDate, "exportDate");
  1091.       initBits &= ~INIT_BIT_EXPORT_DATE;
  1092.       return this;
  1093.     }
  1094.  
  1095.     /**
  1096.      * Builds a new {@link Song Song}.
  1097.      * @return An immutable instance of Song
  1098.      * @throws java.lang.IllegalStateException if any required attributes are missing
  1099.      */
  1100.     public Song build() {
  1101.       if (initBits != 0) {
  1102.         throw new IllegalStateException(formatRequiredAttributesMessage());
  1103.       }
  1104.       return new Song(
  1105.           songId,
  1106.           name,
  1107.           titleVersion,
  1108.           searchTerms,
  1109.           parentalAdvisoryId,
  1110.           artistDisplayName,
  1111.           collectionDisplayName,
  1112.           viewUrl,
  1113.           originalReleaseDate,
  1114.           itunesReleaseDate,
  1115.           trackLength,
  1116.           copyright,
  1117.           pLine,
  1118.           previewUrl,
  1119.           previewLength,
  1120.           exportDate);
  1121.     }
  1122.  
  1123.     private String formatRequiredAttributesMessage() {
  1124.       List<String> attributes = new ArrayList<String>();
  1125.       if ((initBits & INIT_BIT_SONG_ID) != 0) attributes.add("songId");
  1126.       if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
  1127.       if ((initBits & INIT_BIT_PARENTAL_ADVISORY_ID) != 0) attributes.add("parentalAdvisoryId");
  1128.       if ((initBits & INIT_BIT_ARTIST_DISPLAY_NAME) != 0) attributes.add("artistDisplayName");
  1129.       if ((initBits & INIT_BIT_COLLECTION_DISPLAY_NAME) != 0) attributes.add("collectionDisplayName");
  1130.       if ((initBits & INIT_BIT_VIEW_URL) != 0) attributes.add("viewUrl");
  1131.       if ((initBits & INIT_BIT_ORIGINAL_RELEASE_DATE) != 0) attributes.add("originalReleaseDate");
  1132.       if ((initBits & INIT_BIT_ITUNES_RELEASE_DATE) != 0) attributes.add("itunesReleaseDate");
  1133.       if ((initBits & INIT_BIT_TRACK_LENGTH) != 0) attributes.add("trackLength");
  1134.       if ((initBits & INIT_BIT_COPYRIGHT) != 0) attributes.add("copyright");
  1135.       if ((initBits & INIT_BIT_P_LINE) != 0) attributes.add("pLine");
  1136.       if ((initBits & INIT_BIT_PREVIEW_URL) != 0) attributes.add("previewUrl");
  1137.       if ((initBits & INIT_BIT_PREVIEW_LENGTH) != 0) attributes.add("previewLength");
  1138.       if ((initBits & INIT_BIT_EXPORT_DATE) != 0) attributes.add("exportDate");
  1139.       return "Cannot build Song, some of required attributes are not set " + attributes;
  1140.     }
  1141.   }
  1142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement