Hi,

Your best shot would be to submit a PR on GitHub which includes a unit test
that exercises the new code.

https://github.com/apache/commons-collections

Thank you,
Gary

On Wed, Sep 5, 2018 at 10:12 AM Maxim Solodovnik <solomax...@gmail.com>
wrote:

> Would it be possible to modify the code of AbstractReferenceMap.java as
> follows?
>
>
> diff --git
>
> a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
>
> b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
> index 0eda632f..81f60b4b 100644
> ---
>
> a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
> +++
>
> b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
> @@ -400,13 +400,15 @@ public abstract class AbstractReferenceMap<K, V>
> extends AbstractHashedMap<K, V>
>          HashEntry<K, V> previous = null;
>          HashEntry<K, V> entry = data[index];
>          while (entry != null) {
> -            if (((ReferenceEntry<K, V>) entry).purge(ref)) {
> +            ReferenceEntry<K, V> refEntry = (ReferenceEntry<K, V>) entry;
> +            if (refEntry.purge(ref)) {
>                  if (previous == null) {
>                      data[index] = entry.next;
>                  } else {
>                      previous.next = entry.next;
>                  }
>                  this.size--;
> +                refEntry.onPurge();
>                  return;
>              }
>              previous = entry;
> @@ -721,12 +723,15 @@ public abstract class AbstractReferenceMap<K, V>
> extends AbstractHashedMap<K, V>
>              throw new Error();
>          }
>
> +        protected void onPurge() {
> +        }
> +
>          /**
>           * Purges the specified reference
>           * @param ref  the reference to purge
>           * @return true or false
>           */
> -        boolean purge(final Reference<?> ref) {
> +        protected boolean purge(final Reference<?> ref) {
>              boolean r = parent.keyType != ReferenceStrength.HARD && key ==
> ref;
>              r = r || parent.valueType != ReferenceStrength.HARD && value
> == ref;
>              if (r) {
> @@ -1073,4 +1078,17 @@ public abstract class AbstractReferenceMap<K, V>
> extends AbstractHashedMap<K, V>
>      protected boolean isKeyType(final ReferenceStrength type) {
>          return this.keyType == type;
>      }
> +
> +    /**
> +     * Provided protected read-only access to the value type.
> +     * @param type the type to check against.
> +     * @return true if valueType has the specified type
> +     */
> +    protected boolean isValueType(final ReferenceStrength type) {
> +        return this.valueType == type;
> +    }
> +
> +    public boolean isPurgeValues() {
> +        return purgeValues;
> +    }
>  }
>
>
> On Mon, 3 Sep 2018 at 20:08, Maxim Solodovnik <solomax...@gmail.com>
> wrote:
>
> > Thanks a lot for the answer,
> >
> > OpenJPA ReferenceHashMap overrides purge method to be able to call
> > custom methods keyExpired/valueExpired [1]
> > I see no way to migrate this code without massive copy/paste or
> reflection
> > ...
> >
> > Maybe you can suggest something?
> > Or maybe commons-collections API can be enhanced so this task will be
> > trivial :)
> >
> >
> >
> https://github.com/apache/openjpa/blob/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java#L138
> >
> > On Mon, 3 Sep 2018 at 20:03, Julio Oliveira
> > <julio.julioolive...@gmail.com> wrote:
> > >
> > > What is realy your problem??..
> > >
> > > On Sat, Sep 1, 2018, 5:46 AM Maxim Solodovnik <solomax...@gmail.com>
> > wrote:
> > >
> > > > Hello,
> > > >
> > > > I'm trying to migrate code of Apache OpenJPA from commons-collections
> > > > to commons-collections4
> > > >
> > > > The only real issue so far with migrating this class
> > > >
> > > >
> >
> https://github.com/apache/openjpa/blob/trunk/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/ReferenceHashMap.java#L112
> > > >
> > > > code of commons-collections4 is more restrictive could you please
> > > > suggest how custom purge can be implemented?
> > > >
> > > > --
> > > > WBR
> > > > Maxim aka solomax
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> > > > For additional commands, e-mail: user-h...@commons.apache.org
> > > >
> > > >
> >
> >
> >
> > --
> > WBR
> > Maxim aka solomax
> >
>
>
> --
> WBR
> Maxim aka solomax
>

Reply via email to