brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Introduce a type registry as a si...
Date Mon, 02 Nov 2015 16:16:35 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/993#discussion_r43645927
  
    --- Diff: core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypeConstraints.java
---
    @@ -0,0 +1,156 @@
    +/*
    + * 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 javax.annotation.Nullable;
    +
    +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);
    +    
    +    /** Immutable (from caller's perspective) record of a constraint */
    +    public final static class BasicRegisteredTypeConstraint implements RegisteredTypeConstraint
{
    +        private RegisteredTypeKind kind;
    +        private Class<?> javaSuperType;
    +        private Set<String> encounteredTypes;
    +        
    +        private BasicRegisteredTypeConstraint() {}
    +        
    +        public BasicRegisteredTypeConstraint(@Nullable 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<String> getEncounteredTypes() {
    +            if (encounteredTypes==null) return ImmutableSet.of();
    +            return ImmutableSet.<String>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<String> encounteredTypeSymbolicNames)
{
    +        BasicRegisteredTypeConstraint result = new BasicRegisteredTypeConstraint();
    +        result.encounteredTypes = encounteredTypeSymbolicNames == null ? ImmutableSet.<String>of()
: ImmutableSet.copyOf(encounteredTypeSymbolicNames);
    --- End diff --
    
    there may be places where we pass around the set of visited places and some might be null;
agree callers should generally avoid nulls for this but i prefer code being defensive here


---
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.
---

Mime
View raw message