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

oracle / opengrok / #3716

30 Nov 2023 08:55AM UTC coverage: 66.158% (+0.05%) from 66.106%
#3716

push

web-flow
Refactoring to reduce sonar code smell fixes (#4485)

---------

Signed-off-by: Gino Augustine <ginoaugustine@gmail.com>
Co-authored-by: Vladimir Kotal <vlada@kotalovi.cz>

389 of 478 new or added lines in 51 files covered. (81.38%)

11 existing lines in 9 files now uncovered.

38764 of 58593 relevant lines covered (66.16%)

0.66 hits per line

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

67.74
/suggester/src/main/java/org/opengrok/suggest/popular/impl/chronicle/BytesRefDataAccess.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) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
22
 */
23
package org.opengrok.suggest.popular.impl.chronicle;
24

25
import net.openhft.chronicle.bytes.BytesStore;
26
import net.openhft.chronicle.bytes.RandomDataInput;
27
import net.openhft.chronicle.hash.AbstractData;
28
import net.openhft.chronicle.hash.Data;
29
import net.openhft.chronicle.hash.serialization.DataAccess;
30
import net.openhft.chronicle.wire.WireIn;
31
import net.openhft.chronicle.wire.WireOut;
32
import org.apache.lucene.util.BytesRef;
33
import org.jetbrains.annotations.NotNull;
34
import org.jetbrains.annotations.Nullable;
35

36
import java.util.Optional;
37

38
/**
39
 * {@link BytesRef} data serializer for {@link net.openhft.chronicle.map.ChronicleMap}.
40
 * Modified from <a href="https://github.com/OpenHFT/Chronicle-Map/blob/master/docs/CM_Tutorial_DataAccess.adoc">...</a>
41
 */
42
@SuppressWarnings({"java:S2065", "java:S2160"})
43
public class BytesRefDataAccess extends AbstractData<BytesRef> implements DataAccess<BytesRef> {
44

45
    /** Cache field. */
46
    private transient BytesStore<?, ?> bs;
47

48
    /** State field. */
49
    private transient byte[] array;
50

51
    public BytesRefDataAccess() {
1✔
52
        initTransients();
1✔
53
    }
1✔
54

55
    private void initTransients() {
56
        bs = null;
1✔
57
    }
1✔
58

59
    @Override
60
    public RandomDataInput bytes() {
61
        return bs;
1✔
62
    }
63

64
    @Override
65
    public long offset() {
66
        return bs.start();
1✔
67
    }
68

69
    @Override
70
    public long size() {
71
        return bs.capacity();
1✔
72
    }
73

74
    @Override
75
    public BytesRef get() {
76
        return new BytesRef(array);
×
77
    }
78

79
    @Override
80
    public BytesRef getUsing(@Nullable BytesRef using) {
NEW
81
        using = Optional.ofNullable(using)
×
NEW
82
                .orElseGet( () ->
×
NEW
83
                        new BytesRef(new byte[array.length])
×
84
                );
NEW
85
        if (using.bytes.length < array.length) {
×
UNCOV
86
            using.bytes = new byte[array.length];
×
87
        }
88
        System.arraycopy(array, 0, using.bytes, 0, array.length);
×
89
        using.offset = 0;
×
90
        using.length = array.length;
×
91
        return using;
×
92
    }
93

94
    @Override
95
    public Data<BytesRef> getData(@NotNull BytesRef instance) {
96
        if (instance.bytes.length == instance.length) {
1✔
97
            array = instance.bytes;
1✔
98
        } else {
99
            array = new byte[instance.length];
1✔
100
            System.arraycopy(instance.bytes, instance.offset, array, 0, instance.length);
1✔
101
        }
102
        bs = BytesStore.wrap(array);
1✔
103
        return this;
1✔
104
    }
105

106
    @Override
107
    public void uninit() {
108
        array = null;
1✔
109
        bs = null;
1✔
110
    }
1✔
111

112
    @Override
113
    public DataAccess<BytesRef> copy() {
114
        return new BytesRefDataAccess();
1✔
115
    }
116

117
    @Override
118
    public void writeMarshallable(@NotNull WireOut wireOut) {
119
        // no fields to write
120
    }
1✔
121

122
    @Override
123
    public void readMarshallable(@NotNull WireIn wireIn) {
124
        // no fields to read
125
        initTransients();
1✔
126
    }
1✔
127

128
}
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