Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing of object labels #30

Open
orionll opened this issue Mar 9, 2021 · 0 comments
Open

Allow customizing of object labels #30

orionll opened this issue Mar 9, 2021 · 0 comments

Comments

@orionll
Copy link

orionll commented Mar 9, 2021

Proposal

Can we add methods like:

// Set the same label for all objects of the given class
public LJV setClassLabel(Class<?> cz, String label);

// Set a label for an individual object of the given class
public <T> LJV setObjectLabelProvider(Class<T> cz, ObjectLabelProvider<T> labelProvider);

// Set a label for individual objects of the given class (only if it's a specific field)
public <T> LJV setObjectLabelProvider(Field field, Class<T> cz, ObjectLabelProvider<T> labelProvider);
@FunctionalInterface
public interface ObjectLabelProvider<T> {
    String getLabel(T obj);
}

Examples

var p = new SimpleImmutableEntry(1, 2);
browse(new LJV().setClassLabel(SimpleImmutableEntry.class, "Entry"), p);

class_label

var list = new ArrayList<>();
list.add(1);
list.add(2);
browse(new LJV()
        .setTreatAsPrimitive(Integer.class)
        .setObjectLabelProvider(ArrayList.class, lst -> lst.getClass().getName() + "@" + System.identityHashCode(lst)),
        list);

class_label

var string = "hello";
browse(new LJV()
        .setObjectLabelProvider(String.class, str -> str)
        .setObjectLabelProvider(byte.class, b -> "0x" + Integer.toHexString(Byte.toUnsignedInt(b))),
        string);

string

Issues

  • Primitives. Should we add IntLabelProvider, LongLabelProvider, ByteLabelProvider or use setObjectLabelProvider(int.class, (Integer x) -> )?
  • Inheritance. Should setClassLabel(List.class, ...) work only for List or ArrayList, LinkedList and other subclasses?
@orionll orionll mentioned this issue Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant