vcollections

Lightweight observable collections (used by VMF and VRL)

License

License

GroupId

GroupId

eu.mihosoft.vcollections
ArtifactId

ArtifactId

vcollections
Last Version

Last Version

0.3.3
Release Date

Release Date

Type

Type

jar
Description

Description

vcollections
Lightweight observable collections (used by VMF and VRL)
Project URL

Project URL

https://github.com/miho/VCollections
Source Code Management

Source Code Management

https://github.com/miho/VCollections.git

Download vcollections

How to add to project

<!-- https://jarcasting.com/artifacts/eu.mihosoft.vcollections/vcollections/ -->
<dependency>
    <groupId>eu.mihosoft.vcollections</groupId>
    <artifactId>vcollections</artifactId>
    <version>0.3.3</version>
</dependency>
// https://jarcasting.com/artifacts/eu.mihosoft.vcollections/vcollections/
implementation 'eu.mihosoft.vcollections:vcollections:0.3.3'
// https://jarcasting.com/artifacts/eu.mihosoft.vcollections/vcollections/
implementation ("eu.mihosoft.vcollections:vcollections:0.3.3")
'eu.mihosoft.vcollections:vcollections:jar:0.3.3'
<dependency org="eu.mihosoft.vcollections" name="vcollections" rev="0.3.3">
  <artifact name="vcollections" type="jar" />
</dependency>
@Grapes(
@Grab(group='eu.mihosoft.vcollections', module='vcollections', version='0.3.3')
)
libraryDependencies += "eu.mihosoft.vcollections" % "vcollections" % "0.3.3"
[eu.mihosoft.vcollections/vcollections "0.3.3"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

VCollections

Build Status Download Javadocs

Lightweight observable collections (used by VMF and VRL).

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
        System.out.println(">> add one collection of elements without notification");
        vList.addAll(Arrays.asList(4, 5, 6));
    }
}

Observing Unmodifiable Lists

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);
        
        // How to make the list unmodifiable and still listen to changes?
        // THIS DOES NOT WORK: VList.newInstance(Collections.unmodifiableList(list));
        VList<Integer> vListUnmodifiable = vList.asUnmodifiable();

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

        // add element and generate event
        vList.add(1);

        // modifying the unmodifiable list results in RuntimeException...
        vListUnmodifiable.add(37);
        
    }
}

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

Versions

Version
0.3.3
0.3.1
0.3
0.2.1
0.2.0
0.0.9
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1