hotspot/test/testlibrary/jdk/test/lib/Triple.java
author ppunegov
Thu, 24 Sep 2015 20:13:04 +0300
changeset 33081 71794b149055
permissions -rw-r--r--
8066157: JEP-JDK-8046155: Test task: method matcher Summary: MethodMatcher test and framework Reviewed-by: iignatyev, neliasso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33081
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     1
/*
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     4
 *
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     8
 *
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    13
 * accompanied this code).
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    14
 *
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    18
 *
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    21
 * questions.
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    22
 */
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    23
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    24
package jdk.test.lib;
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    25
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    26
import java.util.Objects;
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    27
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    28
/**
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    29
 * Triple - a three element tuple
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    30
 *
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    31
 * @param <F> first element type
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    32
 * @param <S> second element type
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    33
 * @param <T> third element type
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    34
 */
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    35
public class Triple<F, S, T> {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    36
    private final Pair<F, Pair<S, T>> container;
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    37
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    38
    /**
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    39
     * Constructor
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    40
     *
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    41
     * @param first  first element of the triple
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    42
     * @param second second element of the triple
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    43
     * @param third  third element of the triple
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    44
     */
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    45
    public Triple(F first, S second, T third) {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    46
        container = new Pair<>(first, new Pair<>(second, third));
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    47
    }
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    48
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    49
    /**
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    50
     * Gets first element of the triple
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    51
     */
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    52
    public F getFirst() {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    53
        return container.first;
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    54
    }
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    55
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    56
    /**
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    57
     * Gets second element of the triple
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    58
     */
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    59
    public S getSecond() {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    60
        return container.second.first;
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    61
    }
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    62
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    63
    /**
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    64
     * Gets third element of the triple
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    65
     */
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    66
    public T getThird() {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    67
        return container.second.second;
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    68
    }
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    69
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    70
    @Override
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    71
    public int hashCode() {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    72
        return container.hashCode();
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    73
    }
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    74
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    75
    @Override
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    76
    public boolean equals(Object obj) {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    77
        if (obj instanceof Triple<?, ?, ?>) {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    78
            Triple<?, ?, ?> objTriple = (Triple<?, ?, ?>) obj;
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    79
            return Objects.equals(container.first, objTriple.container.first)
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    80
                    && Objects.equals(container.second,
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    81
                    objTriple.container.second);
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    82
        }
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    83
        return false;
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    84
    }
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    85
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    86
    @Override
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    87
    public String toString() {
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    88
        return "(" + getFirst() + " : " + getSecond() + " : " + getThird() + ")";
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    89
    }
71794b149055 8066157: JEP-JDK-8046155: Test task: method matcher
ppunegov
parents:
diff changeset
    90
}