org.eclipse.smarthome.core.items.Item.getGroupNames()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(76)

本文整理了Java中org.eclipse.smarthome.core.items.Item.getGroupNames()方法的一些代码示例,展示了Item.getGroupNames()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Item.getGroupNames()方法的具体详情如下:
包路径:org.eclipse.smarthome.core.items.Item
类名称:Item
方法名:getGroupNames

Item.getGroupNames介绍

[英]Returns a list of the names of the groups this item belongs to.
[中]返回此项所属组的名称列表。

代码示例

代码示例来源:origin: eclipse/smarthome

@Override
protected void onUpdateElement(Item oldItem, Item item) {
  // don't use #initialize and retain order of items in groups:
  List<String> oldNames = oldItem.getGroupNames();
  List<String> newNames = item.getGroupNames();
  List<String> commonNames = oldNames.stream().filter(name -> newNames.contains(name)).collect(toList());
  removeFromGroupItems(oldItem, oldNames.stream().filter(name -> !commonNames.contains(name)).collect(toList()));
  replaceInGroupItems(oldItem, item, commonNames);
  addToGroupItems(item, newNames.stream().filter(name -> !commonNames.contains(name)).collect(toList()));
  if (item instanceof GroupItem) {
    addMembersToGroupItem((GroupItem) item);
  }
  injectServices(item);
}

代码示例来源:origin: eclipse/smarthome

@Override
protected void onRemoveElement(Item element) {
  if (element instanceof GenericItem) {
    ((GenericItem) element).dispose();
  }
  removeFromGroupItems(element, element.getGroupNames());
}

代码示例来源: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

private void addMembersToGroupItem(GroupItem groupItem) {
  for (Item i : getItems()) {
    if (i.getGroupNames().contains(groupItem.getName())) {
      groupItem.addMember(i);
    }
  }
}

代码示例来源:origin: eclipse/smarthome

@Override
protected PersistedItem toPersistableElement(Item item) {
  PersistedItem persistedItem = new PersistedItem(
      item instanceof GroupItem ? ITEM_TYPE_GROUP : toItemFactoryName(item));
  if (item instanceof GroupItem) {
    GroupItem groupItem = (GroupItem) item;
    String baseItemType = null;
    Item baseItem = groupItem.getBaseItem();
    if (baseItem != null) {
      baseItemType = toItemFactoryName(baseItem);
    }
    persistedItem.baseItemType = baseItemType;
    addFunctionToPersisedItem(persistedItem, groupItem);
  }
  persistedItem.label = item.getLabel();
  persistedItem.groupNames = new ArrayList<>(item.getGroupNames());
  persistedItem.tags = new HashSet<>(item.getTags());
  persistedItem.category = item.getCategory();
  return persistedItem;
}

代码示例来源: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

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: openhab/openhab-core

@Override
protected void onUpdateElement(Item oldItem, Item item) {
  // don't use #initialize and retain order of items in groups:
  List<String> oldNames = oldItem.getGroupNames();
  List<String> newNames = item.getGroupNames();
  List<String> commonNames = oldNames.stream().filter(name -> newNames.contains(name)).collect(toList());
  removeFromGroupItems(oldItem, oldNames.stream().filter(name -> !commonNames.contains(name)).collect(toList()));
  replaceInGroupItems(oldItem, item, commonNames);
  addToGroupItems(item, newNames.stream().filter(name -> !commonNames.contains(name)).collect(toList()));
  if (item instanceof GroupItem) {
    addMembersToGroupItem((GroupItem) item);
  }
  injectServices(item);
}

代码示例来源:origin: openhab/openhab-core

@Override
protected void onRemoveElement(Item element) {
  if (element instanceof GenericItem) {
    ((GenericItem) element).dispose();
  }
  removeFromGroupItems(element, element.getGroupNames());
}

代码示例来源:origin: openhab/openhab-core

/**
 * Retrieves the list of identifier token sets per item currently contained in the {@link ItemRegistry}.
 * Each item entry in the resulting hash map will feature a list of different token sets. Each token set
 * represents one possible way "through" a chain of parent groups, where each groups tokenized name is
 * part of the set.
 *
 * @param locale The locale that is to be used for preparing the tokens.
 * @return the list of identifier token sets per item
 */
