fr.quatrevieux.singleinstance.ipc.SimpleMessage   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 72.21%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 30
c 1
b 0
f 0
dl 0
loc 47
ccs 13
cts 18
cp 0.7221
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hashCode() 0 5 1
A data() 0 3 1
A toString() 0 3 1
A SimpleMessage(String) 0 2 1
A SimpleMessage(String,byte[]) 0 3 1
A name() 0 3 1
A equals(Object) 0 12 4
1
/*
2
 * This file is part of SingleInstance.
3
 *
4
 * SingleInstance is free software: you can redistribute it and/or modify
5
 * it under the terms of the GNU Lesser General Public License as published by
6
 * the Free Software Foundation, either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * SingleInstance is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with SingleInstance.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2020 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.singleinstance.ipc;
21
22
import java.util.Arrays;
23
import java.util.Objects;
24
25
/**
26
 * Basic implementation for IPC messages
27
 */
28
final public class SimpleMessage implements Message {
29
    final private String name;
30
    final private byte[] data;
31
32
    public SimpleMessage(String name) {
33 1
        this(name, new byte[0]);
34 1
    }
35
36 1
    public SimpleMessage(String name, byte[] data) {
37 1
        this.name = name;
38 1
        this.data = data;
39 1
    }
40
41
    @Override
42
    public String name() {
43 1
        return name;
44
    }
45
46
    @Override
47
    public byte[] data() {
48 1
        return data;
49
    }
50
51
    @Override
52
    public String toString() {
53 1
        return "SimpleMessage(" + name + ": " + Arrays.toString(data) + ')';
54
    }
55
56
    @Override
57
    public boolean equals(Object o) {
58 1
        if (this == o) {
59
            return true;
60
        }
61
62 1
        if (o == null || getClass() != o.getClass()) {
63
            return false;
64
        }
65
66 1
        SimpleMessage that = (SimpleMessage) o;
67 1
        return name.equals(that.name) && Arrays.equals(data, that.data);
68
    }
69
70
    @Override
71
    public int hashCode() {
72
        int result = Objects.hash(name);
73
        result = 31 * result + Arrays.hashCode(data);
74
        return result;
75
    }
76
}
77