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