📄 spotinfo.java
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. * * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. * * Use is subject to license terms. * * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. * * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. * * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. * * L'utilisation est soumise aux termes du contrat de licence. * * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld.usb.spotselector;import java.io.IOException;/** * The SpotInfo class represents the type, serial port and ID of a single Spot * * @author Christian P黨ringer * */public class SpotInfo { public final static int TYPE_BASESTATION = 1; public final static int TYPE_UNKNOWN = 0; public final static int TYPE_NONBASESTATION = 2; public final static int TYPE_UNKNOWN_AND_PORT_IN_USE = 3; public String ID; public final String serialPort; public int type = TYPE_UNKNOWN; public SpotInfo(String idAndSerialPort) throws IOException { String[] idAndSerialPortArray = idAndSerialPort.split("[\\(\\)]"); if (idAndSerialPortArray.length >= 2) { this.serialPort = idAndSerialPortArray[0].trim(); this.ID = idAndSerialPortArray[1].trim(); } else if (idAndSerialPortArray.length == 1) { this.serialPort = idAndSerialPortArray[0].trim(); this.ID = ""; } else { throw new IOException("Not a valid SpotInfo String: " + idAndSerialPort + "\n\tExpected \"<SerialPort> (<ID>)\""); } if (this.serialPort.trim().equals("")) { throw new IOException( "Not a valid SpotInfo String (serialPort is empty): " + idAndSerialPort + "\n\tExpected \"<SerialPort> (<ID>)\""); } } public SpotInfo(String serialPort, String id) { this.ID = id; this.serialPort = serialPort; } public String getTypeAsString() { if (type == TYPE_UNKNOWN) return "Sun SPOT device"; if (type == TYPE_BASESTATION) return "Sun SPOT basestation"; if (type == TYPE_NONBASESTATION) return "Sun SPOT non-basestation device"; if (type == TYPE_UNKNOWN_AND_PORT_IN_USE) return "Sun SPOT device in use by other application"; return "invalid type"; } public void setType(int type) throws IllegalArgumentException { if ((type == TYPE_BASESTATION) || (type == TYPE_NONBASESTATION) || (type == TYPE_UNKNOWN) || (type == TYPE_UNKNOWN_AND_PORT_IN_USE)) this.type = type; else throw new IllegalArgumentException( "type must be either TYPE_UNKNOWN, TYPE_BASESTATION, TYPE_NONBASESTATION" + ", or TYPE_UNKNOWN_AND_PORT_IN_USE"); } public String getIDString() { if (ID.length() != 16) return "Invalid ID: " + ID; String idString = ""; for (int i = 0; i < 3; i++) idString += ID.substring(i * 4, (i + 1) * 4) + "."; idString += ID.substring(4 * 3, (3 + 1) * 4); return idString; } public String toString() { String spotInfoString = serialPort; if (!ID.equals("")) spotInfoString += " (" + getIDString() + ")"; if ((type != TYPE_UNKNOWN)) spotInfoString += " [" + getTypeAsString() + "]"; return spotInfoString; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -