⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 domain.java

📁 用java开发的一些实用的短信通信模块其中包含MD5加密、http发送等信息
💻 JAVA
字号:
package lib.commons.net;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import lib.commons.Utils;

public class Domain {
	private String _address;

	private int _port;

	public Domain(String address, int port) {
		if (Utils.StringIsNullOrEmpty(address)) {
			throw new IllegalArgumentException("address is null or empty");
		} else {
			this._address = address;
		}
		if (port < 1)
			throw new IllegalArgumentException("port is less than 1");
		else
			this._port = port;
	}

	public String getAddress() {
		return _address;
	}

	public int getPort() {
		return _port;
	}

	public String toString(Protocol protocol) {
		StringBuffer buf = new StringBuffer();
		buf.append(_address);
		if (null == protocol || _port != protocol.getDefaultPort())
			buf.append(':').append(_port);
		return buf.toString();
	}

	public String toString() {
		return toString(null);
	}

	public int hashCode() {
		return this.toString().hashCode();
	}

	public boolean equals(Object obj) {
		boolean equals = false;
		if (null != obj && Domain.class.isInstance(obj)) {
			equals = (this.hashCode() == obj.hashCode());
		}
		return equals;
	}

	public static final String Domain_Pattern_String = "[\\w\\.\\-\\_]+:?\\d*";

	public static final Pattern Domain_Pattern = Pattern
			.compile(Domain_Pattern_String);

	public final static Domain parseDomain(String domainString) {
		return parseDomain(domainString, Protocol.HTTP);
	}

	public final static Domain parseDomain(String domainString,
			Protocol protocol) {
		Domain domain = null;
		if (!Utils.StringIsNullOrEmpty(domainString)) {
			Matcher matcher = Domain_Pattern.matcher(domainString);
			String address = null;
			int port = 0;
			if (matcher.matches()) {
				int splitPos = domainString.indexOf(':');
				if (splitPos > 0) {
					address = domainString.substring(0, splitPos);
					if (splitPos + 1 < domainString.length()) {
						String portStr = domainString.substring(splitPos + 1);
						if (null != portStr && portStr.length() > 0)
							port = Integer.parseInt(portStr);
					}
				} else if (null != protocol) {
					address = domainString;
					port = protocol.getDefaultPort();
				}
			} else {
				throw new IllegalArgumentException(
						"can't parse domain expression");
			}
			domain = new Domain(address, port);
		}
		return domain;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -