8000 GitHub - miho/VCollections at v0.2.0
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

miho/VCollections

Repository files navigation

VCollections

Build Status Download

Lightweight observable collections (used by VMF and VRL).

UPDATE 1: we might switch to another event API. Expect changes...

UPDATE 2: we are almost done...

Features

  • Observable List
  • Mapped List (keeps two lists with different element types in sync)
  • coming sooner or later: ObservableMap and ObservableSet

Code Sample

Observing Changes

public class Main {
    public static void main(String[] args) {
        // creates an ordinary list
        List<Integer> list = new ArrayList<>();

        // to make the list observable, we wrap it in a VList
        VList<Integer> vList = VList.newInstance(list);

        // to get notified, we add a change listener to the VList
        Subscription subscription = vList.addChangeListener((evt) -> {
            // for now, we just print the changes
            System.out.println(EventUtil.toStringWithDetails(evt));
        });

        // add individual elements (generates 3 events)
        System.out.println(">> add 3 individual elements");
        vList.add(1);
        vList.add(2);
        vList.add(3);

        // add collection of elements (generates only one event)
        System.out.println(">> add one collection of elements");
        vList.addAll(Arrays.asList(4, 5, 6));

        // remove individual elements (generates 3 events)
        System.out.println(">> remove 3 individual elements");
        vList.remove((Integer) 1);
        vList.remove((Integer) 2);
        vList.remove((Integer) 3);

        // remove collection of elements (generates only one event)
        System.out.println(">> remove one collection of elements");
        vList.removeAll(Arrays.asList(4,5,6));
        
        // unsubscribe the listener from vList
        subscription.unsubscribe();
        
        // add elements without generating events
        Syste
780F
m.out.println(">> add one collection of elements without notification");
        vList.addAll(Arrays.asList(4, 5, 6));
    }
}

How to Build VCollections

Requirements

  • Java >= 1.8
  • Internet connection (dependencies are downloaded automatically)
  • IDE: Gradle Plugin (not necessary for command line usage)

IDE

Open the VCollections Gradle project in your favourite IDE (tested with NetBeans 8.2) and build it by calling the assemble task.

Command Line

Navigate to the Gradle project (e.g., path/to/VCollections) and enter the following command

Bash (Linux/OS X/Cygwin/other Unix-like shell)

bash gradlew assemble

Windows (CMD)

gradlew assemble

About

Lightweight observable collections (used by VMF and VRL)

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0