fr.quatrevieux.araknemu.data.living.transformer.IpAddressTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 9
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
eloc 7
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize(IPAddressString) 0 3 2
A unserialize(String) 0 3 2
1
/*
2
 * This file is part of Araknemu.
3
 *
4
 * Araknemu 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
 * Araknemu 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 Araknemu.  If not, see <https://www.gnu.org/licenses/>.
16
 *
17
 * Copyright (c) 2017-2020 Vincent Quatrevieux
18
 */
19
20
package fr.quatrevieux.araknemu.data.living.transformer;
21
22
import fr.quatrevieux.araknemu.data.transformer.Transformer;
23
import fr.quatrevieux.araknemu.data.transformer.TransformerException;
24
import inet.ipaddr.IPAddressString;
25
import org.checkerframework.checker.nullness.qual.PolyNull;
26
27
/**
28
 * Parse IP address string
29
 * Handle IPv4, IPv6 and net mask
30
 */
31 1
public final class IpAddressTransformer implements Transformer<IPAddressString> {
32
    @Override
33
    public @PolyNull String serialize(@PolyNull IPAddressString value) {
34 1
        return value == null ? null : value.toNormalizedString();
35
    }
36
37
    @Override
38
    public @PolyNull IPAddressString unserialize(@PolyNull String serialize) throws TransformerException {
39 1
        return serialize == null ? null : new IPAddressString(serialize);
40
    }
41
}
42