From 7a93c1b112587ad2226e1515b195ded7d45a972d Mon Sep 17 00:00:00 2001 From: hizumiaoba <56146205+hizumiaoba@users.noreply.github.com> Date: Wed, 13 Apr 2022 21:45:38 +0900 Subject: [PATCH] doc: update docment --- src/com/ranfa/lib/calc/FanCalc.java | 47 ++++++++++++++- src/com/ranfa/lib/calc/PRPCalc.java | 66 ++++++++++++++++++++++ .../ranfa/lib/concurrent/CountedThreadFactory.java | 42 ++++++++++++++ 3 files changed, 153 insertions(+), 2 deletions(-) diff --git a/src/com/ranfa/lib/calc/FanCalc.java b/src/com/ranfa/lib/calc/FanCalc.java index 9ea5411..a6a1728 100644 --- a/src/com/ranfa/lib/calc/FanCalc.java +++ b/src/com/ranfa/lib/calc/FanCalc.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022 the original author or authors. + * + * 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 + * + * https://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 com.ranfa.lib.calc; import java.math.BigDecimal; @@ -17,21 +33,29 @@ import com.ranfa.lib.concurrent.CountedThreadFactory; * ファン計算用とのライブラリ * ファン数計算とスコア計算を実装 * @author hizum - * + * + * @since 4.0.0 */ public class FanCalc { + // Logger private static final Logger logger = LoggerFactory.getLogger(FanCalc.class); + /** + * 非同期処理用のスレッドプール + */ private static final ExecutorService async = Executors.newCachedThreadPool(new CountedThreadFactory(() -> "DRS", "FanCalcThread", false)); /** * 計算式は * 端数切り上げ(スコア*0.001*ルーム補正値*センター、ゲスト効果補正値*プロデュース方針補正値) * ルーム、センター、ゲスト、プロデュース方針の補正値は百分率。計算時に自動で変換します + * * @param score ライブで獲得したスコアを入力します * @param room ルームアイテムによる補正値を百分率のまま(xxx%)入力します * @param center センター、ゲスト効果による補正値を百分率のまま入力します * @param produce プロデュース方針による補正値を百分率のまま入力します + * @param premium プレミアムパスによる補正値を百分率のまま入力します + * * @return 一人あたりの獲得ファン数。1回のライブで獲得出来るファン数はこの値の5倍です */ public static int fan(int score, int room, int center, int produce, int premium) { @@ -55,6 +79,19 @@ public class FanCalc { return (resPremiumed.compareTo(BigDecimal.ZERO) == 0) || (resPremiumed == null) ? 0 : Integer.parseInt(resPremiumed.toString()); } + /** + * 計算式は + * 端数切り上げ(スコア*0.001*ルーム補正値*センター、ゲスト効果補正値*プロデュース方針補正値) + * ルーム、センター、ゲスト、プロデュース方針の補正値は百分率。計算時に自動で変換します + * + * @param score スコア + * @param room ルーム補正値 + * @param center センターアイドル補正値 + * @param produce プロデュース方針補正値 + * @param premium プレミアムパス補正値 + * + * @return 一人当たりの獲得ファン数がラップされているCompletableFuture + */ public static CompletableFuture fanAsync(int score, int room, int center, int produce, int premium) { return CompletableFuture.supplyAsync(() -> fan(score, room, center, produce, premium), async); } @@ -62,25 +99,31 @@ public class FanCalc { /** * 目標スコアを計算。 * 初期実装の思想は並列処理による再帰計算。 + * * @param fan 目標ファン * @param multiplier LIVEの繰り返し回数 * @param room ルームアイテム補正値(百分率) * @param center センター、ゲスト効果による補正値 * @param produce プロデュース方針にとる補正値 * @param premium プレミアムパスによる補正値 - * @return LIVE一回当たりの目標スコア + * + * @return LIVE一回当たりの目標スコアがラップされているCompletableFuture */ public static CompletableFuture scoreAsync(int fan, int multiplier, int room, int center, int produce, int premium) { return CompletableFuture.supplyAsync(() -> score(fan, multiplier, room, center, produce, premium), async); } /** + * 目標スコアを計算。 + * 初期実装の思想は並列処理による再帰計算。 + * * @param fan 目標ファン * @param multiplier LIVEの繰り返し回数 * @param room ルームアイテム補正値(百分率) * @param center センター、ゲスト効果による補正値 * @param produce プロデュース方針にとる補正値 * @param premium プレミアムパスによる補正値 + * * @return LIVE一回当たりの目標スコア */ private static int score(int fan, int multiplier, int room, int center, int produce, int premium) { diff --git a/src/com/ranfa/lib/calc/PRPCalc.java b/src/com/ranfa/lib/calc/PRPCalc.java index db47b85..339ce46 100644 --- a/src/com/ranfa/lib/calc/PRPCalc.java +++ b/src/com/ranfa/lib/calc/PRPCalc.java @@ -1,3 +1,20 @@ +/* + * Copyright 2022 the original author or authors. + * + * 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 + * + * https://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 com.ranfa.lib.calc; import java.io.IOException; @@ -13,16 +30,43 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +/** + * PRPの計算ライブラリ。 + * PRPの保管も兼ねています。 + * + * @author Ranfa + * + *@since 4.0.0 + */ public class PRPCalc { + // Logger private final Logger logger = LoggerFactory.getLogger(PRPCalc.class); + /** + * PRPを保管しているファイルパス + */ private static final String PRP_STORAGE_FILE_PATH = "generated/prp.json"; + + /** + * 計算用のBigDecimal値 + */ private static final BigDecimal THAUSAND = BigDecimal.valueOf(1000); + /** + * 合計PRP値を計算するために保管しているPRPのList + */ private List TotalPRPList; + /** + * 合計PRP値 + */ private int TotalPRP; + /** + * コンストラクタ。 + *

