001package com.pusher.client.connection; 002 003/** 004 * Represents a change in connection state. 005 */ 006public class ConnectionStateChange { 007 008 private final ConnectionState previousState; 009 private final ConnectionState currentState; 010 011 /** 012 * Used within the library to create a connection state change. Not be used 013 * used as part of the API. 014 * 015 * @param previousState The previous connection state 016 * @param currentState The current connection state 017 */ 018 public ConnectionStateChange(final ConnectionState previousState, final ConnectionState currentState) { 019 020 if (previousState == currentState) { 021 throw new IllegalArgumentException( 022 "Attempted to create an connection state update where both previous and current state are: " 023 + currentState); 024 } 025 026 this.previousState = previousState; 027 this.currentState = currentState; 028 } 029 030 /** 031 * The previous connections state. The state the connection has transitioned 032 * from. 033 * 034 * @return The previous connection state 035 */ 036 public ConnectionState getPreviousState() { 037 return previousState; 038 } 039 040 /** 041 * The current connection state. The state the connection has transitioned 042 * to. 043 * 044 * @return The current connection state 045 */ 046 public ConnectionState getCurrentState() { 047 return currentState; 048 } 049 050 @Override 051 public int hashCode() { 052 return previousState.hashCode() + currentState.hashCode(); 053 } 054 055 @Override 056 public boolean equals(final Object obj) { 057 if (obj != null && obj instanceof ConnectionStateChange) { 058 final ConnectionStateChange other = (ConnectionStateChange)obj; 059 return currentState == other.currentState && previousState == other.previousState; 060 } 061 062 return false; 063 } 064}