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

oracle / opengrok / #3669

01 Nov 2023 10:10AM UTC coverage: 75.13% (-0.03%) from 75.16%
#3669

push

web-flow
Fix Sonar codesmell issues (#4460)

Signed-off-by: Gino Augustine <ginoaugustine@gmail.com>

308 of 308 new or added lines in 27 files covered. (100.0%)

44029 of 58604 relevant lines covered (75.13%)

0.75 hits per line

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

0.0
/opengrok-web/src/main/java/org/opengrok/web/DiffType.java
1
/*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License (the "License").
6
 * You may not use this file except in compliance with the License.
7
 *
8
 * See LICENSE.txt included in this distribution for the specific
9
 * language governing permissions and limitations under the License.
10
 *
11
 * When distributing Covered Code, include this CDDL HEADER in each
12
 * file and include the License file at LICENSE.txt.
13
 * If applicable, add the following below this CDDL HEADER, with the
14
 * fields enclosed by brackets "[]" replaced with your own identifying
15
 * information: Portions Copyright [yyyy] [name of copyright owner]
16
 *
17
 * CDDL HEADER END
18
 */
19

20
/*
21
 * Copyright (c) 2009, 2011, Jens Elkner.
22
 * Copyright (c) 2009, 2019, Oracle and/or its affiliates. All rights reserved.
23
 */
24
package org.opengrok.web;
25

26
/**
27
 * Known diff display types.
28
 *
29
 * @author  Jens Elkner
30
 */
31
public enum DiffType {
×
32

33
    /** side-by-side diff. */
34
    SIDEBYSIDE('s', "sdiff"),
×
35
    /** unified diff (i.e. with context lines). */
36
    UNIFIED('u', "udiff"),
×
37
    /** traditional ed diff (no context lines). */
38
    TEXT('t', "text"),
×
39
    /** the old version of the file (before changes applied). */
40
    OLD('o', "old"),
×
41
    /** the new version of the file (after changes applied). */
42
    NEW('n', "new");
×
43
    private final char abbrev;
44
    private final String name;
45

46
    DiffType(char abbrev, String name) {
×
47
        this.abbrev = abbrev;
×
48
        this.name = name;
×
49
    }
×
50

51
    /**
52
     * Get the diff type for the given abbreviation.
53
     * @param c abbreviation to check.
54
     * @return {@code null} if not found, the diff type otherwise.
55
     */
56
    public static DiffType get(char c) {
57
        for (DiffType d : values()) {
×
58
            if (c == d.abbrev) {
×
59
                return d;
×
60
            }
61
        }
62
        return null;
×
63
    }
64

65
    /**
66
     * Get the diff type for the given abbreviation or name.
67
     * @param c abbreviation or name to check.
68
     * @return {@code null} if not found, the diff type otherwise.
69
     */
70
    public static DiffType get(String c) {
71
        if (c == null || c.length() == 0) {
×
72
            return null;
×
73
        }
74
        if (c.length() == 1) {
×
75
            return get(c.charAt(0));
×
76
        }
77
        for (DiffType d : values()) {
×
78
            if (d.name.equals(c)) {
×
79
                return d;
×
80
            }
81
        }
82
        // fallback to first char
83
        return get(c.charAt(0));
×
84
    }
85

86
    /**
87
     * Get the abbreviation to be used for this diff type.
88
     * @return wrt. to all known diff types a unique character.
89
     */
90
    public char getAbbrev() {
91
        return abbrev;
×
92
    }
93

94
    /**
95
     * {@inheritDoc}
96
     * @return the common name of the diff type.
97
     */
98
    @Override
99
    public String toString() {
100
        return name;
×
101
    }
102
}
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

© 2026 Coveralls, Inc