/*
 * Copyright (c) 2016, Kevin Phoenix
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package in.twizmwaz.cardinal.util;

import lombok.Data;
import lombok.NonNull;

/**
 * Class to represent XML protocols, based on semantic versioning.
 */
@Data
public class Proto {

  private final int major;
  private final int minor;
  private final int patch;

  /**
   * @param in The semantic version string to be parsed.
   * @return The parsed Proto.
   */
  public static Proto parseProto(@NonNull String in) {
    String[] components = in.split("\\.");
    if (components.length != 3) {
      throw new NumberFormatException("A proto must be a semantic version.");
    }
    int major = Integer.parseInt(components[0]);
    int minor = Integer.parseInt(components[1]);
    int patch = Integer.parseInt(components[2]);
    return new Proto(major, minor, patch);
  }

}

/*
 * Copyright (c) 2016, Kevin Phoenix
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package in.twizmwaz.cardinal.util;

import lombok.Data;
import lombok.NonNull;

/**
 * Class to represent XML protocols, based on semantic versioning.
 */
@Data
public class Proto {

  private final int major;
  private final int minor;
  private final int patch;

  /**
   * @param in The semantic version string to be parsed.
   * @return The parsed Proto.
   */
  public static Proto parseProto(@NonNull String in) {
    String[] components = in.split("\\.");
    if (components.length != 3) {
      throw new NumberFormatException("A proto must be a semantic version.");
    }
    int major = Integer.parseInt(components[0]);
    int minor = Integer.parseInt(components[1]);
    int patch = Integer.parseInt(components[2]);
    return new Proto(major, minor, patch);
  }

  /**
   * @param proto The given proto.
   * @return If this proto is greater than the given proto.
   */
  public boolean greaterThan(@NonNull Proto proto) {
    return this.major > proto.getMajor()
            || (this.major == proto.getMajor() && (this.minor > proto.getMinor()
            || (this.minor == proto.getMinor() && this.patch > proto.getPatch())));
  }

  public boolean greaterThanOrEqualTo(@NonNull Proto proto) {
    return this.equals(proto) || this.greaterThan(proto);
  }

  /**
   * @param proto The given proto.
   * @return If this proto is less than the given proto.
   */
  public boolean lessThan(@NonNull Proto proto) {
    return this.major < proto.getMajor()
            || (this.major == proto.getMajor() && (this.minor < proto.getMinor()
            || (this.minor == proto.getMinor() && this.patch < proto.getPatch())));
  }

  public boolean lessThanOrEqualTo(@NonNull Proto proto) {
    return this.equals(proto) || this.lessThan(proto);
  }

}

Add proto evaluation methods