Skip to content

Commit

Permalink
style: reorder functions
Browse files Browse the repository at this point in the history
  • Loading branch information
shouwn committed Jan 31, 2024
1 parent bc38ac8 commit aac989d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions docs/en/jpql-with-kotlin-jdsl/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ Use the following functions to build arithmetic functions:

* ABS (abs)
* CEILING (ceiling)
* SQRT (sqrt)
* ROUND (round)
* SQRT (sqrt)

```kotlin
abs(path(Book::price))

ceiling(path(Book::price))

sqrt(path(Book::price))

round(path(Book::price), 2)

sqrt(path(Book::price))
```

| Function | DSL function |
Expand Down
6 changes: 3 additions & 3 deletions docs/ko/jpql-with-kotlin-jdsl/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,17 @@ locate("Book", path(Book::title))

* ABS (abs)
* CEILING (ceiling)
* SQRT (sqrt)
* ROUND (round)
* SQRT (sqrt)

```kotlin
abs(path(Book::price))

ceiling(path(Book::price))

sqrt(path(Book::price))

round(path(Book::price), 2)

sqrt(path(Book::price))
```

| Function | DSL function |
Expand Down
32 changes: 16 additions & 16 deletions dsl/jpql/src/main/kotlin/com/linecorp/kotlinjdsl/dsl/jpql/Jpql.kt
Original file line number Diff line number Diff line change
Expand Up @@ -568,22 +568,6 @@ open class Jpql : JpqlDsl {
return Expressions.ceiling(value.toExpression())
}

/**
* Creates an expression that represents the square root of value.
*/
@SinceJdsl("3.4.0")
fun <T : Any, V : Number> sqrt(expr: KProperty1<T, @Exact V>): Expression<Double> {
return Expressions.sqrt(Paths.path(expr))
}

/**
* Creates an expression that represents the square root of value.
*/
@SinceJdsl("3.4.0")
fun <T : Number> sqrt(value: Expressionable<T>): Expression<Double> {
return Expressions.sqrt(value.toExpression())
}

/**
* Creates an expression that represents the rounding of the value to a specified scale.
*/
Expand Down Expand Up @@ -616,6 +600,22 @@ open class Jpql : JpqlDsl {
return Expressions.round(value.toExpression(), scale.toExpression())
}

/**
* Creates an expression that represents the square root of value.
*/
@SinceJdsl("3.4.0")
fun <T : Any, V : Number> sqrt(expr: KProperty1<T, @Exact V>): Expression<Double> {
return Expressions.sqrt(Paths.path(expr))
}

/**
* Creates an expression that represents the square root of value.
*/
@SinceJdsl("3.4.0")
fun <T : Number> sqrt(value: Expressionable<T>): Expression<Double> {
return Expressions.sqrt(value.toExpression())
}

/**
* Creates an expression that represents the count of non-null values.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ object Expressions {
return JpqlCeiling(value)
}

/**
* Creates an expression that represents the rounding of the specified value to a specified scale.
*/
@SinceJdsl("3.4.0")
fun <T : Number> round(value: Expression<T>, scale: Expression<Int>): Expression<T> {
return JpqlRound(value, scale)
}

/**
* Creates an expression that represents the square root of the value.
*/
Expand Down Expand Up @@ -274,14 +282,6 @@ object Expressions {
return JpqlAvg(distinct, expr)
}

/**
* Creates an expression that represents the rounding of the specified value to a specified scale.
*/
@SinceJdsl("3.4.0")
fun <T : Number> round(value: Expression<T>, scale: Expression<Int>): Expression<T> {
return JpqlRound(value, scale)
}

/**
* Creates an expression that represents the sum of values.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,26 +363,26 @@ class ExpressionsTest : WithAssertions {
}

@Test
fun sqrt() {
fun round() {
// when
val actual = Expressions.sqrt(intExpression1)
val actual = Expressions.round(bigDecimalExpression1, intExpression1)

// then
val expected = JpqlSqrt(
val expected = JpqlRound(
bigDecimalExpression1,
intExpression1,
)

assertThat(actual).isEqualTo(expected)
}

@Test
fun round() {
fun sqrt() {
// when
val actual = Expressions.round(bigDecimalExpression1, intExpression1)
val actual = Expressions.sqrt(intExpression1)

// then
val expected = JpqlRound(
bigDecimalExpression1,
val expected = JpqlSqrt(
intExpression1,
)

Expand Down

0 comments on commit aac989d

Please sign in to comment.