当前位置: 首页>>代码示例>>Java>>正文


Java DataElement.BOOL属性代码示例

本文整理汇总了Java中javax.bluetooth.DataElement.BOOL属性的典型用法代码示例。如果您正苦于以下问题:Java DataElement.BOOL属性的具体用法?Java DataElement.BOOL怎么用?Java DataElement.BOOL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在javax.bluetooth.DataElement的用法示例。


在下文中一共展示了DataElement.BOOL属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDataSize

public long getDataSize(DataElement data) {
    int type = data.getDataType();
    long size = getPureDataSize(data);
    if ((type == DataElement.NULL) || (type == DataElement.BOOL)
            || (type == DataElement.INT_1) || (type == DataElement.U_INT_1)
            || (type == DataElement.INT_2) || (type == DataElement.U_INT_2)
            || (type == DataElement.INT_4) || (type == DataElement.U_INT_4)
            || (type == DataElement.INT_8) || (type == DataElement.U_INT_8)
            || (type == DataElement.INT_16)
            || (type == DataElement.U_INT_16)
            || (type == DataElement.UUID)) {
        return size + 1;
    } else if ((type == DataElement.DATSEQ)
            || (type == DataElement.DATALT) || (type == DataElement.STRING)
            || (type == DataElement.URL)) {
        if (size <= 0xffL) {
            return size + 2;
        } else if (size <= 0xffffL) {
            return size + 3;
        } else if (size <= 0xffffffffL) {
            return size + 5;
        } else {
            throw new RuntimeException("Data size is too large.");
        }
    } else {
        throw new RuntimeException("Unexpected data type.");
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:28,代码来源:DataElementSerializer.java

示例2: getPureDataSize

public long getPureDataSize(DataElement data) {
    switch (data.getDataType()) {
        case DataElement.NULL:
            return 0;
        case DataElement.BOOL:
        case DataElement.INT_1:
        case DataElement.U_INT_1:
            return 1;
        case DataElement.INT_2:
        case DataElement.U_INT_2:
            return 2;
        case DataElement.INT_4:
        case DataElement.U_INT_4:
            return 4;
        case DataElement.INT_8:
        case DataElement.U_INT_8:
            return 8;
        case DataElement.INT_16:
        case DataElement.U_INT_16:
            return 16;
        case DataElement.DATSEQ:
        case DataElement.DATALT:
            long size = 0;
            Enumeration elements = (Enumeration)data.getValue();
            while (elements.hasMoreElements()) {
                size += getDataSize((DataElement)elements.nextElement());
            }
            return size;
        case DataElement.STRING:
        case DataElement.URL:
            return ((String)data.getValue()).length();
        case DataElement.UUID:
            return 16;
        default:
            throw new RuntimeException("Unknown data type.");
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:37,代码来源:DataElementSerializer.java

示例3: validateConversion

/**
 * Tests for simple types
 */
private void validateConversion(DataElement element) throws IOException {
    int type = element.getDataType();
    switch (type) {
    case DataElement.NULL:
        validateConversion(element, 0, type, 0, null);
        break;
    case DataElement.BOOL:
        validateConversion(element, 0, type, element.getBoolean() ? 1 : 0, null);
        break;
    case DataElement.U_INT_1:
    case DataElement.INT_1:
    case DataElement.U_INT_2:
    case DataElement.INT_2:
    case DataElement.U_INT_4:
    case DataElement.INT_4:
    case DataElement.INT_8:
        validateConversion(element, 0, type, element.getLong(), null);
        break;
    case DataElement.U_INT_8:
    case DataElement.U_INT_16:
    case DataElement.INT_16:
        validateConversion(element, 0, type, 0, (byte[]) element.getValue());
        break;
    case DataElement.UUID:
        validateConversion(element, 0, type, 0, Utils.UUIDToByteArray((UUID) element.getValue()));
        break;
    case DataElement.STRING:
        byte[] bs = Utils.getUTF8Bytes((String) element.getValue());
        validateConversion(element, 0, type, 0, bs);
        break;
    case DataElement.URL:
        byte[] bu = Utils.getASCIIBytes((String) element.getValue());
        validateConversion(element, 0, type, 0, bu);
        break;
    default:
        throw new IllegalArgumentException();
    }
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:41,代码来源:NativeSDPStreamOSXTest.java

示例4: compareDataElements

protected boolean compareDataElements(DataElement first,
        DataElement second) {
    boolean ret = false;
    int valueType = first.getDataType();
    if (ret = (valueType == second.getDataType())) {
        switch (valueType) {
        case DataElement.BOOL:
            ret = first.getBoolean() == second.getBoolean();
            break;
        case DataElement.U_INT_1:
        case DataElement.U_INT_2:
        case DataElement.U_INT_4:
        case DataElement.INT_1:
        case DataElement.INT_2:
        case DataElement.INT_4:
        case DataElement.INT_8:
            ret = first.getLong() == second.getLong();
            break;
        default:
            Object v1 = first.getValue();
            Object v2 = second.getValue();
            if (v1 instanceof Enumeration && v2 instanceof Enumeration) {
                Enumeration e1 = (Enumeration)v1;
                Enumeration e2 = (Enumeration)v2;
                ret = true;
                while (e1.hasMoreElements() &&
                       e2.hasMoreElements() && ret) {
                    ret &= e1.nextElement().equals(e2.nextElement());
                }
                ret = ret &&
                    !(e1.hasMoreElements() ||
                      e2.hasMoreElements());
            } else if (v1 instanceof byte[] && v2 instanceof byte[]) {
                byte[] a1 = (byte[])v1;
                byte[] a2 = (byte[])v2;
                ret = a1.length == a2.length;
                for (int i = a1.length; --i >= 0 && ret; ) {
                    ret &= (a1[i] == a2[i]);
                }
            } else {
                ret = v1.equals(v2);
            }
            break;
        }
    }
    return ret;
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:47,代码来源:BluetoothNotifier.java

示例5: sdpServiceAddAttribute

private void sdpServiceAddAttribute(long handle, char handleType, int attrID, DataElement element) throws ServiceRegistrationException {
    int type = element.getDataType();
    switch (type) {
    case DataElement.NULL:
        sdpServiceAddAttribute(handle, handleType, attrID, type, 0, null);
        break;
    case DataElement.BOOL:
        sdpServiceAddAttribute(handle, handleType, attrID, type, element.getBoolean() ? 1 : 0, null);
        break;
    case DataElement.U_INT_1:
    case DataElement.INT_1:
    case DataElement.U_INT_2:
    case DataElement.INT_2:
    case DataElement.U_INT_4:
    case DataElement.INT_4:
    case DataElement.INT_8:
        sdpServiceAddAttribute(handle, handleType, attrID, type, element.getLong(), null);
        break;
    case DataElement.U_INT_8:
    case DataElement.U_INT_16:
    case DataElement.INT_16:
        sdpServiceAddAttribute(handle, handleType, attrID, type, 0, (byte[]) element.getValue());
        break;
    case DataElement.UUID:
        sdpServiceAddAttribute(handle, handleType, attrID, type, 0, Utils.UUIDToByteArray((UUID) element.getValue()));
        break;
    case DataElement.STRING:
        byte[] bs = Utils.getUTF8Bytes((String) element.getValue());
        sdpServiceAddAttribute(handle, handleType, attrID, type, 0, bs);
        break;
    case DataElement.URL:
        byte[] bu = Utils.getASCIIBytes((String) element.getValue());
        sdpServiceAddAttribute(handle, handleType, attrID, type, 0, bu);
        break;
    case DataElement.DATSEQ:
    case DataElement.DATALT:
        sdpServiceSequenceAttributeStart(handle, handleType, attrID, type);
        for (Enumeration e = (Enumeration) element.getValue(); e.hasMoreElements();) {
            DataElement child = (DataElement) e.nextElement();
            sdpServiceAddAttribute(handle, handleType, -1, child);
        }
        sdpServiceSequenceAttributeEnd(handle, handleType, attrID);
        break;
    default:
        throw new IllegalArgumentException();
    }
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:47,代码来源:BluetoothStackOSX.java

示例6: equals

public static boolean equals(DataElement de1, DataElement de2) {
    if ((de1 == null) || (de2 == null)) {
        return false;
    }
    try {
        if (de1.getDataType() != de2.getDataType()) {
            return false;
        }
        switch (de1.getDataType()) {
        case DataElement.U_INT_1:
        case DataElement.U_INT_2:
        case DataElement.U_INT_4:
        case DataElement.INT_1:
        case DataElement.INT_2:
        case DataElement.INT_4:
        case DataElement.INT_8:
            return (de1.getLong() == de2.getLong());
        case DataElement.URL:
        case DataElement.STRING:
        case DataElement.UUID:
            return de1.getValue().equals(de2.getValue());
        case DataElement.INT_16:
        case DataElement.U_INT_8:
        case DataElement.U_INT_16:
            byte[] byteAray1 = (byte[]) de1.getValue();
            byte[] byteAray2 = (byte[]) de2.getValue();
            if (byteAray1.length != byteAray2.length) {
                return false;
            }
            for (int k = 0; k < byteAray1.length; k++) {
                if (byteAray1[k] != byteAray2[k]) {
                    return false;
                }
            }
            return true;
        case DataElement.NULL:
            return true;
        case DataElement.BOOL:
            return (de1.getBoolean() == de2.getBoolean());
        case DataElement.DATSEQ:
        case DataElement.DATALT:
            Enumeration en1 = (Enumeration) de1.getValue();
            Enumeration en2 = (Enumeration) de2.getValue();
            for (; en1.hasMoreElements() && en2.hasMoreElements();) {
                DataElement d1 = (DataElement) en1.nextElement();
                DataElement d2 = (DataElement) en2.nextElement();
                if (!equals(d1, d2)) {
                    return false;
                }
            }
            if (en1.hasMoreElements() || en2.hasMoreElements()) {
                return false;
            }
            return true;
        default:
            return false;
        }
    } catch (Throwable e) {
        e.printStackTrace();
        return false;
    }
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:62,代码来源:BluetoothStackWIDCOMMSDPInputStreamTest.java

示例7: assertEquals

public static void assertEquals(String message, DataElement de1, DataElement de2) {
	if ((de1 == null) || (de2 == null)) {
		fail(message + "NULL elements");
	}
	assertEquals(message + "Type", de1.getDataType(), de2.getDataType());
	switch (de1.getDataType()) {
	case DataElement.U_INT_1:
	case DataElement.U_INT_2:
	case DataElement.U_INT_4:
	case DataElement.INT_1:
	case DataElement.INT_2:
	case DataElement.INT_4:
	case DataElement.INT_8:
		assertEquals(message + "long", de1.getLong(), de2.getLong());
		return;
	case DataElement.URL:
	case DataElement.STRING:
	case DataElement.UUID:
		assertEquals(message + "value", de1.getValue(), de2.getValue());
		return;
	case DataElement.INT_16:
	case DataElement.U_INT_8:
	case DataElement.U_INT_16:
		byte[] byteAray1 = (byte[]) de1.getValue();
		byte[] byteAray2 = (byte[]) de2.getValue();
		assertEquals(message + "length", byteAray1.length, byteAray2.length);
		for (int k = 0; k < byteAray1.length; k++) {
			assertEquals(message + "byteAray[" + k + "]", byteAray1[k], byteAray2[k]);
		}
		return;
	case DataElement.NULL:
		return;
	case DataElement.BOOL:
		assertEquals(message + "boolean", de1.getBoolean(), de2.getBoolean());
		return;
	case DataElement.DATSEQ:
	case DataElement.DATALT:
		int i = 0;
		Enumeration en1 = (Enumeration) de1.getValue();
		Enumeration en2 = (Enumeration) de2.getValue();
		for (; en1.hasMoreElements() && en2.hasMoreElements();) {
			DataElement d1 = (DataElement) en1.nextElement();
			DataElement d2 = (DataElement) en2.nextElement();
			assertEquals(message + "DataElement[" + i + "]", d1, d2);
			i++;
		}
		if (en1.hasMoreElements() || en2.hasMoreElements()) {
			fail(message + "unknown hasMoreElements");
		}
		return;
	default:
		fail(message + "unknown type");
	}
}
 
开发者ID:empeeoh,项目名称:bluecove-osx,代码行数:54,代码来源:SDPStreamTest.java


注:本文中的javax.bluetooth.DataElement.BOOL属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。