All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.barchart.udt.LingerUDT Maven / Gradle / Ivy

The newest version!
/**
 * Copyright (C) 2009-2013 Barchart, Inc. 
 *
 * All rights reserved. Licensed under the OSI BSD License.
 *
 * http://www.opensource.org/licenses/bsd-license.php
 */
package com.barchart.udt;

public class LingerUDT extends Number implements Comparable {

	public static final LingerUDT LINGER_ZERO = new LingerUDT(0);

	// measured in seconds
	final int timeout;

	/**
	 * Default constructor. NOTE: linger value is "u_short" on windows and "int"
	 * on linux:
* Windows: * linger Structure on Windows
* Linux: GCC Socket-Level Options
* Therefore select smallest range: 0 <= linger <= 65535
* * @param lingerSeconds * the seconds to linger; "0" means "do not linger" * * @throws IllegalArgumentException * when lingerSeconds is out of range */ public LingerUDT(int lingerSeconds) throws IllegalArgumentException { if (65535 < lingerSeconds) { throw new IllegalArgumentException( "lingerSeconds is out of range: 0 <= linger <= 65535"); } this.timeout = lingerSeconds > 0 ? lingerSeconds : 0; } private static final long serialVersionUID = 3414455799823407217L; @Override public double doubleValue() { return timeout; } /* * (non-Javadoc) * * @see java.lang.Number#floatValue() */ @Override public float floatValue() { return timeout; } @Override public int intValue() { return timeout; } @Override public long longValue() { return timeout; } boolean isLingerOn() { return timeout > 0; } int timeout() { return timeout; } @Override public boolean equals(Object otherLinger) { if (otherLinger instanceof LingerUDT) { LingerUDT other = (LingerUDT) otherLinger; return other.timeout == this.timeout; } return false; } @Override public int hashCode() { return timeout; } @Override public int compareTo(LingerUDT other) { return other.timeout - this.timeout; } @Override public String toString() { return String.valueOf(timeout); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy