Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
MappedList.java
Go to the documentation of this file.
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6
7package org.sleuthkit.autopsy.timeline.utils;
8
9import java.util.ArrayList;
10import java.util.List;
11import java.util.function.Function;
12import javafx.collections.ListChangeListener;
13import javafx.collections.ObservableList;
14import javafx.collections.transformation.TransformationList;
15
19public class MappedList<E, F> extends TransformationList<E, F> {
20 private final Function<F, E> mapper;
21
22 public MappedList(ObservableList<? extends F> source, Function<F, E> mapper) {
23 super(source);
24 this.mapper = mapper;
25 }
26
27 @Override
28 public int getSourceIndex(int index) {
29 return index;
30 }
31
32 @Override
33 public E get(int index) {
34 return mapper.apply(getSource().get(index));
35 }
36
37 @Override
38 public int size() {
39 return getSource().size();
40 }
41
42 @Override
43 protected void sourceChanged(ListChangeListener.Change<? extends F> c) {
44 fireChange(new ListChangeListener.Change<E>(this) {
45 @Override
46 public boolean wasAdded() {
47 return c.wasAdded();
48 }
49
50 @Override
51 public boolean wasRemoved() {
52 return c.wasRemoved();
53 }
54
55 @Override
56 public boolean wasReplaced() {
57 return c.wasReplaced();
58 }
59
60 @Override
61 public boolean wasUpdated() {
62 return c.wasUpdated();
63 }
64
65 @Override
66 public boolean wasPermutated() {
67 return c.wasPermutated();
68 }
69
70 @Override
71 public int getPermutation(int i) {
72 return c.getPermutation(i);
73 }
74
75 @Override
76 protected int[] getPermutation() {
77 // This method is only called by the superclass methods
78 // wasPermutated() and getPermutation(int), which are
79 // both overriden by this class. There is no other way
80 // this method can be called.
81 throw new AssertionError("Unreachable code");
82 }
83
84 @Override
85 public List<E> getRemoved() {
86 ArrayList<E> res = new ArrayList<>(c.getRemovedSize());
87 for (F e : c.getRemoved()) {
88 res.add(mapper.apply(e));
89 }
90 return res;
91 }
92
93 @Override
94 public int getFrom() {
95 return c.getFrom();
96 }
97
98 @Override
99 public int getTo() {
100 return c.getTo();
101 }
102
103 @Override
104 public boolean next() {
105 return c.next();
106 }
107
108 @Override
109 public void reset() {
110 c.reset();
111 }
112 });
113 }
114
115 @Override
116 public int getViewIndex(int index) {
117 return index;
118 }
119
120}
MappedList(ObservableList<? extends F > source, Function< F, E > mapper)
void sourceChanged(ListChangeListener.Change<? extends F > c)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.