| 1 | /******************************************************************************* |
| 2 | * Copyright (c) 2016 EfficiOS Inc., Alexandre Montplaisir |
| 3 | * |
| 4 | * All rights reserved. This program and the accompanying materials are |
| 5 | * made available under the terms of the Eclipse Public License v1.0 which |
| 6 | * accompanies this distribution, and is available at |
| 7 | * http://www.eclipse.org/legal/epl-v10.html |
| 8 | *******************************************************************************/ |
| 9 | |
| 10 | package org.eclipse.tracecompass.internal.provisional.tmf.core.views.timegraph2; |
| 11 | |
| 12 | import java.util.ArrayList; |
| 13 | import java.util.Collections; |
| 14 | import java.util.List; |
| 15 | |
| 16 | import com.google.common.collect.ImmutableList; |
| 17 | |
| 18 | public class TimeGraphTreeModel { |
| 19 | |
| 20 | private final List<TimeGraphTreeElement> fTreeElements = Collections.synchronizedList(new ArrayList<>()); |
| 21 | |
| 22 | public TimeGraphTreeModel() { |
| 23 | } |
| 24 | |
| 25 | public int getNbElements() { |
| 26 | return fTreeElements.size(); |
| 27 | } |
| 28 | |
| 29 | public void addElement(TimeGraphTreeElement element) { |
| 30 | fTreeElements.add(element); |
| 31 | } |
| 32 | |
| 33 | public TimeGraphTreeRender getSnapshot() { |
| 34 | /* Safe to use concurrently */ |
| 35 | List<TimeGraphTreeElement> list = ImmutableList.copyOf(fTreeElements); |
| 36 | return new TimeGraphTreeRender(list); |
| 37 | } |
| 38 | } |