@Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }

    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    VersionHistory that = (VersionHistory) o;
    return getId() == that.getId();
  }
  @Override
  public Version getFirstVersion(VersionHistory versionHistory) {
    List<Version> versions = versionHistory.getVersions();
    if (CollectionUtils.isEmpty(versions)) {
      return null;
    }

    return versions.get(versions.size() - 1);
  }
  @Override
  public Version getLatestVersion(VersionHistory versionHistory) {
    List<Version> versions = versionHistory.getVersions();
    if (CollectionUtils.isEmpty(versions)) {
      return null;
    }

    return versions.iterator().next();
  }
 // LIST order: descending
 @Override
 public Version getNext(VersionHistory versionHistory, Version version) {
   List<Version> versions = versionHistory.getVersions();
   int index = versions.indexOf(version);
   if (index == 0) {
     return null;
   }
   return versions.get(index - 1);
 }
  // LIST order: descending
  @Override
  public Version getPrevious(VersionHistory versionHistory, Version version) {
    List<Version> versions = versionHistory.getVersions();
    int index = versions.indexOf(version);

    if ((index + 1) == versions.size()) return null;

    return versions.get(index + 1);
  }
 @Override
 public boolean isLastVersion(VersionHistory versionHistory, Version version) {
   List<Version> versions = versionHistory.getVersions();
   if (CollectionUtils.isEmpty(versions)) {
     return false;
   }
   Version last = versions.iterator().next();
   return last.equals(version);
 }
 @Override
 public Version getVersion(VersionHistory versionHistory, Item item) {
   List<Version> versions = versionHistory.getVersions();
   for (Version v : versions) {
     if (v.getItem().getID() == item.getID()) {
       return v;
     }
   }
   return null;
 }
 @Override
 public void add(VersionHistory versionHistory, Version version) {
   versionHistory.addVersionAtStart(version);
 }
 @Override
 public void remove(VersionHistory versionHistory, Version version) {
   versionHistory.removeVersion(version);
 }
 @Override
 public boolean isFirstVersion(VersionHistory versionHistory, Version version) {
   List<Version> versions = versionHistory.getVersions();
   Version first = versions.get(versions.size() - 1);
   return first.equals(version);
 }