* Renamed ConvertUtil to ConversionUtil

* Added ConversionUtilTest
This commit is contained in:
Trustin Lee 2008-08-25 04:42:18 +00:00
parent c84b1bc139
commit ca249684a6
5 changed files with 102 additions and 19 deletions

View File

@ -29,7 +29,7 @@ import java.util.Map.Entry;
import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.util.ConvertUtil;
import org.jboss.netty.util.ConversionUtil;
public class DefaultServerSocketChannelConfig implements ServerSocketChannelConfig {
@ -52,11 +52,11 @@ public class DefaultServerSocketChannelConfig implements ServerSocketChannelConf
protected boolean setOption(String key, Object value) {
if (key.equals("receiveBufferSize")) {
setReceiveBufferSize(ConvertUtil.toInt(value));
setReceiveBufferSize(ConversionUtil.toInt(value));
} else if (key.equals("reuseAddress")) {
setReuseAddress(ConvertUtil.toBoolean(value));
setReuseAddress(ConversionUtil.toBoolean(value));
} else if (key.equals("backlog")) {
setBacklog(ConvertUtil.toInt(value));
setBacklog(ConversionUtil.toInt(value));
} else {
return false;
}

View File

@ -29,7 +29,7 @@ import java.util.Map.Entry;
import org.jboss.netty.channel.ChannelException;
import org.jboss.netty.channel.ChannelPipelineFactory;
import org.jboss.netty.util.ConvertUtil;
import org.jboss.netty.util.ConversionUtil;
public class DefaultSocketChannelConfig implements SocketChannelConfig {
@ -51,23 +51,23 @@ public class DefaultSocketChannelConfig implements SocketChannelConfig {
protected boolean setOption(String key, Object value) {
if (key.equals("receiveBufferSize")) {
setReceiveBufferSize(ConvertUtil.toInt(value));
setReceiveBufferSize(ConversionUtil.toInt(value));
} else if (key.equals("sendBufferSize")) {
setSendBufferSize(ConvertUtil.toInt(value));
setSendBufferSize(ConversionUtil.toInt(value));
} else if (key.equals("tcpNoDelay")) {
setTcpNoDelay(ConvertUtil.toBoolean(value));
setTcpNoDelay(ConversionUtil.toBoolean(value));
} else if (key.equals("keepAlive")) {
setKeepAlive(ConvertUtil.toBoolean(value));
setKeepAlive(ConversionUtil.toBoolean(value));
} else if (key.equals("reuseAddress")) {
setReuseAddress(ConvertUtil.toBoolean(value));
setReuseAddress(ConversionUtil.toBoolean(value));
} else if (key.equals("soLinger")) {
setSoLinger(ConvertUtil.toInt(value));
setSoLinger(ConversionUtil.toInt(value));
} else if (key.equals("trafficClass")) {
setTrafficClass(ConvertUtil.toInt(value));
setTrafficClass(ConversionUtil.toInt(value));
} else if (key.equals("writeTimeoutMillis")) {
setWriteTimeoutMillis(ConvertUtil.toInt(value));
setWriteTimeoutMillis(ConversionUtil.toInt(value));
} else if (key.equals("connectTimeoutMillis")) {
setConnectTimeoutMillis(ConvertUtil.toInt(value));
setConnectTimeoutMillis(ConversionUtil.toInt(value));
} else if (key.equals("pipelineFactory")) {
setPipelineFactory((ChannelPipelineFactory) value);
} else {

View File

@ -25,7 +25,7 @@ package org.jboss.netty.channel.socket.nio;
import java.net.Socket;
import org.jboss.netty.channel.socket.DefaultSocketChannelConfig;
import org.jboss.netty.util.ConvertUtil;
import org.jboss.netty.util.ConversionUtil;
class DefaultNioSocketChannelConfig extends DefaultSocketChannelConfig
implements NioSocketChannelConfig {
@ -46,9 +46,9 @@ class DefaultNioSocketChannelConfig extends DefaultSocketChannelConfig
}
if (key.equals("readWriteFair")) {
setReadWriteFair(ConvertUtil.toBoolean(value));
setReadWriteFair(ConversionUtil.toBoolean(value));
} else if (key.equals("writeSpinCount")) {
setWriteSpinCount(ConvertUtil.toInt(value));
setWriteSpinCount(ConversionUtil.toInt(value));
} else if (key.equals("receiveBufferSizePredictor")) {
setReceiveBufferSizePredictor((ReceiveBufferSizePredictor) value);
} else {

View File

@ -32,7 +32,7 @@ package org.jboss.netty.util;
* @version $Rev$, $Date$
*
*/
public class ConvertUtil {
public class ConversionUtil {
/**
* Converts the specified object into an integer.
@ -74,7 +74,7 @@ public class ConvertUtil {
}
}
private ConvertUtil() {
private ConversionUtil() {
// Unused
}
}

View File

@ -0,0 +1,83 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser 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.jboss.netty.util;
import static org.junit.Assert.*;
import org.junit.Test;
/**
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public class ConversionUtilTest {
@Test
public void testNumberToInt() {
assertEquals(42, ConversionUtil.toInt(Long.valueOf(42)));
}
@Test
public void testStringToInt() {
assertEquals(42, ConversionUtil.toInt("42"));
}
@Test
public void testBooleanToBoolean() {
assertTrue(ConversionUtil.toBoolean(Boolean.TRUE));
assertFalse(ConversionUtil.toBoolean(Boolean.FALSE));
}
@Test
public void testNumberToBoolean() {
assertTrue(ConversionUtil.toBoolean(Integer.valueOf(42)));
assertFalse(ConversionUtil.toBoolean(Integer.valueOf(0)));
}
@Test
public void testStringToBoolean() {
assertTrue(ConversionUtil.toBoolean("y"));
assertTrue(ConversionUtil.toBoolean("Y"));
assertTrue(ConversionUtil.toBoolean("yes"));
assertTrue(ConversionUtil.toBoolean("YES"));
assertTrue(ConversionUtil.toBoolean("yeah"));
assertTrue(ConversionUtil.toBoolean("YEAH"));
assertTrue(ConversionUtil.toBoolean("t"));
assertTrue(ConversionUtil.toBoolean("T"));
assertTrue(ConversionUtil.toBoolean("true"));
assertTrue(ConversionUtil.toBoolean("TRUE"));
assertTrue(ConversionUtil.toBoolean("42"));
assertFalse(ConversionUtil.toBoolean("n"));
assertFalse(ConversionUtil.toBoolean("no"));
assertFalse(ConversionUtil.toBoolean("NO"));
assertFalse(ConversionUtil.toBoolean("f"));
assertFalse(ConversionUtil.toBoolean("false"));
assertFalse(ConversionUtil.toBoolean("FALSE"));
assertFalse(ConversionUtil.toBoolean("0"));
}
}