X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FVariablesImpl.java;h=db0e836b9de91de187015ff34960b7feed80f4c8;hb=1ecae6e1ad40507badb8807fb14bb67b4adf199c;hp=f861edb357c2b6f065036ddd5f5ee4cb3d6abfac;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariablesImpl.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariablesImpl.java index f861edb35..db0e836b9 100644 --- a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariablesImpl.java +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariablesImpl.java @@ -1,49 +1,49 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.layer0.variable; - -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; - -public final class VariablesImpl { - - public final static int nextSeparator(String path, int startPosition) { - int len = path.length(); - for (int i = startPosition; i < len; ++i) { - char c = path.charAt(i); - if (c == '/' || c == '#') - return i; - } - return -1; - } - - public final static Resource getFirst(ReadGraph graph, Resource type, String path, int startPosition) throws DatabaseException { - - int position = nextSeparator(path, startPosition); - if (position == -1) { - Resource r = graph.getResource(path); - if (graph.isInstanceOf(r, type)) - return r; - return null; - } - - Resource r = graph.getResource(path.substring(0, position)); - if (graph.isInstanceOf(r, type)) { - return r; - } else { - return getFirst(graph, type, path, position + 1); - } - - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.layer0.variable; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; + +public final class VariablesImpl { + + public final static int nextSeparator(String path, int startPosition) { + int len = path.length(); + for (int i = startPosition; i < len; ++i) { + char c = path.charAt(i); + if (c == '/' || c == '#') + return i; + } + return -1; + } + + public final static Resource getFirst(ReadGraph graph, Resource type, String path, int startPosition) throws DatabaseException { + + int position = nextSeparator(path, startPosition); + if (position == -1) { + Resource r = graph.getResource(path); + if (graph.isInstanceOf(r, type)) + return r; + return null; + } + + Resource r = graph.getResource(path.substring(0, position)); + if (graph.isInstanceOf(r, type)) { + return r; + } else { + return getFirst(graph, type, path, position + 1); + } + + } + +}