]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scenegraph.profile/src/org/simantics/scenegraph/profile/request/RuntimeProfileActiveEntries.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.scenegraph.profile / src / org / simantics / scenegraph / profile / request / RuntimeProfileActiveEntries.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.scenegraph.profile.request;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Comparator;
18
19 import org.simantics.db.ReadGraph;
20 import org.simantics.db.Resource;
21 import org.simantics.db.common.request.ResourceRead;
22 import org.simantics.db.exception.DatabaseException;
23 import org.simantics.scenegraph.profile.ProfileEntry;
24
25 /**
26  * @author Antti Villberg
27  */
28 public class RuntimeProfileActiveEntries extends ResourceRead<Collection<ProfileEntry>> {
29
30         private static Comparator<ProfileEntry> COMPARATOR = new Comparator<ProfileEntry>() {
31
32                 @Override
33                 public int compare(ProfileEntry arg0, ProfileEntry arg1) {
34                         return Double.compare(arg0.getPriority(), arg1.getPriority());
35                 }
36                 
37         };
38         
39     public RuntimeProfileActiveEntries(Resource resource) {
40         super(resource);
41     }
42
43     @Override
44     public Collection<ProfileEntry> perform(ReadGraph graph) throws DatabaseException {
45         ArrayList<ProfileEntry> result = new ArrayList<ProfileEntry>();
46         for (Resource entry : graph.syncRequest(new RuntimeProfileActiveEntryResources(resource))) {
47             result.add(graph.adapt(entry, ProfileEntry.class));
48         }
49         Collections.sort(result, COMPARATOR);
50 //        for(ProfileEntry e : result) System.err.println("-RuntimeProfileActiveEntries: " + e + " " + e.getPriority());
51         return result;
52     }
53
54 }