Package: Request

Request

nameinstructionbranchcomplexitylinemethod
Request(Object, ChannelRecord)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
extractReadRequest(ChannelRecord)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
extractReadRequests(List)
M: 0 C: 31
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
extractWriteRequest(ChannelRecord)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
extractWriteRequests(List)
M: 0 C: 31
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
fromRecord(ChannelRecord, Function)
M: 0 C: 20
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
getParameters()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getRecord()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$0(ChannelRecord)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$1(ChannelRecord)
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (c) 2018 Eurotech and/or its affiliates and others
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License v1.0
6: * which accompanies this distribution, and is available at
7: * http://www.eclipse.org/legal/epl-v10.html
8: *
9: */
10:
11: package org.eclipse.kura.internal.driver.opcua.request;
12:
13: import java.util.ArrayList;
14: import java.util.List;
15: import java.util.Optional;
16: import java.util.function.Function;
17:
18: import org.eclipse.kura.channel.ChannelFlag;
19: import org.eclipse.kura.channel.ChannelRecord;
20: import org.eclipse.kura.channel.ChannelStatus;
21:
22: public class Request<T> {
23:
24: private final T params;
25: private final ChannelRecord record;
26:
27: protected Request(final T params, final ChannelRecord record) {
28: this.params = params;
29: this.record = record;
30: }
31:
32: private static <T> Optional<T> fromRecord(final ChannelRecord record, final Function<ChannelRecord, T> func) {
33: try {
34: return Optional.of(func.apply(record));
35: } catch (Exception e) {
36: record.setChannelStatus(new ChannelStatus(ChannelFlag.FAILURE, e.getMessage(), e));
37: record.setTimestamp(System.currentTimeMillis());
38: return Optional.empty();
39: }
40: }
41:
42: public static Optional<Request<ReadParams>> extractReadRequest(final ChannelRecord record) {
43: return fromRecord(record, r -> new Request<>(new ReadParams(r.getChannelConfig()), r));
44: }
45:
46: public static Optional<Request<WriteParams>> extractWriteRequest(final ChannelRecord record) {
47: return fromRecord(record,
48: r -> new Request<>(new WriteParams(r.getChannelConfig(), r.getValue().getValue()), r));
49: }
50:
51: public static List<Request<ReadParams>> extractReadRequests(final List<ChannelRecord> records) {
52: final ArrayList<Request<ReadParams>> result = new ArrayList<>(records.size());
53:• for (final ChannelRecord record : records) {
54: final Optional<Request<ReadParams>> request = extractReadRequest(record);
55:• if (request.isPresent()) {
56: result.add(request.get());
57: }
58: }
59: return result;
60: }
61:
62: public static List<Request<WriteParams>> extractWriteRequests(final List<ChannelRecord> records) {
63: final ArrayList<Request<WriteParams>> result = new ArrayList<>(records.size());
64:• for (final ChannelRecord record : records) {
65: final Optional<Request<WriteParams>> request = extractWriteRequest(record);
66:• if (request.isPresent()) {
67: result.add(request.get());
68: }
69: }
70: return result;
71: }
72:
73: public T getParameters() {
74: return params;
75: }
76:
77: public ChannelRecord getRecord() {
78: return record;
79: }
80: }