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

apache / datasketches-java / #306

30 Apr 2024 10:01PM UTC coverage: 97.645% (-0.5%) from 98.139%
#306

push

web-flow
Merge pull request #555 from apache/fix_pom_xml_header

Fix pom xml header

26865 of 27513 relevant lines covered (97.64%)

0.98 hits per line

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

93.94
/src/main/java/org/apache/datasketches/common/ArrayOfDoublesSerDe.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.datasketches.common;
21

22
import static org.apache.datasketches.common.ByteArrayUtil.putDoubleLE;
23

24
import java.util.Objects;
25

26
import org.apache.datasketches.memory.Memory;
27
import org.apache.datasketches.memory.WritableMemory;
28

29
/**
30
 * Methods of serializing and deserializing arrays of Double.
31
 *
32
 * @author Alexander Saydakov
33
 */
34
public class ArrayOfDoublesSerDe extends ArrayOfItemsSerDe<Double> {
1✔
35

36
  @Override
37
  public byte[] serializeToByteArray(final Double item) {
38
    Objects.requireNonNull(item, "Item must not be null");
1✔
39
    final byte[] byteArr = new byte[Double.BYTES];
1✔
40
    putDoubleLE(byteArr, 0, item.doubleValue());
1✔
41
    return byteArr;
1✔
42
  }
43

44
  @Override
45
  public byte[] serializeToByteArray(final Double[] items) {
46
    Objects.requireNonNull(items, "Items must not be null");
1✔
47
    if (items.length == 0) { return new byte[0]; }
1✔
48
    final byte[] bytes = new byte[Double.BYTES * items.length];
1✔
49
    final WritableMemory mem = WritableMemory.writableWrap(bytes);
1✔
50
    long offset = 0;
1✔
51
    for (int i = 0; i < items.length; i++) {
1✔
52
      mem.putDouble(offset, items[i]);
1✔
53
      offset += Double.BYTES;
1✔
54
    }
55
    return bytes;
1✔
56
  }
57

58
  @Override
59
  public Double[] deserializeFromMemory(final Memory mem, final int numItems) {
60
    return deserializeFromMemory(mem, 0, numItems);
×
61
  }
62

63
  @Override
64
  public Double[] deserializeFromMemory(final Memory mem, final long offsetBytes, final int numItems) {
65
    Objects.requireNonNull(mem, "Memory must not be null");
1✔
66
    if (numItems <= 0) { return new Double[0]; }
1✔
67
    long offset = offsetBytes;
1✔
68
    Util.checkBounds(offset, Double.BYTES * (long)numItems, mem.getCapacity());
1✔
69
    final Double[] array = new Double[numItems];
1✔
70

71
    for (int i = 0; i < numItems; i++) {
1✔
72
      array[i] = mem.getDouble(offset);
1✔
73
      offset += Double.BYTES;
1✔
74
    }
75
    return array;
1✔
76
  }
77

78
  @Override
79
  public int sizeOf(final Double item) {
80
    Objects.requireNonNull(item, "Item must not be null");
1✔
81
    return Double.BYTES;
1✔
82
  }
83

84
  @Override //override because this is simpler
85
  public int sizeOf(final Double[] items) {
86
    Objects.requireNonNull(items, "Items must not be null");
1✔
87
    return items.length * Double.BYTES;
1✔
88
  }
89

90
  @Override
91
  public int sizeOf(final Memory mem, final long offsetBytes, final int numItems) {
92
    Objects.requireNonNull(mem, "Memory must not be null");
1✔
93
    return numItems * Double.BYTES;
1✔
94
  }
95

96
  @Override
97
  public String toString(final Double item) {
98
    if (item == null) { return "null"; }
1✔
99
    return item.toString();
1✔
100
  }
101

102
  @Override
103
  public Class<Double> getClassOfT() { return Double.class; }
×
104
}
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

© 2025 Coveralls, Inc