Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5323 from bjhargrave/issues/5322
resource: Defer SHA-256 calculation into the future
- Loading branch information
Showing
16 changed files
with
483 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
biz.aQute.bnd.util/src/aQute/bnd/unmodifiable/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
@Version("2.0.0") | ||
@Version("2.1.0") | ||
package aQute.bnd.unmodifiable; | ||
|
||
import org.osgi.annotation.versioning.Version; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
biz.aQute.bndlib/src/aQute/bnd/osgi/resource/DeferredComparableValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package aQute.bnd.osgi.resource; | ||
|
||
import java.util.function.Supplier; | ||
|
||
class DeferredComparableValue<T extends Comparable<T>> extends DeferredValue<T> implements Comparable<T> { | ||
|
||
DeferredComparableValue(Class<T> type, Supplier<? extends T> supplier, int hashCode) { | ||
super(type, supplier, hashCode); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public int compareTo(T o) { | ||
if (o instanceof DeferredComparableValue) { | ||
o = ((DeferredComparableValue<T>) o).get(); | ||
} | ||
return get().compareTo(o); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
biz.aQute.bndlib/src/aQute/bnd/osgi/resource/DeferredValue.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package aQute.bnd.osgi.resource; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.function.Supplier; | ||
|
||
class DeferredValue<T> implements Supplier<T> { | ||
private final Class<T> type; | ||
private final Supplier<? extends T> supplier; | ||
private final int hashCode; | ||
private T value; | ||
|
||
DeferredValue(Class<T> type, Supplier<? extends T> supplier, int hashCode) { | ||
this.type = requireNonNull(type); | ||
this.supplier = requireNonNull(supplier); | ||
this.hashCode = hashCode; | ||
} | ||
|
||
@Override | ||
public T get() { | ||
T v = value; | ||
if (v == null) { | ||
return value = supplier.get(); | ||
} | ||
return v; | ||
} | ||
|
||
Class<T> type() { | ||
return type; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return hashCode; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj instanceof DeferredValue) { | ||
obj = ((DeferredValue<T>) obj).get(); | ||
} | ||
return get().equals(obj); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.valueOf(get()); | ||
} | ||
} |
Oops, something went wrong.