use of java.util.Map.Entry in project UltimateAndroid by cymcsg.
the class AlbumHelper method buildImagesBucketList.
/**
* 得到图片集
*/
void buildImagesBucketList() {
long startTime = System.currentTimeMillis();
// 构造缩略图索引
getThumbnail();
// 构造相册索引
String[] columns = new String[] { Media._ID, Media.BUCKET_ID, Media.PICASA_ID, Media.DATA, Media.DISPLAY_NAME, Media.TITLE, Media.SIZE, Media.BUCKET_DISPLAY_NAME };
// 得到一个游标
Cursor cur = cr.query(Media.EXTERNAL_CONTENT_URI, columns, null, null, null);
if (cur.moveToFirst()) {
// 获取指定列的索引
int photoIDIndex = cur.getColumnIndexOrThrow(Media._ID);
int photoPathIndex = cur.getColumnIndexOrThrow(Media.DATA);
int photoNameIndex = cur.getColumnIndexOrThrow(Media.DISPLAY_NAME);
int photoTitleIndex = cur.getColumnIndexOrThrow(Media.TITLE);
int photoSizeIndex = cur.getColumnIndexOrThrow(Media.SIZE);
int bucketDisplayNameIndex = cur.getColumnIndexOrThrow(Media.BUCKET_DISPLAY_NAME);
int bucketIdIndex = cur.getColumnIndexOrThrow(Media.BUCKET_ID);
int picasaIdIndex = cur.getColumnIndexOrThrow(Media.PICASA_ID);
// 获取图片总数
int totalNum = cur.getCount();
do {
String _id = cur.getString(photoIDIndex);
String name = cur.getString(photoNameIndex);
String path = cur.getString(photoPathIndex);
String title = cur.getString(photoTitleIndex);
String size = cur.getString(photoSizeIndex);
String bucketName = cur.getString(bucketDisplayNameIndex);
String bucketId = cur.getString(bucketIdIndex);
String picasaId = cur.getString(picasaIdIndex);
Log.i(TAG, _id + ", bucketId: " + bucketId + ", picasaId: " + picasaId + " name:" + name + " path:" + path + " title: " + title + " size: " + size + " bucket: " + bucketName + "---");
ImageBucket bucket = bucketList.get(bucketId);
if (bucket == null) {
bucket = new ImageBucket();
bucketList.put(bucketId, bucket);
bucket.imageList = new ArrayList<ImageItem>();
bucket.bucketName = bucketName;
}
bucket.count++;
ImageItem imageItem = new ImageItem();
imageItem.imageId = _id;
imageItem.imagePath = path;
imageItem.thumbnailPath = thumbnailList.get(_id);
bucket.imageList.add(imageItem);
} while (cur.moveToNext());
}
Iterator<Entry<String, ImageBucket>> itr = bucketList.entrySet().iterator();
while (itr.hasNext()) {
Entry<String, ImageBucket> entry = (Entry<String, ImageBucket>) itr.next();
ImageBucket bucket = entry.getValue();
Log.d(TAG, entry.getKey() + ", " + bucket.bucketName + ", " + bucket.count + " ---------- ");
for (int i = 0; i < bucket.imageList.size(); ++i) {
ImageItem image = bucket.imageList.get(i);
Log.d(TAG, "----- " + image.imageId + ", " + image.imagePath + ", " + image.thumbnailPath);
}
}
hasBuildImagesBucketList = true;
long endTime = System.currentTimeMillis();
Log.d(TAG, "use time: " + (endTime - startTime) + " ms");
}
use of java.util.Map.Entry in project openhab1-addons by openhab.
the class PLCLogoBinding method updated.
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
Boolean configured = false;
if (config != null) {
String refreshIntervalString = Objects.toString(config.get("refresh"), null);
if (StringUtils.isNotBlank(refreshIntervalString)) {
refreshInterval = Long.parseLong(refreshIntervalString);
}
if (controllers == null) {
controllers = new HashMap<String, PLCLogoConfig>();
}
Enumeration<String> keys = config.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
// don't want to process here ...
if ("service.pid".equals(key)) {
continue;
}
Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
if (!matcher.matches()) {
continue;
}
matcher.reset();
matcher.find();
String controllerName = matcher.group(1);
PLCLogoConfig deviceConfig = controllers.get(controllerName);
if (deviceConfig == null) {
deviceConfig = new PLCLogoConfig();
controllers.put(controllerName, deviceConfig);
logger.info("Create new config for {}", controllerName);
}
if (matcher.group(2).equals("host")) {
String ip = config.get(key).toString();
deviceConfig.setIP(ip);
logger.info("Set host of {}: {}", controllerName, ip);
configured = true;
}
if (matcher.group(2).equals("remoteTSAP")) {
String tsap = config.get(key).toString();
deviceConfig.setRemoteTSAP(Integer.decode(tsap));
logger.info("Set remote TSAP for {}: {}", controllerName, tsap);
}
if (matcher.group(2).equals("localTSAP")) {
String tsap = config.get(key).toString();
deviceConfig.setLocalTSAP(Integer.decode(tsap));
logger.info("Set local TSAP for {}: {}", controllerName, tsap);
}
if (matcher.group(2).equals("model")) {
PLCLogoModel model = null;
String modelName = config.get(key).toString();
if (modelName.equalsIgnoreCase("0BA7")) {
model = PLCLogoModel.LOGO_MODEL_0BA7;
} else if (modelName.equalsIgnoreCase("0BA8")) {
model = PLCLogoModel.LOGO_MODEL_0BA8;
} else {
logger.info("Found unknown model for {}: {}", controllerName, modelName);
}
if (model != null) {
deviceConfig.setModel(model);
logger.info("Set model for {}: {}", controllerName, modelName);
}
}
}
// while
Iterator<Entry<String, PLCLogoConfig>> entries = controllers.entrySet().iterator();
while (entries.hasNext()) {
Entry<String, PLCLogoConfig> thisEntry = entries.next();
String controllerName = thisEntry.getKey();
PLCLogoConfig deviceConfig = thisEntry.getValue();
S7Client LogoS7Client = deviceConfig.getS7Client();
if (LogoS7Client == null) {
LogoS7Client = new Moka7.S7Client();
} else {
LogoS7Client.Disconnect();
}
LogoS7Client.SetConnectionParams(deviceConfig.getlogoIP(), deviceConfig.getlocalTSAP(), deviceConfig.getremoteTSAP());
logger.info("About to connect to {}", controllerName);
if ((LogoS7Client.Connect() == 0) && LogoS7Client.Connected) {
logger.info("Connected to PLC LOGO! device {}", controllerName);
} else {
logger.error("Could not connect to PLC LOGO! device {} : {}", controllerName, S7Client.ErrorText(LogoS7Client.LastError));
throw new ConfigurationException("Could not connect to PLC LOGO! device ", controllerName + " " + deviceConfig.getlogoIP());
}
deviceConfig.setS7Client(LogoS7Client);
}
setProperlyConfigured(configured);
} else {
logger.info("No configuration for PLCLogoBinding");
}
}
use of java.util.Map.Entry in project openhab1-addons by openhab.
the class PLCLogoBinding method deactivate.
@Override
public void deactivate() {
for (PLCLogoBindingProvider provider : providers) {
provider.removeBindingChangeListener(this);
}
providers.clear();
Iterator<Entry<String, PLCLogoConfig>> entries = controllers.entrySet().iterator();
while (entries.hasNext()) {
Entry<String, PLCLogoConfig> thisEntry = entries.next();
PLCLogoConfig logoConfig = thisEntry.getValue();
S7Client LogoS7Client = logoConfig.getS7Client();
if (LogoS7Client != null) {
LogoS7Client.Disconnect();
}
}
controllers.clear();
}
use of java.util.Map.Entry in project openhab1-addons by openhab.
the class PLCLogoBinding method execute.
@Override
protected void execute() {
if (!bindingsExist()) {
logger.debug("There is no existing plclogo binding configuration => refresh cycle aborted!");
return;
}
Iterator<Entry<String, PLCLogoConfig>> entries = controllers.entrySet().iterator();
while (entries.hasNext()) {
Entry<String, PLCLogoConfig> thisEntry = entries.next();
String controller = thisEntry.getKey();
PLCLogoConfig logoConfig = thisEntry.getValue();
S7Client LogoS7Client = logoConfig.getS7Client();
if (LogoS7Client == null) {
logger.debug("No S7client for {} found", controller);
} else {
lock.lock();
int result = ReadLogoDBArea(LogoS7Client, logoConfig.getMemorySize());
lock.unlock();
if (result != 0) {
logger.warn("Failed to read memory: {}. Reconnecting...", S7Client.ErrorText(result));
ReconnectLogo(LogoS7Client);
return;
}
// Now have the LOGO! memory (note: not suitable for S7) - more efficient than multiple reads (test
// shows <14mS to read all)
// iterate through bindings to see what has changed - this approach assumes a small number (< 100)of
// bindings
// otherwise might see what has changed in memory and map to binding
}
for (PLCLogoBindingProvider provider : providers) {
for (String itemName : provider.getItemNames()) {
PLCLogoBindingConfig config = provider.getBindingConfig(itemName);
if (config.getController().equals(controller)) {
// it is for our currently selected controller
PLCLogoMemoryConfig rd = config.getRD();
int address = -1;
try {
address = rd.getAddress(logoConfig.getModel());
} catch (BindingConfigParseException exception) {
logger.error("Invalid address for block {} on {}", rd.getBlockName(), controller);
continue;
}
int currentValue;
if (rd.isDigital()) {
int bit = -1;
try {
bit = rd.getBit(logoConfig.getModel());
} catch (BindingConfigParseException exception) {
logger.error("Invalid bit for block {} on {}", rd.getBlockName(), controller);
continue;
}
currentValue = S7.GetBitAt(data, address, bit) ? 1 : 0;
} else {
/*
* After the data transfer from a LOGO! Base Module to LOGO!Soft Comfort,
* you can view only analog values within the range of -32768 to 32767 on LOGO!Soft Comfort.
* If an analog value exceeds the value range,
* then only the nearest upper limit (32767) or lower limit (-32768) can be displayed.
*/
currentValue = S7.GetShortAt(data, address);
}
if (config.isSet()) {
if (currentValue == config.getLastValue()) {
continue;
}
int delta = Math.abs(config.getLastValue() - currentValue);
if (!rd.isDigital() && (delta < config.getAnalogDelta())) {
continue;
}
}
boolean isValid = false;
Item item = provider.getItem(itemName);
switch(rd.getKind()) {
case I:
case NI:
{
isValid = item instanceof ContactItem;
break;
}
case Q:
case NQ:
{
isValid = item instanceof SwitchItem;
break;
}
case M:
case VB:
case VW:
{
isValid = item instanceof ContactItem || item instanceof SwitchItem;
break;
}
default:
{
break;
}
}
if (item instanceof NumberItem || isValid) {
eventPublisher.postUpdate(itemName, createState(item, currentValue));
config.setLastValue(currentValue);
} else {
String block = rd.getBlockName();
logger.warn("Block {} is incompatible with item {} on {}", block, item.getName(), controller);
}
}
}
}
}
}
use of java.util.Map.Entry in project openhab1-addons by openhab.
the class InsteonPLMActiveBinding method removeFeatureListener.
/**
* Finds the device that a particular item was bound to, and removes the
* item as a listener
*
* @param aItem The item (FeatureListener) to remove from all devices
*/
private void removeFeatureListener(String aItem) {
for (Iterator<Entry<InsteonAddress, InsteonDevice>> it = m_devices.entrySet().iterator(); it.hasNext(); ) {
InsteonDevice dev = it.next().getValue();
boolean removedListener = dev.removeFeatureListener(aItem);
if (removedListener) {
logger.trace("removed feature listener {} from dev {}", aItem, dev);
}
if (!dev.hasAnyListeners()) {
Poller.s_instance().stopPolling(dev);
it.remove();
logger.trace("removing unreferenced {}", dev);
if (m_devices.isEmpty()) {
logger.debug("all devices removed!", dev);
}
}
}
}
Aggregations