X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FVariableOrResource.java;fp=bundles%2Forg.simantics.db.layer0%2Fsrc%2Forg%2Fsimantics%2Fdb%2Flayer0%2Fvariable%2FVariableOrResource.java;h=1c35049a93048c32a303ad920936dc22fb235141;hb=545538ee3a2353eee994042800e6e5393177f858;hp=0000000000000000000000000000000000000000;hpb=5b0c7af1c0845daa63a2ab7600a460a6573c6a56;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java new file mode 100644 index 000000000..1c35049a9 --- /dev/null +++ b/bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/variable/VariableOrResource.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2019 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: + * Semantum Oy - initial API and implementation + *******************************************************************************/ +package org.simantics.db.layer0.variable; + +import org.simantics.db.Resource; + +/** + * An interface to match the VariableOrResource SCL data type + * which represents either a Resource or a Variable. Allows + * defining SCL classes with either of the two as a input. + * + * @author Antti Villberg + * @since 1.40.0 + */ +public interface VariableOrResource { + + public static VariableOrResource make(Resource value) { + return new ResourceX(value); + } + + public static VariableOrResource make(Variable value) { + return new VariableX(value); + } + + public static VariableOrResource make(Object value) { + if(value instanceof Resource) + return make((Resource)value); + if(value instanceof Variable) + return make((Variable)value); + throw new IllegalArgumentException("VariableOrResource acccepts only Variable or Resource, got " + value + " with class " + value.getClass().getName()); + } + +}