001 package org.sonar.core.purge; 002 003 import org.apache.commons.lang.builder.ToStringBuilder; 004 import org.sonar.api.batch.PurgeContext; 005 import org.sonar.api.database.model.Snapshot; 006 007 public class DefaultPurgeContext implements PurgeContext { 008 009 private Integer currentSid; 010 private Integer lastSid; 011 012 public DefaultPurgeContext() { 013 } 014 015 public DefaultPurgeContext(Snapshot currentSnapshot) { 016 this(currentSnapshot, null); 017 } 018 019 public DefaultPurgeContext(Snapshot currentSnapshot, Snapshot lastSnapshot) { 020 if (currentSnapshot != null) { 021 currentSid = currentSnapshot.getId(); 022 } 023 if (lastSnapshot != null) { 024 lastSid = lastSnapshot.getId(); 025 } 026 } 027 028 public DefaultPurgeContext(Integer currentSid, Integer lastSid) { 029 this.currentSid = currentSid; 030 this.lastSid = lastSid; 031 } 032 033 public DefaultPurgeContext setLastSnapshotId(Integer lastSid) { 034 this.lastSid = lastSid; 035 return this; 036 } 037 038 public DefaultPurgeContext setCurrentSnapshotId(Integer currentSid) { 039 this.currentSid = currentSid; 040 return this; 041 } 042 043 public Integer getPreviousSnapshotId() { 044 return lastSid; 045 } 046 047 public Integer getLastSnapshotId() { 048 return currentSid; 049 } 050 051 @Override 052 public boolean equals(Object o) { 053 if (this == o) { 054 return true; 055 } 056 if (o == null || getClass() != o.getClass()) { 057 return false; 058 } 059 060 DefaultPurgeContext context = (DefaultPurgeContext) o; 061 062 if (!currentSid.equals(context.currentSid)) { 063 return false; 064 } 065 if (lastSid != null ? !lastSid.equals(context.lastSid) : context.lastSid != null) { 066 return false; 067 } 068 069 return true; 070 } 071 072 @Override 073 public int hashCode() { 074 int result = lastSid != null ? lastSid.hashCode() : 0; 075 result = 31 * result + currentSid.hashCode(); 076 return result; 077 } 078 079 @Override 080 public String toString() { 081 return new ToStringBuilder(this) 082 .append("currentSid", currentSid) 083 .append("lastSid", lastSid) 084 .toString(); 085 } 086 }