예제 #1
0
  /**
   * Merges service properties from parent into the the service properties of this this service.
   * Current properties overrides properties with same name from parent
   *
   * @param other service properties to merge with the current service property list
   */
  private void mergeServiceProperties(List<ServicePropertyInfo> other) {
    if (!other.isEmpty()) {
      List<ServicePropertyInfo> servicePropertyList = serviceInfo.getServicePropertyList();
      List<ServicePropertyInfo> servicePropertiesToAdd = Lists.newArrayList();

      Set<String> servicePropertyNames =
          Sets.newTreeSet(
              Iterables.transform(
                  servicePropertyList,
                  new Function<ServicePropertyInfo, String>() {
                    @Nullable
                    @Override
                    public String apply(ServicePropertyInfo serviceProperty) {
                      return serviceProperty.getName();
                    }
                  }));

      for (ServicePropertyInfo otherServiceProperty : other) {
        if (!servicePropertyNames.contains(otherServiceProperty.getName()))
          servicePropertiesToAdd.add(otherServiceProperty);
      }

      List<ServicePropertyInfo> mergedServicePropertyList =
          ImmutableList.<ServicePropertyInfo>builder()
              .addAll(servicePropertyList)
              .addAll(servicePropertiesToAdd)
              .build();

      serviceInfo.setServicePropertyList(mergedServicePropertyList);

      validateServiceInfo();
    }
  }