source: java/main/src/main/java/com/framsticks/util/lang/Containers.java @ 107

Last change on this file since 107 was 107, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • add SimultorProviders? hierarchy
  • start Framsticks server over SSH
  • FJF compatible with Framsticks 4.0rc3
  • reading and writing of standard.expt
  • a proof-of-concept implementation of StandardExperiment?

CHANGELOG:
Optionally return FreeAccess? from registry.

Add SimulatorRange?.

StandardExperiment? with genotypes circulation.

Automate registration around StandardState?.

More improvements to StandardExperiment?.

Skeleton version of StandardExperiment?.

Test saving of StandardState?.

Standard experiment state is being loaded.

More development towards StandardState? reading.

Work on reading standard experiment state.

Add classes for standard experiment.

Update example standard.expt

Add FreeAccess? and FreeObject?.

Made compatible with version 4.0rc3

Change deserialization policy.

Improve SSH support.

Working running simulator over SSH.

Fix joining bug in Experiment.

Working version of SimulatorRunner?.

Add more SimulatorProviders?.

Working PrimeExperimentTest? with 4.0rc3

Add references to deserialization.

Add OpaqueObject? and it's serialization.

Add deserialization of dictionaries.

Partial implementation of deserialization.

Add more tests for deserialization.

Prepare tests for deserialization.

Add proper result to prime experiment test.

Minor fixes to simulators providers.

Draft version of SimulatorProvider?.

Add SimulatorProvider? interface.

File size: 2.2 KB
Line 
1package com.framsticks.util.lang;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Iterator;
6import java.util.List;
7import java.util.Map;
8import java.util.TreeMap;
9
10import org.apache.commons.collections.functors.InstanceofPredicate;
11import org.apache.commons.collections.functors.NotPredicate;
12import org.apache.commons.collections.iterators.FilterIterator;
13
14import com.framsticks.util.Builder;
15import com.framsticks.util.FramsticksException;
16
17/**
18 * @author Piotr Sniegowski
19 */
20public abstract class Containers {
21        public static void resizeList(List<?> list, int size) {
22                while (list.size() < size) {
23                        list.add(null);
24                }
25                while (list.size() > size) {
26                        list.remove(list.size() - 1);
27                }
28        }
29
30        public static <T> Iterable<T> filterInstanceof(Iterator<? super T> i, Class<T> type) {
31                return new IterableIterator<T>(new FilterIterator(i, new InstanceofPredicate(type)));
32        }
33
34        public static <T> Iterable<T> filterInstanceof(Iterable<? super T> i, Class<T> type) {
35                return new IterableIterator<T>(new FilterIterator(i.iterator(), new InstanceofPredicate(type)));
36        }
37
38        public static <T> Iterable<T> filterInstanceof(Collection<? super T> c, Class<T> type) {
39                return new IterableIterator<T>(new FilterIterator(c.iterator(), new InstanceofPredicate(type)));
40        }
41
42        public static <T> Iterable<T> filterNotInstanceof(Collection<T> c, Class<? extends T> type) {
43                return new IterableIterator<T>(new FilterIterator(c.iterator(), new NotPredicate(new InstanceofPredicate(type))));
44        }
45
46        public static <T> T getFromList(List<T> list, int number, String name, Object context) {
47                if (number < 0 || number >= list.size()) {
48                        throw new FramsticksException().msg("invalid " + name + " number").arg("number", number).arg("in", context);
49                }
50                return list.get(number);
51        }
52
53        public static <T> List<T> build(List<? extends Builder<T>> builders) {
54                List<T> result = new ArrayList<T>();
55                for (Builder<T> builder : builders) {
56                        result.add(builder.finish());
57                }
58                return result;
59        }
60
61        @SafeVarargs
62        public static <K> Map<K, Object> buildMap(Pair<K, ? extends Object> ... pairs) {
63                Map<K, Object> map = new TreeMap<>();
64                for (Pair<K, ? extends Object> p : pairs) {
65                        map.put(p.first, p.second);
66                }
67                return map;
68        }
69}
Note: See TracBrowser for help on using the repository browser.