• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / automatalib / 13138848026

04 Feb 2025 02:53PM UTC coverage: 92.108% (+2.2%) from 89.877%
13138848026

push

github

mtf90
[maven-release-plugin] prepare release automatalib-0.12.0

16609 of 18032 relevant lines covered (92.11%)

1.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/commons/util/src/main/java/net/automatalib/common/util/Pair.java
1
/* Copyright (C) 2013-2025 TU Dortmund University
2
 * This file is part of AutomataLib <https://automatalib.net>.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package net.automatalib.common.util;
17

18
import java.io.IOException;
19
import java.util.Objects;
20

21
import net.automatalib.common.util.string.AbstractPrintable;
22
import net.automatalib.common.util.string.StringUtil;
23
import org.checkerframework.checker.nullness.qual.Nullable;
24

25
/**
26
 * Immutable pair class.
27
 * <p>
28
 * <b>Note</b>: this class should only be used for internal representations of tuples with value type semantics (e.g.
29
 * equality, only if all components are equal).
30
 * <p>
31
 * Whenever a public interface returns an aggregation of individual objects, a separate class should be created/used
32
 * that has meaningful identifiers for the individual components.
33
 *
34
 * @param <T1>
35
 *         type of the first component
36
 * @param <T2>
37
 *         type of the second component
38
 */
39
public final class Pair<T1, T2> extends AbstractPrintable {
40

41
    private final T1 first;
42
    private final T2 second;
43

44
    private Pair(T1 first, T2 second) {
1✔
45
        this.first = first;
1✔
46
        this.second = second;
1✔
47
    }
1✔
48

49
    /**
50
     * Creates a new pair from the given components.
51
     *
52
     * @param first
53
     *         the first pair component
54
     * @param second
55
     *         the second pair component
56
     * @param <T1>
57
     *         type of the first component
58
     * @param <T2>
59
     *         type of the second component
60
     *
61
     * @return the new pair object
62
     */
63
    public static <T1, T2> Pair<T1, T2> of(T1 first, T2 second) {
64
        return new Pair<>(first, second);
1✔
65
    }
66

67
    public T1 getFirst() {
68
        return first;
1✔
69
    }
70

71
    public T2 getSecond() {
72
        return second;
1✔
73
    }
74

75
    @Override
76
    public void print(Appendable a) throws IOException {
77
        a.append('(');
1✔
78
        StringUtil.appendObject(a, first);
1✔
79
        a.append(", ");
1✔
80
        StringUtil.appendObject(a, second);
1✔
81
        a.append(')');
1✔
82
    }
1✔
83

84
    @Override
85
    public boolean equals(@Nullable Object o) {
86
        if (this == o) {
1✔
87
            return true;
×
88
        }
89
        if (!(o instanceof Pair)) {
1✔
90
            return false;
×
91
        }
92

93
        final Pair<?, ?> that = (Pair<?, ?>) o;
1✔
94
        return Objects.equals(first, that.first) && Objects.equals(second, that.second);
1✔
95
    }
96

97
    @Override
98
    public int hashCode() {
99
        int result = 1;
1✔
100
        result = 31 * result + Objects.hashCode(first);
1✔
101
        result = 31 * result + Objects.hashCode(second);
1✔
102
        return result;
1✔
103
    }
104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc