Skip to content

Commit

Permalink
OPENNLP-421 - Updates JavaDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
rzo1 committed Dec 18, 2023
1 parent e597dc6 commit 11526c5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ private static String generateRandomString(int length) {

return randomString.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import java.util.concurrent.ThreadLocalRandom;

import opennlp.tools.commons.Internal;
import opennlp.tools.commons.ThreadSafe;

/**
* A {@link StringInterner} (more a deduplication) implementation by Aleksey Shipilëv
* with relaxed canonical requirements. Default probability is set to <code>0.5</code>.
* A {@link StringInterner} implementation by Aleksey Shipilëv with relaxed canonical requirements.
* It is a probabilistic deduplication implementation with a default probability of {@code 0.5}.
* Users may implement a custom class with a different probability value.
* <p>
* Origin:
Expand All @@ -34,6 +35,7 @@
* <p>
*/
@Internal
@ThreadSafe
class CHMStringDeduplicator implements StringInterner {

private final int prob;
Expand All @@ -43,6 +45,9 @@ public CHMStringDeduplicator() {
this(0.5);
}

/**
* @param prob represents the probability, that a given String will be interned
*/
public CHMStringDeduplicator(double prob) {
this.prob = (int) (Integer.MIN_VALUE + prob * (1L << 32));
this.map = new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
import java.util.concurrent.ConcurrentHashMap;

import opennlp.tools.commons.Internal;
import opennlp.tools.commons.ThreadSafe;

/**
* A {@link StringInterner}implementation by Aleksey Shipilëv.
* A {@link StringInterner} implementation based on {@link ConcurrentHashMap} by Aleksey Shipilëv.
* <p>
* Origin:
* <a href="https://shipilev.net/jvm/anatomy-quarks/10-string-intern/">
* https://shipilev.net/jvm/anatomy-quarks/10-string-intern/</a>
* <p>
*/
@Internal
@ThreadSafe
class CHMStringInterner implements StringInterner {
private final Map<String, String> map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import opennlp.tools.commons.Internal;

/**
* A {@link StringInterner} implementation by Aleksey Shipilëv.
* A {@link StringInterner} implementation based on {@link HashMap} by Aleksey Shipilëv.
* This implementation is <b>not</b> thread-safe.
* <p>
* Origin:
* <a href="https://shipilev.net/jvm/anatomy-quarks/10-string-intern/">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package opennlp.tools.util.jvm;

import opennlp.tools.commons.Internal;
import opennlp.tools.commons.ThreadSafe;

/**
* A {@link StringInterner} implementation based on String.intern().
* A {@link StringInterner} implementation based on {@code String.intern()}.
*/
@Internal
@ThreadSafe
class JvmStringInterner implements StringInterner {
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
package opennlp.tools.util.jvm;

import opennlp.tools.commons.Internal;
import opennlp.tools.commons.ThreadSafe;

/**
* A no-op {@link StringInterner} implementation, which does not intern.
* It just returns the input as is.
*/
@Internal
@ThreadSafe
class NoOpStringInterner implements StringInterner {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@

/**
* Provides string interning utility methods. Interning mechanism can be configured via the
* system property <code>opennlp.interner.class</code> by specifying an implementation via its
* full qualified classname. It needs to implement the interface {@link StringInterner}.
* system property {@code opennlp.interner.class} by specifying an implementation via its
* full qualified classname. It needs to implement {@link StringInterner}.
* <p>
* If not specified by the user, the default interner
* implementation {@link CHMStringInterner} is used.
* If not specified by the user, the default interner is {@link CHMStringInterner}.
*/
public class StringInterners {

Expand All @@ -41,8 +40,8 @@ public class StringInterners {
CHMStringInterner.class.getCanonicalName());

try {
Class<?> clazz = Class.forName(clazzName);
Constructor<?> cons = clazz.getDeclaredConstructor();
final Class<?> clazz = Class.forName(clazzName);
final Constructor<?> cons = clazz.getDeclaredConstructor();
INTERNER = (StringInterner) cons.newInstance();
LOGGER.debug("Using '{}' as String interner implementation.", clazzName);
} catch (Exception e) {
Expand Down

0 comments on commit 11526c5

Please sign in to comment.