Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (C) Posten Norge AS
Copyright (C) Posten Bring AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/license-header.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) Posten Norge AS
Copyright (C) Posten Bring AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggBase.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggCollectors.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggCompare.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggConcurrent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
55 changes: 54 additions & 1 deletion src/main/java/no/digipost/DiggEnums.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/
package no.digipost;

import java.util.BitSet;
import java.util.Collection;
import java.util.function.Function;
import java.util.function.Predicate;
Expand All @@ -23,6 +24,7 @@

import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.joining;

/**
Expand Down Expand Up @@ -94,6 +96,57 @@ public static <E extends Enum<E>> Stream<E> fromEnumsString(String enumsString,
}


/**
* Select enum constants by mapping <em>indexes</em> of elements in a boolean array which are {@code true} to <em>ordinals</em>
* of the enum type.
* <p>
* It is valid that the enum contains either more or less constants than the given boolean array,
* and the resolving will discard any exhaustive elements in either cases. E.g. specifying two booleans
* will at most consider two first constants of a given enum type, as well as if the enum only has one
* constant, only the first boolean will be processed.
*
* @param includedOrdinals the boolean array where the <em>indexes</em> of {@code true} elements are mapped
* to any existing ordinals of the given {@code enumType}
* @param enumType the enum type to resolve constants from
*
* @return the resolved {@code enum} constants
*/
public static <E extends Enum<E>> Stream<E> selectByIndexAsOrdinals(boolean[] includedOrdinals, Class<E> enumType) {
BitSet mask = new BitSet(includedOrdinals.length);
for (int i = 0; i < includedOrdinals.length; i++) {
mask.set(i, includedOrdinals[i]);
}
return selectByBitmask(mask, enumType);
}


/**
* Select enum constants by overlaying a bitmask ({@code long}) and selecting the enum <em>by ordinals</em>
* which align with the indices of the set bits, mapping the first index to the first enum constant and so
* forth. A bitmask of {@code 10110001} (177) will select the first, fifth, sixth, and eight enum constant.
* <p>
* It is valid both for the enum to contain more constants than the length of the mask,
* or less constants than the highest index of a <em>set</em> bit in the given mask,
* and the resolving will discard any exhaustive elements in either cases. E.g. a set bit at
* index 2 will be ignored for enums with only one constant.
*
* @param mask the bit mask used for selecting enum constants, the method may mutate this mask
* @param enumType the enum type to resolve constants from
*
* @return the resolved {@code enum} constants
*/
public static <E extends Enum<E>> Stream<E> selectByBitmask(BitSet mask, Class<E> enumType) {
if (mask.cardinality() == 0) {
return Stream.empty();
}
E[] candidates = requireNonNull(enumType.getEnumConstants(), enumType + " is not an enum");
if (candidates.length == 0) {
return Stream.empty();
}
return mask.get(0, candidates.length).stream().mapToObj(selectedOrdinal -> candidates[selectedOrdinal]);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeg skjønner åpenbart ikke hvordan dette virker… vil ikke selectedOrdnial alltid bare være 0 eller 1?

Copy link
Member Author

@runeflobakk runeflobakk Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ja, den er sneaky 😅
Et BitSet er ikke en Collection (eller java.util.Set), det er en helt standalone struktur for å behandle bit-sekvenser.

BitSet.stream() gir ikke hvert av elementene i bit-sekvensen, altså en strøm med 0-er og 1-ere og som typisk ville vært ekvivalent til å kalle .stream() på en collection, men (hold deg fast) indeksene til de bit-ene som er satt, altså hvilke bits som er 1. Dette gir altså en strøm-linjeformet (høhø) tilgang til hvilke bits som er "påskrudd", fremfor å selv traversere alle bits, holde styr på hvilke posisjon man er på og sjekke 0 vs. 1 etc.

Edit: Det som kanskje ikke er åpenbart her heller, er at BitSet.get(0, candidates.length) gir et nytt BitSet, og ikke en collection hvor man får det antallet første bits man spesifiserer, også kaller .stream() på en sånn collection.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BitSet.stream() gir ikke hvert av elementene i bit-sekvensen, altså en strøm med 0-er og 1-ere […], men […] indeksene til de bit-ene som er satt, altså hvilke bits som er 1.

Da gir det straks mer mening! 💡

}


/**
* Join several {@code enum} constants to a comma separated string of their {@link Enum#name() names}.
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggExceptions.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggIO.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggMaps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggOptionals.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggPredicates.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/DiggStreams.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/collection/BatchedIterable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/collection/NonEmptyList.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/collection/SimpleIterator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/concurrent/CountDown.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/concurrent/OneTimeToggle.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/concurrent/SignalMediator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/concurrent/TargetState.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/concurrent/Waiter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/DecaFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/HexaFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/NonaFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/ObjIntFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/ObjLongFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/OctoFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/PentaFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/QuadFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/SeptiFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/ThrowingBiConsumer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/ThrowingBiFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/ThrowingConsumer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/ThrowingFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/ThrowingRunnable.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/ThrowingSupplier.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/digipost/function/TriFunction.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) Posten Norge AS
* Copyright (C) Posten Bring AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading