001// Generated by delombok at Sat Feb 25 17:58:34 UTC 2023 002package io.cui.tools.collect; 003 004import java.io.Serializable; 005import java.util.ArrayList; 006import java.util.Collection; 007import java.util.Collections; 008import java.util.List; 009 010/** 011 * <h2>Overview</h2> 012 * Default implementation of {@link PartialCollection} based on {@link ArrayList}. 013 * <h3>Usage</h3> 014 * <p> 015 * See {@link PartialArrayList#of(List, int)} 016 * </p> 017 * 018 * @param <T> at least {@link Serializable} 019 */ 020public class PartialArrayList<T extends Serializable> extends ArrayList<T> implements PartialCollection<T> { 021 private static final long serialVersionUID = -7548645400982124555L; 022 private final boolean moreAvailable; 023 024 /** 025 * Default constructor. 026 * 027 * @param list the list of entities to store. 028 * @param moreAvailable the flag to store. 029 */ 030 public PartialArrayList(Collection<T> list, boolean moreAvailable) { 031 super(list); 032 this.moreAvailable = moreAvailable; 033 } 034 035 /** 036 * Static constructor for an empty instance. 037 * 038 * @param <T> 039 * @return an empty {@link PartialArrayList}. 040 */ 041 public static <T extends Serializable> PartialArrayList<T> emptyList() { 042 return new PartialArrayList<>(Collections.emptyList(), false); 043 } 044 045 /** 046 * Convenience method for creating a {@link PartialArrayList} as sublist for the given 047 * collection with setting the {@link PartialCollection#isMoreAvailable()} automatically 048 * 049 * @param full the complete List to be wrapped, may be larger than the limit. If so, a sublist 050 * will be used. 051 * @param limit to be checked against 052 * 053 * @param <T> identifying the type of contained elements 054 * @return a newly created {@link PartialArrayList}. 055 */ 056 public static <T extends Serializable> PartialArrayList<T> of(List<T> full, int limit) { 057 if (MoreCollections.isEmpty(full)) { 058 return emptyList(); 059 } 060 var actualSize = full.size(); 061 if (actualSize <= limit) { 062 return new PartialArrayList<>(full, false); 063 } 064 return new PartialArrayList<>(full.subList(0, limit), true); 065 } 066 067 @java.lang.Override 068 @java.lang.SuppressWarnings("all") 069 @lombok.Generated 070 public boolean equals(final java.lang.Object o) { 071 if (o == this) return true; 072 if (!(o instanceof PartialArrayList)) return false; 073 final PartialArrayList<?> other = (PartialArrayList<?>) o; 074 if (!other.canEqual((java.lang.Object) this)) return false; 075 if (!super.equals(o)) return false; 076 if (this.isMoreAvailable() != other.isMoreAvailable()) return false; 077 return true; 078 } 079 080 @java.lang.SuppressWarnings("all") 081 @lombok.Generated 082 protected boolean canEqual(final java.lang.Object other) { 083 return other instanceof PartialArrayList; 084 } 085 086 @java.lang.Override 087 @java.lang.SuppressWarnings("all") 088 @lombok.Generated 089 public int hashCode() { 090 final int PRIME = 59; 091 int result = super.hashCode(); 092 result = result * PRIME + (this.isMoreAvailable() ? 79 : 97); 093 return result; 094 } 095 096 @java.lang.Override 097 @java.lang.SuppressWarnings("all") 098 @lombok.Generated 099 public java.lang.String toString() { 100 return "PartialArrayList(super=" + super.toString() + ", moreAvailable=" + this.isMoreAvailable() + ")"; 101 } 102 103 @java.lang.SuppressWarnings("all") 104 @lombok.Generated 105 public boolean isMoreAvailable() { 106 return this.moreAvailable; 107 } 108}