Skip to content

Reduce duplication: merge trivial drivers like Auxv into single parameterized implementation #3262

Closed

Description

@dbwiddis

Problem

Several small driver classes exist as JNA/FFM pairs with only 1-2 lines of actual difference. For example:

AuxvJNA.java (44 lines) vs AuxvFFM.java (44 lines) — differ only in:

// JNA
key = FileUtilJNA.readNativeLongFromBuffer(buff).intValue();
auxvMap.put(key, FileUtilJNA.readNativeLongFromBuffer(buff).longValue());

// FFM
key = (int) FileUtilFFM.readNativeLongFromBuffer(buff);
auxvMap.put(key, FileUtilFFM.readNativeLongFromBuffer(buff));

The entire rest of the file (buffer reading loop, map construction, error handling) is identical.

Proposal

Introduce a functional interface for the native-long-reading operation:

@FunctionalInterface
interface NativeLongReader {
    long readNativeLong(ByteBuffer buffer);
}

Then provide a single Auxv implementation in oshi-common that accepts a NativeLongReader, with JNA and FFM each supplying their reader. This pattern applies to other trivially-different driver pairs as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions