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

📄 dataelement.java

📁 java se平台蓝牙开发的插件 ,包括源码 根据readme 生成包很多东西可以自己DIY很实用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		case UUID:			if (!(value instanceof UUID))				throw new IllegalArgumentException();			break;		case U_INT_8:			if (!(value instanceof byte[]) || ((byte[]) value).length != 8)				throw new IllegalArgumentException();			break;		case U_INT_16:		case INT_16:			if (!(value instanceof byte[]) || ((byte[]) value).length != 16)				throw new IllegalArgumentException();			break;		default:			throw new IllegalArgumentException();		}		this.value = value;		this.valueType = valueType;	}	/*	 * Adds a DataElement to this DATALT or DATSEQ DataElement object. The elem	 * will be added at the end of the list. The elem can be of any DataElement	 * type, i.e., URL, NULL, BOOL, UUID, STRING, DATSEQ, DATALT, and the	 * various signed and unsigned integer types. The same object may be added	 * twice. If the object is successfully added the size of the DataElement is	 * increased by one. Parameters: elem - the DataElement object to add	 * Throws: ClassCastException - if the method is invoked on a DataElement	 * whose type is not DATALT or DATSEQ NullPointerException - if elem is null	 */	public void addElement(DataElement elem) {		if (elem == null)			throw new NullPointerException();		switch (valueType) {		case DATALT:		case DATSEQ:			((Vector) value).addElement(elem);			break;		default:			throw new ClassCastException();		}	}	/*	 * Inserts a DataElement at the specified location. This method can be	 * invoked only on a DATALT or DATSEQ DataElement. elem can be of any	 * DataElement type, i.e., URL, NULL, BOOL, UUID, STRING, DATSEQ, DATALT,	 * and the various signed and unsigned integers. The same object may be	 * added twice. If the object is successfully added the size will be	 * increased by one. Each element with an index greater than or equal to the	 * specified index is shifted upward to have an index one greater than the	 * value it had previously. The index must be greater than or equal to 0 and	 * less than or equal to the current size. Therefore, DATALT and DATSEQ are	 * zero-based objects.	 * 	 * Parameters: elem - the DataElement object to add index - the location at	 * which to add the DataElement Throws: ClassCastException - if the method	 * is invoked on an instance of DataElement whose type is not DATALT or	 * DATSEQ IndexOutOfBoundsException - if index is negative or greater than	 * the size of the DATALT or DATSEQ NullPointerException - if elem is null	 */	public void insertElementAt(DataElement elem, int index) {		if (elem == null)			throw new NullPointerException();		switch (valueType) {		case DATALT:		case DATSEQ:			((Vector) value).insertElementAt(elem, index);			break;		default:			throw new ClassCastException();		}	}	/*	 * Returns the number of DataElements that are present in this DATALT or	 * DATSEQ object. It is possible that the number of elements is equal to	 * zero. Returns: the number of elements in this DATALT or DATSEQ Throws:	 * ClassCastException - if this object is not of type DATALT or DATSEQ	 */	public int getSize() {		switch (valueType) {		case DATALT:		case DATSEQ:			return ((Vector) value).size();		default:			throw new ClassCastException();		}	}	/*	 * Removes the first occurrence of the DataElement from this object. elem	 * may be of any type, i.e., URL, NULL, BOOL, UUID, STRING, DATSEQ, DATALT,	 * or the variously sized signed and unsigned integers. Only the first	 * object in the list that is equal to elem will be removed. Other objects,	 * if present, are not removed. Since this class doesn't override the	 * equals() method of the Object class, the remove method compares only the	 * references of objects. If elem is successfully removed the size of this	 * DataElement is decreased by one. Each DataElement in the DATALT or DATSEQ	 * with an index greater than the index of elem is shifted downward to have	 * an index one smaller than the value it had previously. Parameters: elem -	 * the DataElement to be removed Returns: true if the input value was found	 * and removed; else false Throws: ClassCastException - if this object is	 * not of type DATALT or DATSEQ NullPointerException - if elem is null	 */	public boolean removeElement(DataElement elem) {		if (elem == null)			throw new NullPointerException();		switch (valueType) {		case DATALT:		case DATSEQ:			return ((Vector) value).removeElement(elem);		default:			throw new ClassCastException();		}	}	/*	 * Returns the data type of the object this DataElement represents. Returns:	 * the data type of this DataElement object; the legal return values are:	 * URL, NULL, BOOL, UUID, STRING, DATSEQ, DATALT, U_INT_1, U_INT_2, U_INT_4,	 * U_INT_8, U_INT_16, INT_1, INT_2, INT_4, INT_8, or INT_16	 */	public int getDataType() {		return valueType;	}	/*	 * Returns the value of the DataElement if it can be represented as a long.	 * The data type of the object must be U_INT_1, U_INT_2, U_INT_4, INT_1,	 * INT_2, INT_4, or INT_8. Returns: the value of the DataElement as a long	 * Throws: ClassCastException - if the data type of the object is not	 * U_INT_1, U_INT_2, U_INT_4, INT_1, INT_2, INT_4, or INT_8	 */	public long getLong() {		switch (valueType) {		case U_INT_1:		case U_INT_2:		case U_INT_4:		case INT_1:		case INT_2:		case INT_4:		case INT_8:			return ((Long) value).longValue();		default:			throw new ClassCastException();		}	}	/*	 * Returns the value of the DataElement if it is represented as a boolean.	 * Returns: the boolean value of this DataElement object Throws:	 * ClassCastException - if the data type of this object is not of type BOOL	 */	public boolean getBoolean() {		if (valueType == BOOL)			return ((Boolean) value).booleanValue();		else			throw new ClassCastException();	}	/*	 * Returns the value of this DataElement as an Object. This method returns	 * the appropriate Java object for the following data types: URL, UUID,	 * STRING, DATSEQ, DATALT, U_INT_8, U_INT_16, and INT_16. Modifying the	 * returned Object will not change this DataElement. The following are the	 * legal pairs of data type and Java object type being returned. DataElement	 * Data Type Java Data Type URL java.lang.String UUID javax.bluetooth.UUID	 * STRING java.lang.String DATSEQ java.util.Enumeration DATALT	 * java.util.Enumeration U_INT_8 byte[] of length 8 U_INT_16 byte[] of	 * length 16 INT_16 byte[] of length 16	 * 	 * Returns: the value of this object Throws: ClassCastException - if the	 * object is not a URL, UUID, STRING, DATSEQ, DATALT, U_INT_8, U_INT_16, or	 * INT_16	 */	public Object getValue() {		switch (valueType) {		case URL:		case STRING:		case UUID:		case U_INT_8:		case U_INT_16:		case INT_16:			return value;		case DATSEQ:		case DATALT:			return ((Vector) value).elements();		default:			throw new ClassCastException();		}	}	public String toString() {		switch (valueType) {		case U_INT_1:		case U_INT_2:		case U_INT_4:		case INT_1:		case INT_2:		case INT_4:		case INT_8:			return "0x" + Long.toHexString(((Long) value).longValue());		case BOOL:		case URL:		case STRING:		case UUID:			return value.toString();		case U_INT_8:		case U_INT_16:		case INT_16: {			byte[] b = (byte[]) value;			StringBuffer buf = new StringBuffer();			for (int i = 0; i < b.length; i++) {				buf.append(Integer.toHexString(b[i] >> 4 & 0xf));				buf.append(Integer.toHexString(b[i] & 0xf));			}			return buf.toString();		}		case DATSEQ: {			StringBuffer buf = new StringBuffer("DATSEQ {\n");			for (Enumeration e = ((Vector) value).elements(); e					.hasMoreElements();) {				buf.append(e.nextElement());				buf.append("\n");			}			buf.append("}");			return buf.toString();		}		case DATALT: {			StringBuffer buf = new StringBuffer("DATALT {\n");			for (Enumeration e = ((Vector) value).elements(); e					.hasMoreElements();) {				buf.append(e.nextElement());				buf.append("\n");			}			buf.append("}");			return buf.toString();		}		default:			return "???";		}	}}

⌨️ 快捷键说明

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