Skip to content

Instantly share code, notes, and snippets.

@cyclotimia
Last active March 12, 2016 11:27
Show Gist options
  • Select an option

  • Save cyclotimia/04269e7956adc9f98d55 to your computer and use it in GitHub Desktop.

Select an option

Save cyclotimia/04269e7956adc9f98d55 to your computer and use it in GitHub Desktop.

Revisions

  1. cyclotimia revised this gist Mar 12, 2016. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions class Pair
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,23 @@ class Pair<T, M> {
    private final T first;
    private final M second;

    // конструктор
    private Pair(T value1, M value2) {
    this.first = value1;
    this.second = value2;
    }


    // получить первый эл-т пары
    public T getFirst() {
    return this.first;
    }


    // получить второй эл-т пары
    public M getSecond() {
    return this.second;
    }

    // equals
    @Override
    public boolean equals(Object obj) {
    if (this == obj) return true;
    @@ -27,13 +31,15 @@ class Pair<T, M> {

    }

    // hashcode
    @Override
    public int hashCode() {
    int result = first != null ? first.hashCode() : 0;
    result = 31 * result + (second != null ? second.hashCode() : 0);
    return result;
    }

    // конструктор
    public static <T, M> Pair of(T value1, M value2) {
    return new Pair(value1, value2);
    }
  2. cyclotimia created this gist Dec 21, 2015.
    40 changes: 40 additions & 0 deletions class Pair
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    class Pair<T, M> {
    private final T first;
    private final M second;

    private Pair(T value1, M value2) {
    this.first = value1;
    this.second = value2;
    }

    public T getFirst() {
    return this.first;
    }

    public M getSecond() {
    return this.second;
    }

    @Override
    public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null || getClass() != obj.getClass()) return false;

    Pair<?, ?> pair = (Pair<?, ?>) obj;

    if (first != null ? !first.equals(pair.first) : pair.first != null) return false;
    return !(second != null ? !second.equals(pair.second) : pair.second != null);

    }

    @Override
    public int hashCode() {
    int result = first != null ? first.hashCode() : 0;
    result = 31 * result + (second != null ? second.hashCode() : 0);
    return result;
    }

    public static <T, M> Pair of(T value1, M value2) {
    return new Pair(value1, value2);
    }
    }