Skip to content

Commit

Permalink
Add equals and hashcode to base sync statistics (#1108)
Browse files Browse the repository at this point in the history
  • Loading branch information
lojzatran authored Nov 13, 2023
1 parent c0cbae0 commit 9232b22
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 17 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# commercetools sync java
[![CI](https://github.com/commercetools/commercetools-sync-java/workflows/CI/badge.svg)](https://github.com/commercetools/commercetools-sync-java/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/commercetools/commercetools-sync-java/branch/master/graph/badge.svg)](https://codecov.io/gh/commercetools/commercetools-sync-java)
[![Javadoc](https://javadoc.io/badge2/com.commercetools/commercetools-sync-java/javadoc.svg?label=Javadoc)](https://commercetools.github.io/commercetools-sync-java/v/10.0.0-beta.3-beta.3/)
[![Javadoc](https://javadoc.io/badge2/com.commercetools/commercetools-sync-java/javadoc.svg?label=Javadoc)](https://commercetools.github.io/commercetools-sync-java/v/10.0.0/)
[![Known Vulnerabilities](https://snyk.io/test/github/commercetools/commercetools-sync-java/4b2e26113d591bda158217c5dc1cf80a88665646/badge.svg)](https://snyk.io/test/github/commercetools/commercetools-sync-java/4b2e26113d591bda158217c5dc1cf80a88665646)


Expand Down Expand Up @@ -60,26 +60,26 @@ Here are the most popular ones:
<dependency>
<groupId>com.commercetools</groupId>
<artifactId>commercetools-sync-java</artifactId>
<version>10.0.0-beta.3</version>
<version>10.0.0</version>
</dependency>
````

#### Gradle

````groovy
implementation 'com.commercetools:commercetools-sync-java:10.0.0-beta.3'
implementation 'com.commercetools:commercetools-sync-java:10.0.0'
````

#### SBT

````
libraryDependencies += "com.commercetools" % "commercetools-sync-java" % "10.0.0-beta.3"
libraryDependencies += "com.commercetools" % "commercetools-sync-java" % "10.0.0"
````

#### Ivy

````xml
<dependency org="com.commercetools" name="commercetools-sync-java" rev="10.0.0-beta.3"/>
<dependency org="com.commercetools" name="commercetools-sync-java" rev="10.0.0"/>
````

**Note**: To avoid `commercetools JVM SDK` libraries version mismatch between projects.
Expand Down
14 changes: 7 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# commercetools sync
[![CI](https://github.com/commercetools/commercetools-sync-java/workflows/CI/badge.svg)](https://github.com/commercetools/commercetools-sync-java/actions?query=workflow%3ACI)
[![codecov](https://codecov.io/gh/commercetools/commercetools-sync-java/branch/master/graph/badge.svg)](https://codecov.io/gh/commercetools/commercetools-sync-java)
[![Benchmarks 10.0.0-beta.3](https://img.shields.io/badge/Benchmarks-10.0.0-beta.3-orange.svg)](https://commercetools.github.io/commercetools-sync-java/benchmarks/)
[![Download from Maven Central](https://img.shields.io/badge/Maven_Central-10.0.0-beta.3-blue.svg)](https://search.maven.org/artifact/com.commercetools/commercetools-sync-java/10.0.0-beta.3/jar)
[![Javadoc](https://javadoc.io/badge2/com.commercetools/commercetools-sync-java/javadoc.svg?label=Javadoc)](https://commercetools.github.io/commercetools-sync-java/v/10.0.0-beta.3/)
[![Benchmarks 10.0.0](https://img.shields.io/badge/Benchmarks-10.0.0-orange.svg)](https://commercetools.github.io/commercetools-sync-java/benchmarks/)
[![Download from Maven Central](https://img.shields.io/badge/Maven_Central-10.0.0-blue.svg)](https://search.maven.org/artifact/com.commercetools/commercetools-sync-java/10.0.0/jar)
[![Javadoc](https://javadoc.io/badge2/com.commercetools/commercetools-sync-java/javadoc.svg?label=Javadoc)](https://commercetools.github.io/commercetools-sync-java/v/10.0.0/)
[![Known Vulnerabilities](https://snyk.io/test/github/commercetools/commercetools-sync-java/4b2e26113d591bda158217c5dc1cf80a88665646/badge.svg)](https://snyk.io/test/github/commercetools/commercetools-sync-java/4b2e26113d591bda158217c5dc1cf80a88665646)


Expand Down Expand Up @@ -40,18 +40,18 @@ Here are the most popular ones:
<dependency>
<groupId>com.commercetools</groupId>
<artifactId>commercetools-sync-java</artifactId>
<version>10.0.0-beta.3</version>
<version>10.0.0</version>
</dependency>
````
#### Gradle
````groovy
implementation 'com.commercetools:commercetools-sync-java:10.0.0-beta.3'
implementation 'com.commercetools:commercetools-sync-java:10.0.0'
````
#### SBT
````
libraryDependencies += "com.commercetools" % "commercetools-sync-java" % "10.0.0-beta.3"
libraryDependencies += "com.commercetools" % "commercetools-sync-java" % "10.0.0"
````
#### Ivy
````xml
<dependency org="com.commercetools" name="commercetools-sync-java" rev="10.0.0-beta.3"/>
<dependency org="com.commercetools" name="commercetools-sync-java" rev="10.0.0"/>
````
10 changes: 5 additions & 5 deletions docs/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@
7. Add Migration guide section which specifies explicitly if there are breaking changes and how to tackle them.
-->

### 10.0.0-beta.1 - Sep 8, 2023
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/9.2.3...10.0.0-beta.3) |
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/10.0.0-beta.3/) |
[Jar](https://search.maven.org/artifact/com.commercetools/commercetools-sync-java/10.0.0-beta.3/jar)
### 10.0.0 - Nov 6, 2023
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/9.2.3...10.0.0) |
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/10.0.0/) |
[Jar](https://search.maven.org/artifact/com.commercetools/commercetools-sync-java/10.0.0/jar)
-
- 🚧 **Breaking Changes** (1)
- commercetools-sync-java is now fully migrated to `commercetools-sdk-java-v2`. See [Migration Guide](./MIGRATION_GUIDE.md) on how to use this library version.


### 9.2.3 - Mar 21, 2023
[Commits](https://github.com/commercetools/commercetools-sync-java/compare/9.2.1...9.2.3) |
[Javadoc](https://commercetools.github.io/commercetools-sync-java/v/9.2.3/) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static java.lang.String.format;

import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -303,6 +304,44 @@ public String getSyncStatisticsClassName() {
*/
protected abstract SyncStatisticsT getThis();

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
final BaseSyncStatistics<?> that = (BaseSyncStatistics<?>) o;
return latestBatchStartTime == that.latestBatchStartTime
&& Objects.equals(getSyncStatisticsClassName(), that.getSyncStatisticsClassName())
&& getLatestBatchProcessingTimeInDays() == that.getLatestBatchProcessingTimeInDays()
&& getLatestBatchProcessingTimeInHours() == that.getLatestBatchProcessingTimeInHours()
&& getLatestBatchProcessingTimeInMinutes() == that.getLatestBatchProcessingTimeInMinutes()
&& getLatestBatchProcessingTimeInSeconds() == that.getLatestBatchProcessingTimeInSeconds()
&& getLatestBatchProcessingTimeInMillis() == that.getLatestBatchProcessingTimeInMillis()
&& getUpdated().get() == that.getUpdated().get()
&& getCreated().get() == that.getCreated().get()
&& getFailed().get() == that.getFailed().get()
&& getProcessed().get() == that.getProcessed().get()
&& Objects.equals(
getLatestBatchHumanReadableProcessingTime(),
that.getLatestBatchHumanReadableProcessingTime());
}

@Override
public int hashCode() {
return Objects.hash(
getSyncStatisticsClassName(),
getUpdated().get(),
getCreated().get(),
getFailed().get(),
getProcessed().get(),
latestBatchStartTime,
getLatestBatchProcessingTimeInDays(),
getLatestBatchProcessingTimeInHours(),
getLatestBatchProcessingTimeInMinutes(),
getLatestBatchProcessingTimeInSeconds(),
getLatestBatchProcessingTimeInMillis(),
getLatestBatchHumanReadableProcessingTime());
}

/**
* Builds a proper summary message of the statistics report of a given {@code resourceString} in
* following format:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,12 @@ void getDefaultReportMessageForResource_withResourceString_ShouldBuildCorrectSum
"Summary: 0 resources were processed in total (0 created, 0 updated and 0 "
+ "failed to sync).");
}

@Test
void twoSyncsStatistics_withSameProperties_ShouldBeEqual() {
final CustomerSyncStatistics customerSyncStatistics = new CustomerSyncStatistics();
final CustomerSyncStatistics customerSyncStatisticsIdentical = new CustomerSyncStatistics();

assertThat(customerSyncStatistics).isEqualTo(customerSyncStatisticsIdentical);
}
}

0 comments on commit 9232b22

Please sign in to comment.