Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * openwms.org, the Open Warehouse Management System.
   * Copyright (C) 2014 Heiko Scherrer
   *
   * This file is part of openwms.org.
   *
   * openwms.org is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as 
   * published by the Free Software Foundation; either version 2 of the
  * License, or (at your option) any later version.
  *
  * openwms.org is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this software. If not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.openwms.common.comm.api;
 
 
A CommonHeader represents the header part of a CommonMessage.

Author(s):
Heiko Scherrer
Version:
$Revision: $
Since:
0.2
 
 public class CommonHeader implements Serializable {
 
     private static final long serialVersionUID = 1L;
     private String sync;
     private short messageLength;
     private String sender;
     private String receiver;
     private short sequenceNo;
 
     private static final short LENGTH_SYNC_FIELD = 3;
     private static final short LENGTH_MESSAGE_LENGTH_FIELD = 5;
     private static final short LENGTH_SENDER_FIELD = 5;
     private static final short LENGTH_RECEIVER_FIELD = 5;
     private static final short LENGTH_SEQUENCE_NO_FIELD = 5;

    
Create a new CommonHeader.

Parameters:
sync The sync field
messageLength The length of the message
sender The sender identifier
receiver The receiver identifier
sequenceNo An incremental sequence number
 
     public CommonHeader(String syncshort messageLengthString senderString receivershort sequenceNo) {
         super();
         this. = sync;
         this. = messageLength;
         this. = sender;
         this. = receiver;
         this. = sequenceNo;
     }

    
Create a new CommonHeader.

Parameters:
commonHeader The header to get the values from.
 
     public CommonHeader(CommonHeader commonHeader) {
         this(commonHeader.getSync(), commonHeader.getMessageLength(), commonHeader.getSender(), commonHeader.getReceiver(), commonHeader.getSequenceNo());
     }

    
Create a new CommonHeader.

Parameters:
telegram The telegram String
 
     // TODO [scherrer] : remove this it is specific to telegrams.
     public CommonHeader(String telegram) {
         this. = telegram.substring(0, getLengthSyncField());
 
         int start = .length();
         int end = start + getLengthTelegramLengthField();
         this. = Short.parseShort(telegram.substring(startend));
 
         start = end;
         end += getLengthSenderField();
         this. = telegram.substring(startend);
 
        start = end;
        end += getLengthReceiverField();
        this. = telegram.substring(startend);
        start = end;
        end += getLengthSequenceNoField();
        this. = Short.parseShort(telegram.substring(startend));
    }

    
Return the number of characters the message header allocates.

Returns:
The header length in characters
    public static final short getHeaderLength() {
                + ;
    }

    
Get the lengthSyncField.

Returns:
the lengthSyncField.
    public static short getLengthSyncField() {
        return ;
    }

    
Get the lengthTelegramLengthField.

Returns:
the lengthTelegramLengthField.
    public static short getLengthTelegramLengthField() {
        return ;
    }

    
Get the lengthReceiverField.

Returns:
the lengthReceiverField.
    public static short getLengthReceiverField() {
        return ;
    }

    
Get the lengthSenderField.

Returns:
the lengthSenderField.
    public static short getLengthSenderField() {
        return ;
    }

    
Get the lengthSequenceNoField.

Returns:
the lengthSequenceNoField.
    public static short getLengthSequenceNoField() {
        return ;
    }

    
Get the sync.

Returns:
the sync.
    public String getSync() {
        return ;
    }

    
Set the sync.

Parameters:
sync The sync to set.
    public void setSync(String sync) {
        this. = sync;
    }

    
Get the messageLength.

Returns:
the messageLength.
    public short getMessageLength() {
        return ;
    }

    
Set the messageLength.

Parameters:
messageLength The messageLength to set.
    public void setMessageLength(short messageLength) {
        this. = messageLength;
    }

    
Get the sender.

Returns:
the sender.
    public String getSender() {
        return ;
    }

    
Set the sender.

Parameters:
sender The sender to set.
    public void setSender(String sender) {
        this. = sender;
    }

    
Get the receiver.

Returns:
the receiver.
    public String getReceiver() {
        return ;
    }

    
Set the receiver.

Parameters:
receiver The receiver to set.
    public void setReceiver(String receiver) {
        this. = receiver;
    }

    
Get the sequenceNo.

Returns:
the sequenceNo.
    public short getSequenceNo() {
        return ;
    }

    
Set the sequenceNo.

Parameters:
sequenceNo The sequenceNo to set.
    public void setSequenceNo(short sequenceNo) {
        this. = sequenceNo;
    }

    
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + ;
        result = prime * result + (( == null) ? 0 : .hashCode());
        result = prime * result + ;
        return result;
    }

    
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        CommonHeader other = (CommonHeaderobj;
        if ( == null) {
            if (other.receiver != null) {
                return false;
            }
        } else if (!.equals(other.receiver)) {
            return false;
        }
        if ( == null) {
            if (other.sender != null) {
                return false;
            }
        } else if (!.equals(other.sender)) {
            return false;
        }
        if ( != other.sequenceNo) {
            return false;
        }
        if ( == null) {
            if (other.sync != null) {
                return false;
            }
        } else if (!.equals(other.sync)) {
            return false;
        }
        if ( != other.messageLength) {
            return false;
        }
        return true;
    }

    
    @Override
    public String toString() {
        return new StringBuilder().append(this.).append(StringUtils.leftPad("" + this."0")).append(this.)
                .append(this.).append(StringUtils.leftPad("" + this."0")).toString();
    }
New to GrepCode? Check out our FAQ X