コード例 #1
0
 @Override
 public IRteDeviceItem getVendorItem() {
   if (getLevel() == EDeviceHierarchyLevel.VENDOR.ordinal()) return this;
   else if (getLevel() > EDeviceHierarchyLevel.VENDOR.ordinal()) {
     if (getParent() != null) return getParent().getVendorItem();
   }
   return null;
 }
コード例 #2
0
  @Override
  public void addDevice(ICpDeviceItem item) {
    if (item == null) return;

    EDeviceHierarchyLevel eLevel = item.getLevel();
    int level = eLevel.ordinal();

    if (fLevel == level || fLevel == EDeviceHierarchyLevel.PROCESSOR.ordinal()) {
      ICpPack pack = item.getPack();
      String packId = pack.getId();
      if (fDevices == null) fDevices = new TreeMap<String, ICpDeviceItem>(new AlnumComparator());

      ICpDeviceItem device = fDevices.get(packId);
      if (device == null) {
        fDevices.put(packId, item);
      }
      if (fLevel == EDeviceHierarchyLevel.PROCESSOR.ordinal()) return;
      Collection<ICpDeviceItem> subItems = item.getDeviceItems();
      if (subItems != null && !subItems.isEmpty()) {
        for (ICpDeviceItem i : subItems) {
          addDevice(i);
        }
      } else if (level >= EDeviceHierarchyLevel.DEVICE.ordinal() && item.getProcessorCount() > 1) {
        // add processor leaves
        Map<String, ICpItem> processors = item.getProcessors();
        for (Entry<String, ICpItem> e : processors.entrySet()) {
          String procName = item.getName() + ":" + e.getKey();
          addDeviceItem(item, procName, EDeviceHierarchyLevel.PROCESSOR.ordinal());
        }
      }
      return;
    } else if (fLevel == EDeviceHierarchyLevel.ROOT.ordinal()) {
      String vendorName = Vendor.getOfficialVendorName(item.getVendor());
      addDeviceItem(item, vendorName, EDeviceHierarchyLevel.VENDOR.ordinal());
      return;
    } else if (fLevel > level) { // should not happen if algorithm is correct
      return;
    }

    // other cases
    addDeviceItem(item, item.getName(), level);
  }