X-Git-Url: http://git.osdn.net/view?p=delesterandomselector%2FDelesteRandomSelector.git;a=blobdiff_plain;f=src%2Fcom%2Franfa%2Flib%2Fcalc%2FPRPCalc.java;fp=src%2Fcom%2Franfa%2Flib%2Fcalc%2FPRPCalc.java;h=d105dfe1e2847811ac7624581af778b9fe9175b3;hp=d895a01faa1af472d8dfd9b04612baef7873003d;hb=d8f427ee5a252c12f81461f9d0340fa4cebf280f;hpb=20783ecbfe9d2cabecf532711b61652c0a0cc546 diff --git a/src/com/ranfa/lib/calc/PRPCalc.java b/src/com/ranfa/lib/calc/PRPCalc.java index d895a01..d105dfe 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); return scoreDecimal.divide(THAUSAND, RoundingMode.DOWN).intValueExact();