HashMap<Item, ArrayList<HashSet<String>>> getItemTokens(Locale locale) {
  if (itemTokens == null) {
    itemTokens = new HashMap<Locale, HashMap<Item, ArrayList<HashSet<String>>>>();
  }
  HashMap<Item, ArrayList<HashSet<String>>> localeTokens = itemTokens.get(locale);
  if (localeTokens == null) {
    itemTokens.put(locale, localeTokens = new HashMap<Item, ArrayList<HashSet<String>>>());
    for (Item item : itemRegistry.getItems()) {
      if (item.getGroupNames().isEmpty()) {
        addItem(locale, localeTokens, new HashSet<String>(), item);
      }
    }
  }
  return localeTokens;
}

代码示例来源: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;
}

代码示例来源:origin: openhab/openhab-core

private void addMembersToGroupItem(GroupItem groupItem) {
  for (Item i : getItems()) {
    if (i.getGroupNames().contains(groupItem.getName())) {
      groupItem.addMember(i);
    }
  }
}

代码示例来源:origin: openhab/openhab-core

@Override
protected PersistedItem toPersistableElement(Item item) {
  PersistedItem persistedItem = new PersistedItem(
      item instanceof GroupItem ? ITEM_TYPE_GROUP : toItemFactoryName(item));
  if (item instanceof GroupItem) {
    GroupItem groupItem = (GroupItem) item;
    String baseItemType = null;
    Item baseItem = groupItem.getBaseItem();
    if (baseItem != null) {
      baseItemType = toItemFactoryName(baseItem);
    }
    persistedItem.baseItemType = baseItemType;
    addFunctionToPersisedItem(persistedItem, groupItem);
  }
  persistedItem.label = item.getLabel();
  persistedItem.groupNames = new ArrayList<>(item.getGroupNames());
  persistedItem.tags = new HashSet<>(item.getTags());
  persistedItem.category = item.getCategory();
  return persistedItem;
}

代码示例来源:origin: openhab/openhab-core

/**
 * 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: openhab/openhab-core

final State state = (State) newType;
internalGetUpdateRules(item.getName(), false, acceptedDataTypes, state, result);
for (String groupName : item.getGroupNames()) {
  internalGetUpdateRules(groupName, true, acceptedDataTypes, state, result);
final State oldState = (State) oldType;
internalGetChangeRules(item.getName(), false, acceptedDataTypes, newState, oldState, result);
for (String groupName : item.getGroupNames()) {
  internalGetChangeRules(groupName, true, acceptedDataTypes, newState, oldState, result);
final Command command = (Command) newType;
internalGetCommandRules(item.getName(), false, acceptedCommandTypes, command, result);
for (String groupName : item.getGroupNames()) {
  internalGetCommandRules(groupName, true, acceptedCommandTypes, command, result);

代码示例来源:origin: openhab/openhab-core

/**
 * Retrieves semantic information from parent or member items.
 *
 * @param item the item to gather the semantic metadata for
 * @param configuration the metadata configuration that should be amended
 */
private void processHierarchy(Item item, Map<String, Object> configuration) {
  Class<? extends Tag> type = SemanticTags.getSemanticType(item);
  if (type != null) {
    for (String parent : item.getGroupNames()) {
      Item parentItem = itemRegistry.get(parent);
      if (parentItem != null) {
        processParent(type, parentItem, configuration);
      }
    }
    if (item instanceof GroupItem) {
      GroupItem gItem = (GroupItem) item;
      for (Item memberItem : gItem.getMembers()) {
        processMember(type, memberItem, configuration);
      }
    }
  }
}

代码示例来源:origin: org.eclipse.smarthome.core/org.eclipse.smarthome.core.semantics

/**
 * Retrieves semantic information from parent or member items.
 *
 * @param item the item to gather the semantic metadata for
 * @param configuration the metadata configuration that should be amended
 */
private void processHierarchy(Item item, Map<String, Object> configuration) {
  Class<? extends Tag> type = SemanticTags.getSemanticType(item);
  if (type != null) {
    for (String parent : item.getGroupNames()) {
      Item parentItem = itemRegistry.get(parent);
      if (parentItem != null) {
        processParent(type, parentItem, configuration);
      }
    }
    if (item instanceof GroupItem) {
      GroupItem gItem = (GroupItem) item;
      for (Item memberItem : gItem.getMembers()) {
        processMember(type, memberItem, configuration);
      }
    }
  }
}

代码示例来源:origin: openhab/openhab-core

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: openhab/openhab-core

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();
}

相关文章