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

📄 dataelement.java

📁 java se平台蓝牙开发的插件 ,包括源码 根据readme 生成包很多东西可以自己DIY很实用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* Copyright 2004 Intel Corporation This file is part of Blue Cove. Blue Cove 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. Blue Cove 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 Blue Cove; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package javax.bluetooth;import java.util.Enumeration;import java.util.Vector;public class DataElement {	/*	 * Defines data of type NULL. The value for data type DataElement.NULL is	 * implicit, i.e., there is no representation of it. Accordingly there is no	 * method to retrieve it, and attempts to retrieve the value will throw an	 * exception. The value of NULL is 0x00 (0).	 */	public static final int NULL = 0;	/*	 * Defines an unsigned integer of size one byte. The value of the constant	 * U_INT_1 is 0x08 (8).	 */	public static final int U_INT_1 = 8;	/*	 * Defines an unsigned integer of size two bytes. The value of the constant	 * U_INT_2 is 0x09 (9).	 */	public static final int U_INT_2 = 9;	/*	 * Defines an unsigned integer of size four bytes. The value of the constant	 * U_INT_4 is 0x0A (10).	 */	public static final int U_INT_4 = 10;	/*	 * Defines an unsigned integer of size eight bytes. The value of the	 * constant U_INT_8 is 0x0B (11).	 */	public static final int U_INT_8 = 11;	/*	 * Defines an unsigned integer of size sixteen bytes. The value of the	 * constant U_INT_16 is 0x0C (12).	 */	public static final int U_INT_16 = 12;	/*	 * Defines a signed integer of size one byte. The value of the constant	 * INT_1 is 0x10 (16).	 */	public static final int INT_1 = 16;	/*	 * Defines a signed integer of size two bytes. The value of the constant	 * INT_2 is 0x11 (17).	 */	public static final int INT_2 = 17;	/*	 * Defines a signed integer of size four bytes. The value of the constant	 * INT_4 is 0x12 (18).	 */	public static final int INT_4 = 18;	/*	 * Defines a signed integer of size eight bytes. The value of the constant	 * INT_8 is 0x13 (19).	 */	public static final int INT_8 = 19;	/*	 * Defines a signed integer of size sixteen bytes. The value of the constant	 * INT_16 is 0x14 (20).	 */	public static final int INT_16 = 20;	/*	 * Defines data of type URL. The value of the constant URL is 0x40 (64).	 */	public static final int URL = 64;	/*	 * Defines data of type UUID. The value of the constant UUID is 0x18 (24).	 */	public static final int UUID = 24;	/*	 * Defines data of type BOOL. The value of the constant BOOL is 0x28 (40).	 */	public static final int BOOL = 40;	/*	 * Defines data of type STRING. The value of the constant STRING is 0x20	 * (32).	 */	public static final int STRING = 32;	/*	 * Defines data of type DATSEQ. The service attribute value whose data has	 * this type must consider all the elements of the list, i.e. the value is	 * the whole set and not a subset. The elements of the set can be of any	 * type defined in this class, including DATSEQ. The value of the constant	 * DATSEQ is 0x30 (48).	 */	public static final int DATSEQ = 48;	/*	 * Defines data of type DATALT. The service attribute value whose data has	 * this type must consider only one of the elements of the set, i.e., the	 * value is the not the whole set but only one element of the set. The user	 * is free to choose any one element. The elements of the set can be of any	 * type defined in this class, including DATALT. The value of the constant	 * DATALT is 0x38 (56).	 */	public static final int DATALT = 56;	private Object value;	private int valueType;	/*	 * Creates a DataElement of type NULL, DATALT, or DATSEQ. Parameters:	 * valueType - the type of DataElement to create: NULL, DATALT, or DATSEQ	 * Throws: IllegalArgumentException - if valueType is not NULL, DATALT, or	 * DATSEQ See Also: NULL, DATALT, DATSEQ	 */	public DataElement(int valueType) {		switch (valueType) {		case NULL:			value = null;			break;		case DATALT:		case DATSEQ:			value = new Vector();			break;		default:			throw new IllegalArgumentException();		}		this.valueType = valueType;	}	/*	 * Creates a DataElement whose data type is BOOL and whose value is equal to	 * bool Parameters: bool - the value of the DataElement of type BOOL. See	 * Also: BOOL	 */	public DataElement(boolean bool) {		value = new Boolean(bool);		valueType = BOOL;	}	/*	 * Creates a DataElement that encapsulates an integer value of size U_INT_1,	 * U_INT_2, U_INT_4, INT_1, INT_2, INT_4, and INT_8. The legal values for	 * the valueType and the corresponding attribute values are: Value Type	 * Value Range U_INT_1 [0, 2^8-1] U_INT_2 [0, 2^16-1] U_INT_4 [0, 2^32-1]	 * INT_1 [-2^7, 2^7-1] INT_2 [-2^15, 2^15-1] INT_4 [-2^31, 2^31-1] INT_8	 * [-2^63, 2^63-1] All other pairings are illegal and will cause an	 * IllegalArgumentException to be thrown. Parameters: valueType - the data	 * type of the object that is being created; must be one of the following:	 * U_INT_1, U_INT_2, U_INT_4, INT_1, INT_2, INT_4, or INT_8 value - the	 * value of the object being created; must be in the range specified for the	 * given valueType Throws: IllegalArgumentException - if the valueType is	 * not valid or the value for the given legal valueType is outside the valid	 * range See Also: U_INT_1, U_INT_2, U_INT_4, INT_1, INT_2, INT_4, INT_8	 */	public DataElement(int valueType, long value) {		switch (valueType) {		case U_INT_1:			if (value < 0 || value > 0xff)				throw new IllegalArgumentException();			break;		case U_INT_2:			if (value < 0 || value > 0xffff)				throw new IllegalArgumentException();			break;		case U_INT_4:			if (value < 0 || value > 0xffffffffl)				throw new IllegalArgumentException();			break;		case INT_1:			if (value < -0x80 || value > 0x7f)				throw new IllegalArgumentException();			break;		case INT_2:			if (value < -0x8000 || value > 0x7fff)				throw new IllegalArgumentException();			break;		case INT_4:			if (value < -0x80000000 || value > 0x7fffffff)				throw new IllegalArgumentException();			break;		case INT_8:			break;		default:			throw new IllegalArgumentException();		}		this.value = new Long(value);		this.valueType = valueType;	}	/*	 * Creates a DataElement whose data type is given by valueType and whose	 * value is specified by the argument value. The legal values for the	 * valueType and the corresponding attribute values are: Value Type Java	 * Type / Value Range URL java.lang.String UUID javax.bluetooth.UUID STRING	 * java.lang.String INT_16 [-2127, 2127-1] as a byte array whose length must	 * be 16 U_INT_8 [0, 264-1] as a byte array whose length must be 8 U_INT_16	 * [0, 2128-1] as a byte array whose length must be 16 All other pairings	 * are illegal and would cause an IllegalArgumentException exception.	 * Parameters: valueType - the data type of the object that is being	 * created; must be one of the following: URL, UUID, STRING, INT_16,	 * U_INT_8, or U_INT_16 value - the value for the DataElement being created	 * of type valueType Throws: IllegalArgumentException - if the value is not	 * of the valueType type or is not in the range specified or is null See	 * Also: URL, UUID, STRING, U_INT_8, INT_16, U_INT_16	 */	public DataElement(int valueType, Object value) {		if (value == null)			throw new IllegalArgumentException();		switch (valueType) {		case URL:		case STRING:			if (!(value instanceof String))				throw new IllegalArgumentException();			break;

⌨️ 快捷键说明

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