-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
advanced unmodifiable support for change aware containers
- Loading branch information
Showing
11 changed files
with
826 additions
and
603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.m-m-m</groupId> | ||
<artifactId>mmm-value-parent</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<artifactId>mmm-value-observable</artifactId> | ||
<packaging>jar</packaging> | ||
<name>${project.artifactId}</name> | ||
<description>Java module providing observable values.</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mmm-value</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mmm-event</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.github.m-m-m</groupId> | ||
<artifactId>mmm-value-parent</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
<artifactId>mmm-value-observable</artifactId> | ||
<packaging>jar</packaging> | ||
<name>${project.artifactId}</name> | ||
<description>Java module providing observable values.</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mmm-value</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mmm-event</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>mmm-base</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
173 changes: 94 additions & 79 deletions
173
observable/src/main/java/io/github/mmm/value/observable/container/list/ChangeAwareLists.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,94 @@ | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.value.observable.container.list; | ||
|
||
import java.util.List; | ||
|
||
import io.github.mmm.value.observable.container.list.impl.ChangeAwareListImpl; | ||
import io.github.mmm.value.observable.container.list.impl.EmptyChangeAwareList; | ||
import io.github.mmm.value.observable.container.list.impl.ImmutableChangeAwareList; | ||
|
||
/** | ||
* Factory for {@link ChangeAwareList}. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public final class ChangeAwareLists { | ||
|
||
private ChangeAwareLists() { | ||
|
||
super(); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @return an empty, immutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> empty() { | ||
|
||
return EmptyChangeAwareList.INSTANCE; | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @return a new empty mutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> of() { | ||
|
||
return new ChangeAwareListImpl<>(); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @param capacity the initial capacity of the list. | ||
* @return a new empty mutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> of(int capacity) { | ||
|
||
return new ChangeAwareListImpl<>(capacity); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @param list the existing {@link List} implementation to wrap as {@link ChangeAwareList}. Please avoid to modify | ||
* this {@link List} afterwards, as this will not trigger modification events. | ||
* @return a new empty mutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> of(List<E> list) { | ||
|
||
if (list instanceof ChangeAwareList) { | ||
return (ChangeAwareList<E>) list; | ||
} | ||
return new ChangeAwareListImpl<>(list); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @param list the existing {@link List} implementation to wrap as {@link ChangeAwareList}. Please avoid to modify | ||
* this {@link List} afterwards, as this will not trigger modification events. | ||
* @return a new empty mutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> ofUnmodifiable(List<E> list) { | ||
|
||
if (list instanceof ImmutableChangeAwareList) { | ||
return (ChangeAwareList<E>) list; | ||
} | ||
return new ImmutableChangeAwareList<>(list); | ||
} | ||
|
||
} | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.value.observable.container.list; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import io.github.mmm.value.observable.container.list.impl.ChangeAwareListImpl; | ||
import io.github.mmm.value.observable.container.list.impl.EmptyChangeAwareList; | ||
import io.github.mmm.value.observable.container.list.impl.ImmutableChangeAwareList; | ||
import io.github.mmm.value.observable.container.list.impl.ImmutableChangeAwareListView; | ||
|
||
/** | ||
* Factory for {@link ChangeAwareList}. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public final class ChangeAwareLists { | ||
|
||
private ChangeAwareLists() { | ||
|
||
super(); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @return an empty, immutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> empty() { | ||
|
||
return EmptyChangeAwareList.INSTANCE; | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @return a new empty mutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> of() { | ||
|
||
return new ChangeAwareListImpl<>(); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @param capacity the initial capacity of the list. | ||
* @return a new empty mutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> of(int capacity) { | ||
|
||
return new ChangeAwareListImpl<>(capacity); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @param list the existing {@link List} implementation to wrap as {@link ChangeAwareList}. Please avoid to modify | ||
* this {@link List} afterwards, as this will not trigger modification events. | ||
* @return a new empty mutable {@link ChangeAwareList}. | ||
*/ | ||
public static <E> ChangeAwareList<E> of(List<E> list) { | ||
|
||
if (list instanceof ChangeAwareList) { | ||
return (ChangeAwareList<E>) list; | ||
} | ||
return new ChangeAwareListImpl<>(list); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @param list the existing {@link List} implementation to wrap as {@link ChangeAwareList}. Modifying such | ||
* {@link List} afterwards will not trigger modification events in the read-only view returned by this method. | ||
* @return a unmodifiable {@link ChangeAwareList} that acts as a view on the given {@link List}. | ||
*/ | ||
public static <E> ChangeAwareList<E> ofUnmodifiable(List<E> list) { | ||
|
||
if (list instanceof ImmutableChangeAwareList<E> result) { | ||
return result; | ||
} | ||
return new ImmutableChangeAwareList<>(list); | ||
} | ||
|
||
/** | ||
* @param <E> the type of the elements. | ||
* @param listSupplier the {@link Supplier} to the (mutable) {@link List} implementation to wrap as | ||
* {@link ChangeAwareList}. Modifying such {@link List} afterwards will not trigger modification events in the | ||
* read-only view returned by this method. | ||
* @return a unmodifiable {@link ChangeAwareList} that acts as a view on the {@link Supplier#get() supplied} | ||
* {@link List}. | ||
*/ | ||
public static <E> ChangeAwareList<E> ofUnmodifiable(Supplier<List<E>> listSupplier) { | ||
|
||
return new ImmutableChangeAwareListView<>(listSupplier); | ||
} | ||
|
||
} |
130 changes: 65 additions & 65 deletions
130
...ain/java/io/github/mmm/value/observable/container/list/impl/ImmutableChangeAwareList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.value.observable.container.list.impl; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Immutable implementation of {@link io.github.mmm.value.observable.container.list.ChangeAwareList}. | ||
* | ||
* @param <E> the type of the elements in the container. | ||
* @since 1.0.0 | ||
*/ | ||
public class ImmutableChangeAwareList<E> extends ReadOnlyChangeAwareList<E> { | ||
|
||
private final List<E> list; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param list the internal {@link List} to adopt. | ||
*/ | ||
public ImmutableChangeAwareList(List<E> list) { | ||
|
||
super(); | ||
this.list = list; | ||
} | ||
|
||
@Override | ||
public E get(int index) { | ||
|
||
return this.list.get(index); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
|
||
return this.list.size(); | ||
} | ||
|
||
@Override | ||
public int indexOf(Object element) { | ||
|
||
return this.list.indexOf(element); | ||
} | ||
|
||
@Override | ||
public int lastIndexOf(Object element) { | ||
|
||
return this.list.lastIndexOf(element); | ||
} | ||
|
||
@Override | ||
public boolean contains(Object element) { | ||
|
||
return this.list.contains(element); | ||
} | ||
|
||
@Override | ||
public boolean containsAll(Collection<?> collection) { | ||
|
||
return this.list.containsAll(collection); | ||
} | ||
|
||
} | ||
/* Copyright (c) The m-m-m Team, Licensed under the Apache License, Version 2.0 | ||
* http://www.apache.org/licenses/LICENSE-2.0 */ | ||
package io.github.mmm.value.observable.container.list.impl; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* Immutable implementation of {@link io.github.mmm.value.observable.container.list.ChangeAwareList}. | ||
* | ||
* @param <E> the type of the elements in the container. | ||
* @since 1.0.0 | ||
*/ | ||
public class ImmutableChangeAwareList<E> extends ReadOnlyChangeAwareList<E> { | ||
|
||
private final List<E> list; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param list the internal {@link List} to adopt. | ||
*/ | ||
public ImmutableChangeAwareList(List<E> list) { | ||
|
||
super(); | ||
this.list = list; | ||
} | ||
|
||
@Override | ||
public E get(int index) { | ||
|
||
return this.list.get(index); | ||
} | ||
|
||
@Override | ||
public int size() { | ||
|
||
return this.list.size(); | ||
} | ||
|
||
@Override | ||
public int indexOf(Object element) { | ||
|
||
return this.list.indexOf(element); | ||
} | ||
|
||
@Override | ||
public int lastIndexOf(Object element) { | ||
|
||
return this.list.lastIndexOf(element); | ||
} | ||
|
||
@Override | ||
public boolean contains(Object element) { | ||
|
||
return this.list.contains(element); | ||
} | ||
|
||
@Override | ||
public boolean containsAll(Collection<?> collection) { | ||
|
||
return this.list.containsAll(collection); | ||
} | ||
|
||
} |
Oops, something went wrong.