Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EA2A218498 for ; Mon, 2 Nov 2015 13:57:31 +0000 (UTC) Received: (qmail 95374 invoked by uid 500); 2 Nov 2015 13:57:31 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 95341 invoked by uid 500); 2 Nov 2015 13:57:31 -0000 Mailing-List: contact dev-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list dev@brooklyn.incubator.apache.org Received: (qmail 95330 invoked by uid 99); 2 Nov 2015 13:57:31 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Nov 2015 13:57:31 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 2F9AE1A2BF7 for ; Mon, 2 Nov 2015 13:57:31 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.971 X-Spam-Level: X-Spam-Status: No, score=0.971 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id o2P9IS-9mY4X for ; Mon, 2 Nov 2015 13:57:22 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 14D1E211D3 for ; Mon, 2 Nov 2015 13:57:20 +0000 (UTC) Received: (qmail 94767 invoked by uid 99); 2 Nov 2015 13:57:20 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Nov 2015 13:57:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id F2F9CE04D7; Mon, 2 Nov 2015 13:57:19 +0000 (UTC) From: neykov To: dev@brooklyn.incubator.apache.org Reply-To: dev@brooklyn.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-brooklyn pull request: Introduce a type registry as a si... Content-Type: text/plain Message-Id: <20151102135719.F2F9CE04D7@git1-us-west.apache.org> Date: Mon, 2 Nov 2015 13:57:19 +0000 (UTC) Github user neykov commented on a diff in the pull request: https://github.com/apache/incubator-brooklyn/pull/993#discussion_r43629895 --- Diff: core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeConstraints.java --- @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.brooklyn.core.typereg; + +import groovy.xml.Entity; + +import java.util.Set; + +import org.apache.brooklyn.api.entity.EntitySpec; +import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec; +import org.apache.brooklyn.api.objs.BrooklynObject; +import org.apache.brooklyn.api.objs.BrooklynObjectType; +import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry.RegisteredTypeKind; +import org.apache.brooklyn.api.typereg.RegisteredTypeConstraint; +import org.apache.brooklyn.util.collections.MutableSet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.ImmutableSet; + +public class RegisteredTypeConstraints { + + private static final Logger log = LoggerFactory.getLogger(RegisteredTypeConstraints.BasicRegisteredTypeConstraint.class); + + public final static class BasicRegisteredTypeConstraint implements RegisteredTypeConstraint { + private RegisteredTypeKind kind; + private Class javaSuperType; + private Set encounteredTypes; + + private BasicRegisteredTypeConstraint() {} + + public BasicRegisteredTypeConstraint(RegisteredTypeConstraint source) { + if (source==null) return; + + this.kind = source.getKind(); + this.javaSuperType = source.getJavaSuperType(); + this.encounteredTypes = source.getEncounteredTypes(); + } + + @Override + public RegisteredTypeKind getKind() { + return kind; + } + + @Override + public Class getJavaSuperType() { + if (javaSuperType==null) return Object.class; + return javaSuperType; + } + + @Override + public Set getEncounteredTypes() { + if (encounteredTypes==null) return ImmutableSet.of(); + return ImmutableSet.copyOf(encounteredTypes); + } + + @Override + public String toString() { + return super.toString()+"["+kind+","+javaSuperType+","+encounteredTypes+"]"; + } + } + + /** returns a constraint which allows anything */ + public static RegisteredTypeConstraint any() { + return new BasicRegisteredTypeConstraint(); + } + + public static RegisteredTypeConstraint alreadyVisited(Set encounteredTypeSymbolicNames) { + BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint(); + result.encounteredTypes = encounteredTypeSymbolicNames; + return result; + } + public static RegisteredTypeConstraint alreadyVisited(Set encounteredTypeSymbolicNames, String anotherEncounteredType) { + BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint(); + result.encounteredTypes = MutableSet.copyOf(encounteredTypeSymbolicNames); + if (anotherEncounteredType!=null) result.encounteredTypes.add(anotherEncounteredType); + return result; + } + + private static RegisteredTypeConstraint of(RegisteredTypeKind kind, Class javaSuperType) { + BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint(); + result.kind = kind; + result.javaSuperType = javaSuperType; + return result; + } + + public static RegisteredTypeConstraint spec(Class javaSuperType) { + return of(RegisteredTypeKind.SPEC, javaSuperType); + } + + public static > RegisteredTypeConstraint extendedWithSpecSuperType(RegisteredTypeConstraint source, Class specSuperType) { + Class superType = lookupTargetTypeForSpec(specSuperType); + BasicRegisteredTypeConstraint constraint = new BasicRegisteredTypeConstraint(source); + if (source==null) source = constraint; --- End diff -- Mark `source` as `@Nullable` --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---