
net.sf.eBus.client.sysmessages.KeyMessage Maven / Gradle / Ivy
//
// Copyright 2016, 2019, 2020 Charles W. Rapp
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package net.sf.eBus.client.sysmessages;
import java.io.Serializable;
import java.util.Objects;
/**
* This system message is used to exchange
* message key-to-identifier mappings.
*
* @author Charles W. Rapp
*/
public final class KeyMessage
extends AbstractKeyMessage
implements Serializable
{
//---------------------------------------------------------------
// Member data.
//
//-----------------------------------------------------------
// Constants.
//
/**
* Serialization version identifier.
*/
private static final long serialVersionUID = 0x050500L;
//-----------------------------------------------------------
// Locals.
//
/**
* The sender's message key identifier. The receiver may
* assign its own unique identifier for the key.
*/
public final int keyId;
//---------------------------------------------------------------
// Member methods.
//
//-----------------------------------------------------------
// Constructors.
//
/**
* Creates a new key message from the configured message
* builder.
* @param builder message builder.
*/
private KeyMessage(final Builder builder)
{
super (builder);
this.keyId = builder.mKeyId;
} // end of KeyMessage(Builder)
//
// end of Constructors.
//-----------------------------------------------------------
//-----------------------------------------------------------
// Object Method Overrides.
//
@Override
public boolean equals(final Object o)
{
boolean retcode = (this == o);
if (!retcode && o instanceof KeyMessage)
{
retcode = (super.equals(o) &&
keyId == ((KeyMessage) o).keyId);
}
return (retcode);
} // end of equals(Object)
@Override
public int hashCode()
{
return (Objects.hash(super.hashCode(), keyId));
} // end of hashCode()
@Override
public String toString()
{
return (String.format("%s%n key ID: %d",
super.toString(),
keyId));
} // end of toString()
//
// end of Object Method Overrides.
//-----------------------------------------------------------
/**
* Returns a new instance of the {@code KeyMessage} builder.
* @return message builder instance.
*/
public static Builder builder()
{
return (new Builder());
} // end of builder()
//---------------------------------------------------------------
// Inner classes.
//
/**
* Class used to create {@link KeyMessage} instances. Used by
* eBus to de-serialize an encoded message.
*/
public static final class Builder
extends AbstractKeyMessage.Builder
{
//-----------------------------------------------------------
// Member data.
//
//-------------------------------------------------------
// Locals.
//
private int mKeyId;
//-----------------------------------------------------------
// Member methods.
//
//-------------------------------------------------------
// Constructors.
//
private Builder()
{
super (KeyMessage.class);
} // end of Builder()
//
// end of Constructors.
//-------------------------------------------------------
//-------------------------------------------------------
// Builder Method Overrides.
//
/**
* Returns the newly instantiated {@code KeyMessage}
* based on this builder configuration.
* @return target message instance.
*/
@Override
protected KeyMessage buildImpl()
{
return (new KeyMessage(this));
} // end of buildImpl()
//
// end of Builder Method Overrides.
//-------------------------------------------------------
//-------------------------------------------------------
// Set Methods.
//
/**
* Sets the message key identifier to the given value.
* @param id message key identifier.
* @return {@code this} key message builder.
*/
public Builder keyId(final int id)
{
mKeyId = id;
return (this);
} // end of keyId(int)
//
// end of Set Methods.
//-------------------------------------------------------
} // end of class Builder
} // end of class KeyMessage
© 2015 - 2025 Weber Informatics LLC | Privacy Policy