Skip to content

Commit

Permalink
Fix some miscellaneous bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kezhenxu94 committed Oct 7, 2019
1 parent 7d3b285 commit c43aeb3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public String key() {
}

public boolean sameWith(AbstractTag<T> tag) {
return canOverwrite && tag.id == tag.id;
return canOverwrite && this.id == tag.id;
}

public int getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void setTypeName(String typeName) {
case "String":
this.type = String.class;
typeName = "String";
break;
default:
try {
this.type = Class.forName(typeName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.apache.skywalking.oap.server.core.analysis.metrics.expression;

import java.util.Objects;

/**
* @author wusheng
*/
Expand All @@ -39,19 +41,19 @@ public boolean match(double left, double right) {
}

public boolean match(Integer left, Integer right) {
return left == right;
return Objects.equals(left, right);
}

public boolean match(Long left, Long right) {
return left == right;
return Objects.equals(left, right);
}

public boolean match(Float left, Float right) {
return left == right;
return Objects.equals(left, right);
}

public boolean match(Double left, Double right) {
return left == right;
return Objects.equals(left, right);
}

public boolean match(Boolean left, Boolean right) {
Expand All @@ -63,6 +65,6 @@ public boolean match(boolean left, boolean right) {
}

public boolean match(Object left, Object right) {
return left.equals(right);
return Objects.equals(left, right);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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.skywalking.oap.server.core.analysis.metrics.expression;

import org.junit.Test;

import static org.junit.Assert.*;

/**
* @author kezhenxu94
*/
public class EqualMatchTest {

@Test
public void integerShouldEqualWhenLargerThan128() {
Integer a = 334;
Integer b = 334;
boolean match = new EqualMatch().match(a, b);
assertTrue(match);
}

@Test
public void longShouldEqualWhenLargerThan128() {
Long a = 334L;
Long b = 334L;
boolean match = new EqualMatch().match(a, b);
assertTrue(match);
}

@Test
public void doubleShouldEqualWhenLargerThan128() {
Double a = 334.0;
Double b = 334.0;
boolean match = new EqualMatch().match(a, b);
assertTrue(match);
}

@Test
public void floatShouldEqualWhenLargerThan128() {
Float a = 334.0F;
Float b = 334.0F;
boolean match = new EqualMatch().match(a, b);
assertTrue(match);
}
}

0 comments on commit c43aeb3

Please sign in to comment.