001 /* 002 * Sonar, open source software quality management tool. 003 * Copyright (C) 2009 SonarSource SA 004 * mailto:contact AT sonarsource DOT com 005 * 006 * Sonar is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 3 of the License, or (at your option) any later version. 010 * 011 * Sonar is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with Sonar; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 019 */ 020 package org.sonar.api.batch; 021 022 import org.apache.commons.lang.builder.ToStringBuilder; 023 import org.sonar.api.database.model.Snapshot; 024 025 /** 026 * 027 * @since 1.10 028 */ 029 public class PurgeContext { 030 031 private Integer currentSid; 032 private Integer lastSid; 033 034 public PurgeContext() { 035 } 036 037 public PurgeContext(Snapshot currentSnapshot) { 038 this(currentSnapshot, null); 039 } 040 041 public PurgeContext(Snapshot currentSnapshot, Snapshot lastSnapshot) { 042 if (currentSnapshot != null) { 043 currentSid = currentSnapshot.getId(); 044 } 045 if (lastSnapshot != null) { 046 lastSid = lastSnapshot.getId(); 047 } 048 } 049 050 public PurgeContext(Integer currentSid, Integer lastSid) { 051 this.currentSid = currentSid; 052 this.lastSid = lastSid; 053 } 054 055 public PurgeContext setLastSnapshotId(Integer lastSid) { 056 this.lastSid = lastSid; 057 return this; 058 } 059 060 public PurgeContext setCurrentSnapshotId(Integer currentSid) { 061 this.currentSid = currentSid; 062 return this; 063 } 064 065 public Integer getPreviousSnapshotId() { 066 return lastSid; 067 } 068 069 public Integer getLastSnapshotId() { 070 return currentSid; 071 } 072 073 @Override 074 public boolean equals(Object o) { 075 if (this == o) { 076 return true; 077 } 078 if (o == null || getClass() != o.getClass()) { 079 return false; 080 } 081 082 PurgeContext context = (PurgeContext) o; 083 084 if (!currentSid.equals(context.currentSid)) { 085 return false; 086 } 087 if (lastSid != null ? !lastSid.equals(context.lastSid) : context.lastSid != null) { 088 return false; 089 } 090 091 return true; 092 } 093 094 @Override 095 public int hashCode() { 096 int result = lastSid != null ? lastSid.hashCode() : 0; 097 result = 31 * result + currentSid.hashCode(); 098 return result; 099 } 100 101 @Override 102 public String toString() { 103 return new ToStringBuilder(this) 104 .append("currentSid", currentSid) 105 .append("lastSid", lastSid) 106 .toString(); 107 } 108 }