Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f2ea7ed

Browse files
committedAug 28, 2024·
[NOID] Update argument descriptions for APOC Functions
1 parent 337cd10 commit f2ea7ed

35 files changed

+7269
-363
lines changed
 

‎core/src/main/java/apoc/agg/CollAggregation.java

+19-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ public static class NthFunction {
6060
private int index;
6161

6262
@UserAggregationUpdate
63-
public void nth(@Name("value") Object value, @Name("offset") long target) {
63+
public void nth(
64+
@Name(value = "value", description = "A value to be aggregated.") Object value,
65+
@Name(
66+
value = "offset",
67+
description = "The index of the value to be returned, or -1 to return the last item.")
68+
long target) {
6469
if (value != null) {
6570
if (target == index++ || target == -1) {
6671
this.value = value;
@@ -81,9 +86,17 @@ public static class SliceFunction {
8186

8287
@UserAggregationUpdate
8388
public void nth(
84-
@Name("value") Object value,
85-
@Name(value = "from", defaultValue = "0") long from,
86-
@Name(value = "to", defaultValue = "-1") long len) {
89+
@Name(value = "value", description = "A value to be multiplied in the aggregate.") Object value,
90+
@Name(
91+
value = "from",
92+
defaultValue = "0",
93+
description = "The index from which to start returning values in the specified range.")
94+
long from,
95+
@Name(
96+
value = "to",
97+
defaultValue = "-1",
98+
description = "The non-inclusive index of the final value in the range.")
99+
long len) {
87100
if (value != null) {
88101
if (index >= from && (len == -1 || index < from + len)) {
89102
this.values.add(value);
@@ -102,7 +115,7 @@ public static class FirstFunction {
102115
private Object value;
103116

104117
@UserAggregationUpdate
105-
public void first(@Name("value") Object value) {
118+
public void first(@Name(value = "value", description = "A value to be aggregated.") Object value) {
106119
if (value != null && this.value == null) {
107120
this.value = value;
108121
}
@@ -118,7 +131,7 @@ public static class LastFunction {
118131
private Object value;
119132

120133
@UserAggregationUpdate
121-
public void last(@Name("value") Object value) {
134+
public void last(@Name(value = "value", description = "A value to be aggregated.") Object value) {
122135
if (value != null) {
123136
this.value = value;
124137
}

‎core/src/main/java/apoc/agg/Graph.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public static class GraphAggregation {
4848
private Set<Relationship> plainRels = new HashSet<>();
4949

5050
@UserAggregationUpdate
51-
public void aggregate(@Name("path") Object element) {
51+
public void aggregate(
52+
@Name(value = "path", description = "A path to return nodes and relationships from.") Object element) {
5253
consume(element);
5354
}
5455

‎core/src/main/java/apoc/agg/MaxAndMinItems.java

+55-13
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,83 @@ public class MaxAndMinItems {
5353
@UserAggregationFunction("apoc.agg.maxItems")
5454
@Description(
5555
"Returns a `MAP` `{items: LIST<ANY>, value: ANY}` where the `value` key is the maximum value present, and `items` represent all items with the same value. The size of the list of items can be limited to a given max size.")
56-
public MaxOrMinItemsFunction maxItems() {
57-
return new MaxOrMinItemsFunction(true);
56+
public MaxItemsFunction maxItems() {
57+
return new MaxItemsFunction();
5858
}
5959

6060
@UserAggregationFunction("apoc.agg.minItems")
6161
@Description(
6262
"Returns a `MAP` `{items: LIST<ANY>, value: ANY}` where the `value` key is the minimum value present, and `items` represent all items with the same value. The size of the list of items can be limited to a given max size.")
63-
public MaxOrMinItemsFunction minItems() {
64-
return new MaxOrMinItemsFunction(false);
63+
public MinItemsFunction minItems() {
64+
return new MinItemsFunction();
6565
}
6666

67-
public static class MaxOrMinItemsFunction {
67+
public static class MaxItemsFunction {
6868
private final List<Object> items = new ArrayList<>();
69-
private final boolean isMax;
7069
private Comparable value;
7170

72-
private MaxOrMinItemsFunction(boolean isMax) {
73-
this.isMax = isMax;
71+
private MaxItemsFunction() {}
72+
73+
@UserAggregationUpdate
74+
public void maxOrMinItems(
75+
@Name(value = "item", description = "A value to be aggregated.") final Object item,
76+
@Name(value = "value", description = "The value from which the max is selected.")
77+
final Object inputValue,
78+
@Name(
79+
value = "groupLimit",
80+
defaultValue = "-1",
81+
description = "The limit on the number of items returned.")
82+
final Long groupLimitParam) {
83+
int groupLimit = groupLimitParam.intValue();
84+
boolean noGroupLimit = groupLimit < 0;
85+
86+
if (item != null && inputValue != null) {
87+
int result = value == null ? -1 : value.compareTo(inputValue);
88+
if (result == 0) {
89+
if (noGroupLimit || items.size() < groupLimit) {
90+
items.add(item);
91+
}
92+
} else if (result < 0) {
93+
// xnor logic, interested value should replace current value
94+
items.clear();
95+
items.add(item);
96+
value = (Comparable) inputValue;
97+
}
98+
}
7499
}
75100

101+
@UserAggregationResult
102+
public Object result() {
103+
return Util.map("items", items, "value", value);
104+
}
105+
}
106+
107+
public static class MinItemsFunction {
108+
private final List<Object> items = new ArrayList<>();
109+
private Comparable value;
110+
111+
private MinItemsFunction() {}
112+
76113
@UserAggregationUpdate
77114
public void maxOrMinItems(
78-
@Name("items") final Object item,
79-
@Name("value") final Object inputValue,
80-
@Name(value = "groupLimit", defaultValue = "-1") final Long groupLimitParam) {
115+
@Name(value = "item", description = "A value to be aggregated.") final Object item,
116+
@Name(value = "value", description = "The value from which the min is selected.")
117+
final Object inputValue,
118+
@Name(
119+
value = "groupLimit",
120+
defaultValue = "-1",
121+
description = "The limit on the number of items returned.")
122+
final Long groupLimitParam) {
81123
int groupLimit = groupLimitParam.intValue();
82124
boolean noGroupLimit = groupLimit < 0;
83125

84126
if (item != null && inputValue != null) {
85-
int result = value == null ? (isMax ? -1 : 1) : value.compareTo(inputValue);
127+
int result = value == null ? 1 : value.compareTo(inputValue);
86128
if (result == 0) {
87129
if (noGroupLimit || items.size() < groupLimit) {
88130
items.add(item);
89131
}
90-
} else if (result < 0 == isMax) {
132+
} else if (result >= 0) {
91133
// xnor logic, interested value should replace current value
92134
items.clear();
93135
items.add(item);

‎core/src/main/java/apoc/agg/Median.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static class MedianFunction {
3838
private List<Double> values = new ArrayList<>();
3939

4040
@UserAggregationUpdate
41-
public void aggregate(@Name("value") Object value) {
41+
public void aggregate(@Name(value = "value", description = "A value to be aggregated.") Object value) {
4242
if (value instanceof Number) {
4343
values.add(((Number) value).doubleValue());
4444
}

‎core/src/main/java/apoc/agg/Percentiles.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ public static class PercentilesFunction {
4646

4747
@UserAggregationUpdate
4848
public void aggregate(
49-
@Name("value") Number value,
50-
@Name(value = "percentiles", defaultValue = "[0.5,0.75,0.9,0.95,0.99]") List<Double> percentiles) {
49+
@Name(value = "value", description = "A value to be aggregated.") Number value,
50+
@Name(
51+
value = "percentiles",
52+
defaultValue = "[0.5,0.75,0.9,0.95,0.99]",
53+
description = "The percentiles from which the values are obtained.")
54+
List<Double> percentiles) {
5155
if (value != null) {
5256
if (doubles != null) {
5357
doubles.recordValue(value.doubleValue());

‎core/src/main/java/apoc/agg/Product.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public static class ProductFunction {
3838
private int count = 0;
3939

4040
@UserAggregationUpdate
41-
public void aggregate(@Name("value") Number number) {
41+
public void aggregate(
42+
@Name(value = "value", description = "A value to be multiplied in the aggregate.") Number number) {
4243
if (number != null) {
4344
if (number instanceof Long) {
4445
longProduct = Math.multiplyExact(longProduct, number.longValue());

‎core/src/main/java/apoc/agg/Statistics.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ public static class StatisticsFunction {
5050

5151
@UserAggregationUpdate
5252
public void aggregate(
53-
@Name("value") Number value,
54-
@Name(value = "percentiles", defaultValue = "[0.5,0.75,0.9,0.95,0.99]") List<Double> percentiles) {
53+
@Name(value = "value", description = "A value to be aggregated.") Number value,
54+
@Name(
55+
value = "percentiles",
56+
defaultValue = "[0.5,0.75,0.9,0.95,0.99]",
57+
description = "The percentiles from which the values are obtained.")
58+
List<Double> percentiles) {
5559
if (value != null) {
5660
if (doubles != null) {
5761
doubles.recordValue(value.doubleValue());

‎core/src/main/java/apoc/bitwise/BitwiseOperations.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ public class BitwiseOperations {
3030

3131
@UserFunction("apoc.bitwise.op")
3232
@Description("Returns the result of the bitwise operation")
33-
public Long op(@Name("a") final Long a, @Name("operator") final String operator, @Name("b") final Long b)
33+
public Long op(
34+
@Name(value = "a", description = "The lefthand side value of the bitwise operation.") final Long a,
35+
@Name(value = "operator", description = "The type of bitwise operation to perform.") final String operator,
36+
@Name(value = "b", description = "The righthand side value of the bitwise operation.") final Long b)
3437
throws Exception {
3538
if (a == null || operator == null || operator.isEmpty()) {
3639
return null;

0 commit comments

Comments
 (0)
Please sign in to comment.