| 1 | package com.reallifedeveloper.common.application.notification; | |
| 2 | ||
| 3 | /** | |
| 4 | * The ID of a {@link NotificationLog}, representing an interval of {@link Notification Notifications} that can be held in the log. | |
| 5 | * <p> | |
| 6 | * The low and high properties of the {@code NotificationLogId} refer to the IDs of the | |
| 7 | * {@link com.reallifedeveloper.common.application.eventstore.StoredEvent StoredEvents} represented by the first and last | |
| 8 | * {@link Notification Notifications}, respectively. | |
| 9 | * <p> | |
| 10 | * For a {@link NotificationLog} that has been archived, the low and high attributes of the ID exactly match the stored event IDs of the | |
| 11 | * first and last notifications. If the log has not yet been archived, it is not yet "full", so the high attribute may be greater than the | |
| 12 | * stored event ID of the last notification. | |
| 13 | * <p> | |
| 14 | * For example, an unarchived notification log which can hold 20 notifications may contain only 5 notifications, with stored event IDs 80 | |
| 15 | * through 84. In this case, the {@code NotificationLogId} would have a low property of 80 and a high property of 99. | |
| 16 | * | |
| 17 | * @author RealLifeDeveloper | |
| 18 | */ | |
| 19 | public final class NotificationLogId { | |
| 20 | ||
| 21 | private final long low; | |
| 22 | private final long high; | |
| 23 | ||
| 24 | /** | |
| 25 | * Creates a new {@code NotificationLogId} with the given low and high properties. | |
| 26 | * | |
| 27 | * @param low the stored event ID of the first {@link Notification} | |
| 28 | * @param high the stored event ID of the last {@link Notification} | |
| 29 | * | |
| 30 | * @throws IllegalArgumentException if {@code low} is greater than {@code high} | |
| 31 | */ | |
| 32 | public NotificationLogId(long low, long high) { | |
| 33 |
2
1. <init> : negated conditional → KILLED 2. <init> : changed conditional boundary → KILLED |
if (low > high) { |
| 34 | throw new IllegalArgumentException("low must not be greater than high: low=" + low + ", high=" + high); | |
| 35 | } | |
| 36 | this.low = low; | |
| 37 | this.high = high; | |
| 38 | } | |
| 39 | ||
| 40 | /** | |
| 41 | * Creates a new {@code NotificationLogId} with the low and high properties parsed from a comma-separated string. | |
| 42 | * | |
| 43 | * @param notificationLogId a string on the form "<low>,<high>" | |
| 44 | * | |
| 45 | * @throws IllegalArgumentException if the string is {@code null} or has the wrong form | |
| 46 | */ | |
| 47 | public NotificationLogId(String notificationLogId) { | |
| 48 |
1
1. <init> : negated conditional → KILLED |
if (notificationLogId == null) { |
| 49 | throw new IllegalArgumentException("notificationLogId must not be null"); | |
| 50 | } | |
| 51 | String[] textIds = notificationLogId.split(",", -1); | |
| 52 |
1
1. <init> : negated conditional → KILLED |
if (textIds.length != 2) { |
| 53 | throw new IllegalArgumentException("notificationLogId should be on the form '<low>,<high>'" | |
| 54 | + ", where <low> and <high> are integers: notificationLogId=" + notificationLogId); | |
| 55 | } | |
| 56 | try { | |
| 57 | this.low = Long.parseLong(textIds[0]); | |
| 58 | this.high = Long.parseLong(textIds[1]); | |
| 59 | } catch (NumberFormatException e) { | |
| 60 | throw new IllegalArgumentException("notificationLogId should be on the form '<low>,<high>'" | |
| 61 | + ", where <low> and <high> are integers: notificationLogId=" + notificationLogId, e); | |
| 62 | } | |
| 63 |
2
1. <init> : negated conditional → KILLED 2. <init> : changed conditional boundary → KILLED |
if (low() > high()) { |
| 64 | throw new IllegalArgumentException("low must not be greater than high: low=" + low() + ", high=" + high()); | |
| 65 | } | |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * Gives a standard string representation of this {@code NotificationLogId}, on the form "<low>,<high>". | |
| 70 | * | |
| 71 | * @return a standard string representation of this {@code NotificationLogId} | |
| 72 | */ | |
| 73 | public String externalForm() { | |
| 74 |
1
1. externalForm : replaced return value with "" for com/reallifedeveloper/common/application/notification/NotificationLogId::externalForm → KILLED |
return Long.toString(low()) + "," + Long.toString(high()); |
| 75 | } | |
| 76 | ||
| 77 | /** | |
| 78 | * Gives the low property of this {@code NotificationLogId}, i.e., the stored event ID of the first notification that may be stored in a | |
| 79 | * {@link NotificationLog}. | |
| 80 | * | |
| 81 | * @return the low property of this {@code NotificationLogId} | |
| 82 | */ | |
| 83 | public long low() { | |
| 84 |
1
1. low : replaced long return with 0 for com/reallifedeveloper/common/application/notification/NotificationLogId::low → KILLED |
return low; |
| 85 | } | |
| 86 | ||
| 87 | /** | |
| 88 | * Gives the high property of this {@code NotificationLogId}, i.e., the stored event ID of the last notification that may be stored in a | |
| 89 | * {@link NotificationLog}. | |
| 90 | * | |
| 91 | * @return the high property of this {@code NotificationLogId} | |
| 92 | */ | |
| 93 | public long high() { | |
| 94 |
1
1. high : replaced long return with 0 for com/reallifedeveloper/common/application/notification/NotificationLogId::high → KILLED |
return high; |
| 95 | } | |
| 96 | ||
| 97 | /** | |
| 98 | * Gives a {@code NotificationLogId} representing the next batch of notifications, after the ones in the current | |
| 99 | * {@link NotificationLog}. | |
| 100 | * | |
| 101 | * @return a {@code NotificationLogId} representing the next batch of notifications | |
| 102 | */ | |
| 103 | public NotificationLogId next() { | |
| 104 |
3
1. next : replaced return value with null for com/reallifedeveloper/common/application/notification/NotificationLogId::next → KILLED 2. next : Replaced long addition with subtraction → KILLED 3. next : Replaced long addition with subtraction → KILLED |
return new NotificationLogId(low() + batchSize(), high() + batchSize()); |
| 105 | } | |
| 106 | ||
| 107 | /** | |
| 108 | * Gives a {@code NotificationLogId} representing the previous batch of notifications, before the ones in the current | |
| 109 | * {@link NotificationLog}. | |
| 110 | * | |
| 111 | * @return a {@code NotificationLogId} representing the previous batch of notifications | |
| 112 | */ | |
| 113 | public NotificationLogId previous() { | |
| 114 |
3
1. previous : replaced return value with null for com/reallifedeveloper/common/application/notification/NotificationLogId::previous → KILLED 2. previous : Replaced long subtraction with addition → KILLED 3. previous : Replaced long subtraction with addition → KILLED |
return new NotificationLogId(low() - batchSize(), high() - batchSize()); |
| 115 | } | |
| 116 | ||
| 117 | /** | |
| 118 | * Gives the batch size of the {@link NotificationLog} with this {@code NotificationLogId}, i.e., the number of {@link Notification | |
| 119 | * Notifications} it can hold. | |
| 120 | * | |
| 121 | * @return the batch size | |
| 122 | */ | |
| 123 | public int batchSize() { | |
| 124 |
3
1. batchSize : replaced int return with 0 for com/reallifedeveloper/common/application/notification/NotificationLogId::batchSize → KILLED 2. batchSize : Replaced long subtraction with addition → KILLED 3. batchSize : Replaced long addition with subtraction → KILLED |
return (int) (high() - low() + 1); |
| 125 | } | |
| 126 | ||
| 127 | @Override | |
| 128 | public String toString() { | |
| 129 |
1
1. toString : replaced return value with "" for com/reallifedeveloper/common/application/notification/NotificationLogId::toString → KILLED |
return externalForm(); |
| 130 | } | |
| 131 | ||
| 132 | } | |
Mutations | ||
| 33 |
1.1 2.2 |
|
| 48 |
1.1 |
|
| 52 |
1.1 |
|
| 63 |
1.1 2.2 |
|
| 74 |
1.1 |
|
| 84 |
1.1 |
|
| 94 |
1.1 |
|
| 104 |
1.1 2.2 3.3 |
|
| 114 |
1.1 2.2 3.3 |
|
| 124 |
1.1 2.2 3.3 |
|
| 129 |
1.1 |