Skip to content

Package: SortField

SortField

nameinstructionbranchcomplexitylinemethod
SortField()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
SortField(SortDirection, String)
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
ascending(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
descending(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getField()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getSortDirection()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
of(String, SortDirection)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: * Red Hat Inc
13: *******************************************************************************/
14: package org.eclipse.kapua.service.storable.model.query;
15:
16: import org.eclipse.kapua.service.storable.model.Storable;
17: import org.eclipse.kapua.service.storable.model.StorableListResult;
18:
19: import javax.validation.constraints.NotNull;
20:
21: /**
22: * {@link SortField} definition.
23: * <p>
24: * It defines the sorting of {@link StorableListResult} when processing {@link StorableQuery}.
25: *
26: * @since 1.0.0
27: */
28: public class SortField {
29:
30: private SortDirection sortDirection;
31: private String field;
32:
33: /**
34: * Constructor.
35: * <p>
36: * Required by JAXB.
37: *
38: * @since 1.0.0
39: */
40: public SortField() {
41: }
42:
43: /**
44: * Constructor.
45: *
46: * @param direction The {@link SortDirection}.
47: * @param field The name of the field of the {@link Storable} for which to sort.
48: * @since 1.0.0
49: */
50: private SortField(@NotNull SortDirection direction, @NotNull String field) {
51: this.sortDirection = direction;
52: this.field = field;
53: }
54:
55: /**
56: * Gets the name of the field of the {@link Storable} for which to sort.
57: *
58: * @return Tname of the field of the {@link Storable} for which to sort.
59: * @since 1.0.0
60: */
61: public String getField() {
62: return this.field;
63: }
64:
65: /**
66: * Gets the {@link SortDirection}.
67: *
68: * @return The {@link SortDirection}.
69: * @since 1.0.0
70: */
71: public SortDirection getSortDirection() {
72: return this.sortDirection;
73: }
74:
75:
76: /**
77: * Instantiates a {@link SortField} with the given parameters.
78: *
79: * @param fieldName The name of the field of the {@link Storable} for which to sort.
80: * @param direction The {@link SortDirection}.
81: * @return The newly instantiated {@link SortField}.
82: * @since 1.0.0
83: */
84: public static SortField of(@NotNull String fieldName, @NotNull SortDirection direction) {
85: return new SortField(direction, fieldName);
86: }
87:
88: /**
89: * Instantiates a {@link SortField} with {@link SortDirection#ASC}.
90: *
91: * @param fieldName The name of the field of the {@link Storable} for which to sort.
92: * @return The newly instantiated {@link SortField}.
93: * @see #of(String, SortDirection)
94: * @since 1.0.0
95: */
96: public static SortField ascending(final String fieldName) {
97: return of(fieldName, SortDirection.ASC);
98: }
99:
100: /**
101: * Instantiates a {@link SortField} with {@link SortDirection#ASC}.
102: *
103: * @param fieldName The name of the field of the {@link Storable} for which to sort.
104: * @return The newly instantiated {@link SortField}.
105: * @see #of(String, SortDirection)
106: * @since 1.0.0
107: */
108: public static SortField descending(final String fieldName) {
109: return of(fieldName, SortDirection.DESC);
110: }
111: }