• 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/ArrayOfLongsSerDe.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.putLongLE;
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 Long.
31
 *
32
 * @author Alexander Saydakov
33
 */
34
public class ArrayOfLongsSerDe extends ArrayOfItemsSerDe<Long> {
1✔
35

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

44
  @Override
45
  public byte[] serializeToByteArray(final Long[] 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[Long.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.putLong(offset, items[i]);
1✔
53
      offset += Long.BYTES;
1✔
54
    }
55
    return bytes;
1✔
56
  }
57

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

63
  @Override
64
  public Long[] 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 Long[0]; }
1✔
67
    long offset = offsetBytes;
1✔
68
    Util.checkBounds(offset, Long.BYTES * (long)numItems, mem.getCapacity());
1✔
69
    final Long[] array = new Long[numItems];
1✔
70
    for (int i = 0; i < numItems; i++) {
1✔
71
      array[i] = mem.getLong(offset);
1✔
72
      offset += Long.BYTES;
1✔
73
    }
74
    return array;
1✔
75
  }
76

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

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

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

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

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