Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
YczYanchengzhe committed Sep 2, 2021
1 parent 60827a6 commit a7447af
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ literalExpression
;

expression
: booleanMatch | intMatch | stringMatch | greaterMatch | lessMatch | greaterEqualMatch | lessEqualMatch | notEqualMatch | booleanNotEqualMatch | likeMatch | inMatch | containMatch | notContainMatch
: booleanMatch | numberMatch | stringMatch | greaterMatch | lessMatch | greaterEqualMatch | lessEqualMatch | notEqualMatch | booleanNotEqualMatch | likeMatch | inMatch | containMatch | notContainMatch
;

containMatch
Expand All @@ -108,7 +108,7 @@ booleanMatch
: conditionAttributeStmt DUALEQUALS booleanConditionValue
;

intMatch
numberMatch
: conditionAttributeStmt DUALEQUALS numberConditionValue
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public void enterBooleanMatch(OALParser.BooleanMatchContext ctx) {
}

@Override
public void enterIntMatch(OALParser.IntMatchContext ctx) {
conditionExpression.setExpressionType("intMatch");
public void enterNumberMatch(OALParser.NumberMatchContext ctx) {
conditionExpression.setExpressionType("numberMatch");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@
import org.apache.skywalking.oap.server.core.analysis.metrics.annotation.FilterMatcher;

@FilterMatcher
public class IntMatch {
public class NumberMatch {

public boolean match(int left, int right) {
return left == right;
}

public boolean match(Integer left, Integer right) {
public boolean match(long left, long right) {
return left == right;
}

public boolean match(float left, float right) {
return left == right;
}

public boolean match(Number left, Number right) {
return left.equals(right);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* 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.assertTrue;
import static org.junit.Assert.assertFalse;

public class NumberMatchTest {

@Test
public void integerShouldEqual() {
Integer a = 334;
Integer b = 334;
boolean match = new NumberMatch().match(a, b);
assertTrue(match);

a = -123;
b = -123;
match = new NumberMatch().match(a, b);
assertTrue(match);

a = -122;
b = -123;
match = new NumberMatch().match(a, b);
assertFalse(match);

a = -123;
b = -122;
match = new NumberMatch().match(a, b);
assertFalse(match);
}

@Test
public void intShouldEqual() {
int a = 334;
int b = 334;
boolean match = new NumberMatch().match(a, b);
assertTrue(match);

a = -123;
b = -123;
match = new NumberMatch().match(a, b);
assertTrue(match);

a = -122;
b = -123;
match = new NumberMatch().match(a, b);
assertFalse(match);

a = -123;
b = -122;
match = new NumberMatch().match(a, b);
assertFalse(match);
}

@Test
public void longShouldEqual() {
long a = 21474836478L;
long b = 21474836478L;
boolean match = new NumberMatch().match(a, b);
assertTrue(match);

a = -21474836478L;
b = -21474836479L;
match = new NumberMatch().match(a, b);
assertFalse(match);

Long c = -123L;
Long d = -123L;
match = new NumberMatch().match(c, d);
assertTrue(match);

c = -21474836478L;
d = -21474836479L;
match = new NumberMatch().match(c, d);
assertFalse(match);
}

@Test
public void doubleShouldEqual() {
Double a = 334.0;
Double b = 334.0;
boolean match = new NumberMatch().match(a, b);
assertTrue(match);

double c = 334.0;
double d = 334.0;
match = new NumberMatch().match(c, d);
assertTrue(match);
}

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

float c = 334.0F;
float d = 334.0F;
match = new NumberMatch().match(c, d);
assertTrue(match);
}

}

0 comments on commit a7447af

Please sign in to comment.