| 1 | /* | |
| 2 | * Copyright 2019 Hector Espert <hectorespertpardo@gmail.com>. | |
| 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 es.blackleg.jlibnotify.core; | |
| 17 | ||
| 18 | import com.sun.jna.Pointer; | |
| 19 | import java.util.ArrayList; | |
| 20 | import java.util.Collection; | |
| 21 | import java.util.List; | |
| 22 | import java.util.Objects; | |
| 23 | ||
| 24 | /** | |
| 25 | * Reference implementation of {@link ServerCapabilitiesReader}. | |
| 26 | * | |
| 27 | * <p>Walks the native {@code GList} node by node, reading each node as an array of two pointers | |
| 28 | * where the first one is the capability string and the second one the next node of the list. This | |
| 29 | * is the only place of the library that traverses native memory by hand.</p> | |
| 30 | * | |
| 31 | * @author Hector Espert | |
| 32 | */ | |
| 33 | public class DefaultServerCapabilitiesReader implements ServerCapabilitiesReader { | |
| 34 | ||
| 35 | /** | |
| 36 | * Creates a reader. It holds no state, so a single instance can be shared. | |
| 37 | */ | |
| 38 | public DefaultServerCapabilitiesReader() { | |
| 39 | } | |
| 40 | ||
| 41 | @Override | |
| 42 | public Collection<String> getServerCapabilitiesFromPointer(Pointer pointer) { | |
| 43 | List<String> serverCapabilities = new ArrayList<>(); | |
| 44 | Pointer readedPointer = pointer; | |
| 45 |
1
1. getServerCapabilitiesFromPointer : negated conditional → NO_COVERAGE |
while (Objects.nonNull(readedPointer)) { |
| 46 | Pointer[] readedPointers = readedPointer.getPointerArray(0); | |
| 47 |
2
1. getServerCapabilitiesFromPointer : changed conditional boundary → NO_COVERAGE 2. getServerCapabilitiesFromPointer : negated conditional → NO_COVERAGE |
if (readedPointers.length >= 1) { |
| 48 | String readedString = readedPointers[0].getString(0); | |
| 49 | serverCapabilities.add(readedString); | |
| 50 | } | |
| 51 |
2
1. getServerCapabilitiesFromPointer : negated conditional → NO_COVERAGE 2. getServerCapabilitiesFromPointer : changed conditional boundary → NO_COVERAGE |
if (readedPointers.length >= 2) { |
| 52 | readedPointer = readedPointers[1]; | |
| 53 | } else { | |
| 54 | readedPointer = null; | |
| 55 | } | |
| 56 | } | |
| 57 |
1
1. getServerCapabilitiesFromPointer : replaced return value with Collections.emptyList for es/blackleg/jlibnotify/core/DefaultServerCapabilitiesReader::getServerCapabilitiesFromPointer → NO_COVERAGE |
return serverCapabilities; |
| 58 | } | |
| 59 | ||
| 60 | } | |
Mutations | ||
| 45 |
1.1 |
|
| 47 |
1.1 2.2 |
|
| 51 |
1.1 2.2 |
|
| 57 |
1.1 |