public MesosSlaveInfo getMesosSlaveInfoForLabel(Label label) {
    if (!matchesLabel(label)) {
      return null;
    }

    if (label == null) {
      if (getLabelString() == null) {
        return this;
      } else {
        return null;
      }
    }

    if (label.matches(Label.parse(getLabelString()))) {
      return this;
    }

    if (!containerInfo.getDockerImageCustomizable()) {
      return null;
    }

    String customImage = getCustomImage(label);
    if (customImage == null) {
      return null;
    }

    return copyWithDockerImage(label.toString(), customImage);
  }
  public MesosSlaveInfo copyWithDockerImage(String label, String dockerImage) {
    LOGGER.fine(
        String.format(
            "Customize mesos slave %s using docker image %s", this.getLabelString(), dockerImage));

    try {
      return new MesosSlaveInfo(
          label,
          mode,
          slaveCpus,
          slaveMem,
          minExecutors,
          maxExecutors,
          executorCpus,
          executorMem,
          remoteFSRoot,
          idleTerminationMinutes,
          slaveAttributes,
          jvmArgs,
          jnlpArgs,
          defaultSlave,
          containerInfo.copyWithDockerImage(dockerImage),
          additionalURIs,
          nodeProperties);
    } catch (Descriptor.FormException e) {
      LOGGER.log(Level.WARNING, "Failed to create customized mesos container info", e);
      return null;
    } catch (IOException e) {
      LOGGER.log(Level.WARNING, "Failed to create customized mesos slave info", e);
      return null;
    }
  }
  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    MesosSlaveInfo that = (MesosSlaveInfo) o;

    if (Double.compare(that.slaveCpus, slaveCpus) != 0) return false;
    if (slaveMem != that.slaveMem) return false;
    if (Double.compare(that.executorCpus, executorCpus) != 0) return false;
    if (minExecutors != that.minExecutors) return false;
    if (maxExecutors != that.maxExecutors) return false;
    if (executorMem != that.executorMem) return false;
    if (idleTerminationMinutes != that.idleTerminationMinutes) return false;
    if (remoteFSRoot != null ? !remoteFSRoot.equals(that.remoteFSRoot) : that.remoteFSRoot != null)
      return false;
    if (jvmArgs != null ? !jvmArgs.equals(that.jvmArgs) : that.jvmArgs != null) return false;
    if (jnlpArgs != null ? !jnlpArgs.equals(that.jnlpArgs) : that.jnlpArgs != null) return false;
    if (slaveAttributes != null
        ? !slaveAttributes.equals(that.slaveAttributes)
        : that.slaveAttributes != null) return false;
    if (containerInfo != null
        ? !containerInfo.equals(that.containerInfo)
        : that.containerInfo != null) return false;
    if (additionalURIs != null
        ? !additionalURIs.equals(that.additionalURIs)
        : that.additionalURIs != null) return false;
    if (mode != that.mode) return false;
    if (nodeProperties != null
        ? !nodeProperties.equals(that.nodeProperties)
        : that.nodeProperties != null) return false;
    return labelString != null ? labelString.equals(that.labelString) : that.labelString == null;
  }
  /**
   * Check if the label in the slave matches the provided label, either both are null or are the
   * same.
   *
   * @param label
   * @return Whether the slave label matches.
   */
  public boolean matchesLabel(@CheckForNull Label label) {

    if (label == null || getLabelString() == null) {
      return label == null && getLabelString() == null;
    }

    if (label.matches(Label.parse(getLabelString()))) {
      return true;
    }

    if (containerInfo == null || !containerInfo.getDockerImageCustomizable()) {
      return false;
    }

    String customImage = getCustomImage(label);
    return customImage != null
        && getLabelWithoutCustomImage(label, customImage).matches(Label.parse(getLabelString()));
  }
 @Override
 public int hashCode() {
   int result;
   long temp;
   temp = Double.doubleToLongBits(slaveCpus);
   result = (int) (temp ^ (temp >>> 32));
   result = 31 * result + slaveMem;
   temp = Double.doubleToLongBits(executorCpus);
   result = 31 * result + (int) (temp ^ (temp >>> 32));
   result = 31 * result + minExecutors;
   result = 31 * result + maxExecutors;
   result = 31 * result + executorMem;
   result = 31 * result + (remoteFSRoot != null ? remoteFSRoot.hashCode() : 0);
   result = 31 * result + idleTerminationMinutes;
   result = 31 * result + (jvmArgs != null ? jvmArgs.hashCode() : 0);
   result = 31 * result + (jnlpArgs != null ? jnlpArgs.hashCode() : 0);
   result = 31 * result + (slaveAttributes != null ? slaveAttributes.hashCode() : 0);
   result = 31 * result + (containerInfo != null ? containerInfo.hashCode() : 0);
   result = 31 * result + (additionalURIs != null ? additionalURIs.hashCode() : 0);
   result = 31 * result + (mode != null ? mode.hashCode() : 0);
   result = 31 * result + (nodeProperties != null ? nodeProperties.hashCode() : 0);
   result = 31 * result + (labelString != null ? labelString.hashCode() : 0);
   return result;
 }