+ * 合計PRP値の算出に必要な値を読み出し、Listへ詰め込むまでを行います。 + */ public PRPCalc() { if(Files.notExists(Paths.get(PRP_STORAGE_FILE_PATH))) generateEmptyPRPFile(); @@ -35,6 +79,13 @@ public class PRPCalc { TotalPRP = calcCurrentTotal(); } + /** + * 内容が空のPRP保管ファイルを生成します。 + *

+ * ファイルを生成するのみで内容の書き込みはしません。 + * + * @return ファイルの生成に成功した場合はtrue、それ以外はfalse + */ public boolean generateEmptyPRPFile() { if(Files.notExists(Paths.get("generated"))) try { @@ -47,6 +98,10 @@ public class PRPCalc { return true; } + /** + * {@link #TotalPRPList} を参照して現在時点の合計を算出します。 + * @return 現在時点の合計PRP + */ public int calcCurrentTotal() { int res = 0; for(int val : TotalPRPList) @@ -54,10 +109,21 @@ public class PRPCalc { return res; } + /** + * {@link #TotalPRP} を返します + * @return {@link #TotalPRP}の値 + */ public int getTotalPRP() { return TotalPRP; } + /** + * 入力されたスコアからPRPを計算します。 + *

+ * PRPは「端数切捨て(スコア×0.001)」になります + * @param score 計算するスコア + * @return 入力から計算したPRP値 + */ public static int calcPRPFromScore(int score) { BigDecimal scoreDecimal = BigDecimal.valueOf(score); scoreDecimal.divide(THAUSAND, RoundingMode.DOWN); diff --git a/src/com/ranfa/lib/concurrent/CountedThreadFactory.java b/src/com/ranfa/lib/concurrent/CountedThreadFactory.java index 170b677..8c3903b 100644 --- a/src/com/ranfa/lib/concurrent/CountedThreadFactory.java +++ b/src/com/ranfa/lib/concurrent/CountedThreadFactory.java @@ -1,3 +1,20 @@ +/* + * Copyright 2022 the original author or authors. + * + * 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 + * + * https://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 com.ranfa.lib.concurrent; import java.util.concurrent.ThreadFactory; @@ -6,13 +23,38 @@ import java.util.function.Supplier; import lombok.NonNull; +/** + * ワーカースレッド用のスレッドファクトリー。 + * + * @author Ranfa + * + *@since 4.0.0 + */ public class CountedThreadFactory implements ThreadFactory { + /** + * スレッド識別用のsupplier + */ private final Supplier identifier; + + /** + * スレッドの作業内容の識別用文字列 + */ private String specifier; + + /** + * ワーカーカウント用のカウンター + */ private final AtomicLong count = new AtomicLong(1); + + /** + * デーモン識別用のBoolean + */ private final boolean isDaemon; + /** + * + */ public CountedThreadFactory() { this(() -> "Default", "Thread"); } -- 2.11.0