Skip to content

Commit

Permalink
Inheritance in DefaulQualifierAndValue (#6639)
Browse files Browse the repository at this point in the history
* resolves issue#6630
  • Loading branch information
trentjeff authored Apr 17, 2023
1 parent c8b9513 commit 14ae10c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected DefaultQualifierAndValue(Builder b) {
*/
public static DefaultQualifierAndValue createNamed(String name) {
Objects.requireNonNull(name);
return (DefaultQualifierAndValue) builder().typeName(CommonQualifiers.NAMED).value(name).build();
return builder().typeName(CommonQualifiers.NAMED).value(name).build();
}

/**
Expand All @@ -61,7 +61,7 @@ public static DefaultQualifierAndValue createNamed(String name) {
*/
public static DefaultQualifierAndValue create(Class<? extends Annotation> qualifierType) {
Objects.requireNonNull(qualifierType);
return (DefaultQualifierAndValue) builder().typeName(DefaultTypeName.create(qualifierType)).build();
return builder().typeName(DefaultTypeName.create(qualifierType)).build();
}

/**
Expand All @@ -73,7 +73,7 @@ public static DefaultQualifierAndValue create(Class<? extends Annotation> qualif
*/
public static DefaultQualifierAndValue create(Class<? extends Annotation> qualifierType, String val) {
Objects.requireNonNull(qualifierType);
return (DefaultQualifierAndValue) builder().typeName(DefaultTypeName.create(qualifierType)).value(val).build();
return builder().typeName(DefaultTypeName.create(qualifierType)).value(val).build();
}

/**
Expand All @@ -84,7 +84,7 @@ public static DefaultQualifierAndValue create(Class<? extends Annotation> qualif
* @return qualifier
*/
public static DefaultQualifierAndValue create(String qualifierTypeName, String val) {
return (DefaultQualifierAndValue) builder()
return builder()
.typeName(DefaultTypeName.createFromTypeName(qualifierTypeName))
.value(val)
.build();
Expand All @@ -98,7 +98,7 @@ public static DefaultQualifierAndValue create(String qualifierTypeName, String v
* @return qualifier
*/
public static DefaultQualifierAndValue create(TypeName qualifierType, String val) {
return (DefaultQualifierAndValue) builder()
return builder()
.typeName(qualifierType)
.value(val)
.build();
Expand All @@ -112,7 +112,7 @@ public static DefaultQualifierAndValue create(TypeName qualifierType, String val
* @return qualifier
*/
public static DefaultQualifierAndValue create(TypeName qualifierType, Map<String, String> vals) {
return (DefaultQualifierAndValue) builder()
return builder()
.typeName(qualifierType)
.values(vals)
.build();
Expand Down Expand Up @@ -162,6 +162,30 @@ public static class Builder extends DefaultAnnotationAndValue.Builder {
protected Builder() {
}

@Override
public Builder typeName(TypeName val) {
super.typeName(val);
return this;
}

@Override
public Builder value(String val) {
super.value(val);
return this;
}

@Override
public Builder values(Map<String, String> val) {
super.values(val);
return this;
}

@Override
public Builder type(Class<? extends Annotation> annoType) {
super.type(annoType);
return this;
}

/**
* Build the instance.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
*
* Licensed 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 io.helidon.pico.api;

import io.helidon.common.types.DefaultAnnotationAndValue;

import jakarta.inject.Named;
import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

class DefaultQualifierAndValueTest {

@Test
void buildAndCompare() {
DefaultQualifierAndValue qav1 = DefaultQualifierAndValue.builder()
.type(Named.class)
.value("x.y")
.build();
DefaultAnnotationAndValue qav2 = DefaultQualifierAndValue.builder()
.type(Named.class)
.value("x.y")
.build();
assertThat(qav1.compareTo(qav2),
is(0));
}

}

0 comments on commit 14ae10c

Please sign in to comment.