本文整理了Java中org.eclipse.smarthome.core.items.Item.getName()
方法的一些代码示例,展示了Item.getName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Item.getName()
方法的具体详情如下:
包路径:org.eclipse.smarthome.core.items.Item
类名称:Item
方法名:getName
[英]returns the name of the item
[中]返回项的名称
代码示例来源:origin: eclipse/smarthome
@Override
public Collection<Item> getItems(String pattern) {
String regex = pattern.replace("?", ".?").replace("*", ".*?");
Collection<Item> matchedItems = new ArrayList<Item>();
for (Item item : getItems()) {
if (item.getName().matches(regex)) {
matchedItems.add(item);
}
}
return matchedItems;
}
代码示例来源:origin: eclipse/smarthome
@Override
protected void internalSend(Command command) {
if (eventPublisher != null) {
for (Item member : members) {
// try to send the command to the bus
eventPublisher.post(ItemEventFactory.createCommandEvent(member.getName(), command));
}
}
}
代码示例来源:origin: eclipse/smarthome
private List<@NonNull String> getMemberNamesRecursively(GroupItem groupItem, Collection<Item> allItems) {
List<@NonNull String> memberNames = new ArrayList<>();
for (Item item : allItems) {
if (item.getGroupNames().contains(groupItem.getName())) {
memberNames.add(item.getName());
if (item instanceof GroupItem) {
memberNames.addAll(getMemberNamesRecursively((GroupItem) item, allItems));
}
}
}
return memberNames;
}
代码示例来源:origin: eclipse/smarthome
@Override
public void removed(Provider<Item> provider, Item element) {
super.removed(provider, element);
for (RegistryHook<Item> registryHook : registryHooks) {
registryHook.afterRemoving(element);
}
if (provider instanceof ManagedItemProvider) {
// remove our metadata for that item
logger.debug("Item {} was removed, trying to clean up corresponding metadata", element.getUID());
metadataRegistry.removeItemMetadata(element.getName());
}
}
代码示例来源:origin: eclipse/smarthome
@Override
public void stateUpdated(Item item, State state) {
State oldState = this.state;
if (function != null && baseItem != null) {
State calculatedState = function.calculate(getStateMembers(getMembers()));
calculatedState = itemStateConverter.convertToAcceptedState(calculatedState, baseItem);
setState(calculatedState);
}
if (!oldState.equals(this.state)) {
sendGroupStateChangedEvent(item.getName(), this.state, oldState);
}
}
代码示例来源:origin: eclipse/smarthome
/**
* Creates an item updated event.
*
* @param item the item
* @param oldItem the old item
* @return the created item updated event
* @throws IllegalArgumentException if item or oldItem is null
*/
public static ItemUpdatedEvent createUpdateEvent(Item item, Item oldItem) {
assertValidArgument(item, "item");
assertValidArgument(oldItem, "oldItem");
String topic = buildTopic(ITEM_UPDATED_EVENT_TOPIC, item.getName());
ItemDTO itemDTO = map(item);
ItemDTO oldItemDTO = map(oldItem);
List<ItemDTO> itemDTOs = new LinkedList<ItemDTO>();
itemDTOs.add(itemDTO);
itemDTOs.add(oldItemDTO);
String payload = serializePayload(itemDTOs);
return new ItemUpdatedEvent(topic, payload, itemDTO, oldItemDTO);
}
代码示例来源:origin: eclipse/smarthome
/**
* Creates an item removed event.
*
* @param item the item
* @return the created item removed event
* @throws IllegalArgumentException if item is null
*/
public static ItemRemovedEvent createRemovedEvent(Item item) {
assertValidArgument(item, "item");
String topic = buildTopic(ITEM_REMOVED_EVENT_TOPIC, item.getName());
ItemDTO itemDTO = map(item);
String payload = serializePayload(itemDTO);
return new ItemRemovedEvent(topic, payload, itemDTO);
}
代码示例来源:origin: eclipse/smarthome
/**
* Creates an item added event.
*
* @param item the item
* @return the created item added event
* @throws IllegalArgumentException if item is null
*/
public static ItemAddedEvent createAddedEvent(Item item) {
assertValidArgument(item, "item");
String topic = buildTopic(ITEM_ADDED_EVENT_TOPIC, item.getName());
ItemDTO itemDTO = map(item);
String payload = serializePayload(itemDTO);
return new ItemAddedEvent(topic, payload, itemDTO);
}
代码示例来源:origin: eclipse/smarthome
if (convertedState != null) {
logger.debug("Converting {} '{}' to {} '{}' for item '{}'", state.getClass().getSimpleName(), state,
convertedState.getClass().getSimpleName(), convertedState, item.getName());
return convertedState;
代码示例来源:origin: eclipse/smarthome
/**
* An item should be initialized, which means that the event publisher is
* injected and its implementation is notified that it has just been
* created, so it can perform any task it needs to do after its creation.
*
* @param item the item to initialize
* @throws IllegalArgumentException if the item has no valid name
*/
private void initializeItem(Item item) throws IllegalArgumentException {
ItemUtil.assertValidItemName(item.getName());
injectServices(item);
if (item instanceof GroupItem) {
// fill group with its members
addMembersToGroupItem((GroupItem) item);
}
// add the item to all relevant groups
addToGroupItems(item, item.getGroupNames());
}
代码示例来源:origin: eclipse/smarthome
/**
* Removes an item and it´s member if recursive flag is set to true.
*
* @param itemName item name to remove
* @param recursive if set to true all members of the item will be removed, too.
* @return removed item or null if no item with that name exists
*/
public Item remove(String itemName, boolean recursive) {
Item item = get(itemName);
if (recursive && item instanceof GroupItem) {
for (String member : getMemberNamesRecursively((GroupItem) item, getAll())) {
this.remove(member);
}
}
if (item != null) {
this.remove(item.getName());
return item;
} else {
return null;
}
}
代码示例来源:origin: eclipse/smarthome
public ItemBuilderImpl(Set<ItemFactory> itemFactories, Item item) {
this.itemFactories = itemFactories;
this.itemType = item.getType();
this.name = item.getName();
this.category = item.getCategory();
this.groups = item.getGroupNames();
this.label = item.getLabel();
this.tags = item.getTags();
if (item instanceof GroupItem) {
this.baseItem = ((GroupItem) item).getBaseItem();
this.groupFunction = ((GroupItem) item).getFunction();
}
}
代码示例来源:origin: eclipse/smarthome
private static void fillProperties(ItemDTO itemDTO, Item item) {
if (item instanceof GroupItem) {
GroupItem groupItem = (GroupItem) item;
GroupItemDTO groupItemDTO = (GroupItemDTO) itemDTO;
if (groupItem.getBaseItem() != null) {
groupItemDTO.groupType = groupItem.getBaseItem().getType();
groupItemDTO.function = mapFunction(groupItem.getFunction());
}
}
itemDTO.name = item.getName();
itemDTO.type = item.getType();
itemDTO.label = item.getLabel();
itemDTO.tags = item.getTags();
itemDTO.category = item.getCategory();
itemDTO.groupNames = item.getGroupNames();
}
代码示例来源:origin: org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.module.script.defaultscope
@Override
public Set<String> keySet() {
Set<String> keys = new HashSet<>();
for (Item item : itemRegistry.getAll()) {
keys.add(item.getName());
}
return keys;
}
代码示例来源:origin: openhab/openhab-core
@SuppressWarnings("null")
@Override
public void removed(Item item) {
Metadata removedMd = semantics.remove(item.getName());
if (removedMd != null) {
notifyListenersAboutRemovedElement(removedMd);
}
}
代码示例来源:origin: org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.module.script.defaultscope
/**
* Sends a command for a specified item to the event bus.
*
* @param item the item to send the command to
* @param commandString the command to send
*/
public Object sendCommand(Item item, String commandString) {
if (item != null) {
return sendCommand(item.getName(), commandString);
} else {
return null;
}
}
代码示例来源:origin: org.eclipse.smarthome.automation/org.eclipse.smarthome.automation.module.script.defaultscope
/**
* Posts a status update for a specified item to the event bus.
*
* @param item the item to send the status update for
* @param state the new state of the item as a number
*/
public Object postUpdate(Item item, Number state) {
if (item != null && state != null) {
return postUpdate(item.getName(), state.toString());
} else {
return null;
}
}
代码示例来源:origin: openhab/openhab-core
private void postUpdate(Item item, State newState, String origin) {
boolean isAccepted = isAcceptedState(newState, item);
if (isAccepted) {
eventPublisher.post(ItemEventFactory.createStateEvent(item.getName(), newState, origin));
} else {
logger.debug("Received update of a not accepted type ({}) for item {}", newState.getClass().getSimpleName(),
item.getName());
}
}
代码示例来源:origin: openhab/openhab-core
/**
* Sends a command for a specified item to the event bus.
*
* @param item the item to send the command to
* @param command the command to send
*/
public Object sendCommand(Item item, Command command) {
if (eventPublisher != null && item != null) {
eventPublisher.post(ItemEventFactory.createCommandEvent(item.getName(), command));
}
return null;
}
代码示例来源:origin: openhab/openhab-core
private List<@NonNull String> getMemberNamesRecursively(GroupItem groupItem, Collection<Item> allItems) {
List<@NonNull String> memberNames = new ArrayList<>();
for (Item item : allItems) {
if (item.getGroupNames().contains(groupItem.getName())) {
memberNames.add(item.getName());
if (item instanceof GroupItem) {
memberNames.addAll(getMemberNamesRecursively((GroupItem) item, allItems));
}
}
}
return memberNames;
}
内容来源于网络,如有侵权,请联系作者删除!