]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/request/ResourceSetURIs.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / request / ResourceSetURIs.java
1 /*******************************************************************************
2  * Copyright (c) 2019 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  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.common.request;
13
14 import java.util.Collections;
15 import java.util.Set;
16
17 import org.simantics.db.ReadGraph;
18 import org.simantics.db.Resource;
19 import org.simantics.db.exception.DatabaseException;
20
21 import gnu.trove.set.hash.THashSet;
22
23 /**
24  * @author Tuukka Lehtonen
25  * @since 1.41.0, 1.35.2
26  */
27 public class ResourceSetURIs extends UnaryRead<Set<Resource>, Set<String>> {
28
29     public ResourceSetURIs(Set<Resource> set) {
30         super(set);
31     }
32
33     @Override
34     public Set<String> perform(ReadGraph graph) throws DatabaseException {
35         if (parameter == null || parameter.isEmpty())
36             return Collections.emptySet();
37
38         Set<String> result = new THashSet<String>(parameter.size());
39         for (Resource r : parameter) {
40             String uri = graph.getPossibleURI(r);
41             if (uri != null)
42                 result.add(uri);
43         }
44
45         return result;
46     }
47
48 }