• 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

85.71
/src/main/java/org/apache/datasketches/common/ArrayOfItemsSerDe.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 java.util.Objects;
23

24
import org.apache.datasketches.memory.Memory;
25

26
/**
27
 * Base class for serializing and deserializing custom types.
28
 * @param <T> Type of item
29
 *
30
 * @author Alexander Saydakov
31
 */
32
public abstract class ArrayOfItemsSerDe<T> {
1✔
33

34
  /**
35
   * Serialize a single unserialized item to a byte array.
36
   *
37
   * @param item the item to be serialized
38
   * @return serialized representation of the given item
39
   */
40
  public abstract byte[] serializeToByteArray(T item);
41

42
  /**
43
   * Serialize an array of unserialized items to a byte array of contiguous serialized items.
44
   *
45
   * @param items array of items to be serialized
46
   * @return contiguous, serialized representation of the given array of unserialized items
47
   */
48
  public abstract byte[] serializeToByteArray(T[] items);
49

50
  /**
51
   * Deserialize a contiguous sequence of serialized items from the given Memory
52
   * starting at a Memory offset of zero and extending numItems.
53
   *
54
   * @param mem Memory containing a contiguous sequence of serialized items
55
   * @param numItems number of items in the contiguous serialized sequence.
56
   * @return array of deserialized items
57
   * @see #deserializeFromMemory(Memory, long, int)
58
   */
59
  public T[] deserializeFromMemory(final Memory mem, final int numItems) {
60
    return deserializeFromMemory(mem, 0, numItems);
×
61
  }
62

63
  /**
64
   * Deserialize a contiguous sequence of serialized items from the given Memory
65
   * starting at the given Memory <i>offsetBytes</i> and extending numItems.
66
   *
67
   * @param mem Memory containing a contiguous sequence of serialized items
68
   * @param offsetBytes the starting offset in the given Memory.
69
   * @param numItems number of items in the contiguous serialized sequence.
70
   * @return array of deserialized items
71
   */
72
  public abstract T[] deserializeFromMemory(Memory mem, long offsetBytes, int numItems);
73

74
  /**
75
   * Returns the serialized size in bytes of a single unserialized item.
76
   * @param item a specific item
77
   * @return the serialized size in bytes of a single unserialized item.
78
   */
79
  public abstract int sizeOf(T item);
80

81
  /**
82
   * Returns the serialized size in bytes of the array of items.
83
   * @param items an array of items.
84
   * @return the serialized size in bytes of the array of items.
85
   */
86
  public int sizeOf(final T[] items) {
87
    Objects.requireNonNull(items, "Items must not be null");
1✔
88
    int totalBytes = 0;
1✔
89
    for (int i = 0; i < items.length; i++) {
1✔
90
      totalBytes += sizeOf(items[i]);
1✔
91
    }
92
    return totalBytes;
1✔
93
  }
94

95
  /**
96
   * Returns the serialized size in bytes of the number of contiguous serialized items in Memory.
97
   * The capacity of the given Memory can be much larger that the required size of the items.
98
   * @param mem the given Memory.
99
   * @param offsetBytes the starting offset in the given Memory.
100
   * @param numItems the number of serialized items contained in the Memory
101
   * @return the serialized size in bytes of the given number of items.
102
   */
103
  public abstract int sizeOf(Memory mem, long offsetBytes, int numItems);
104

105
  /**
106
   * Returns a human readable string of an item.
107
   * @param item a specific item
108
   * @return a human readable string of an item.
109
   */
110
  public abstract String toString(T item);
111

112
  /**
113
   * Returns the concrete class of type T
114
   * @return the concrete class of type T
115
   */
116
  public abstract Class<T> getClassOfT();
117
}
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