rename DhApiResult.errorMessage -> message
This commit is contained in:
@@ -6,15 +6,18 @@ package com.seibel.lod.api.objects;
|
||||
* @param <T> The payload type this result contains, can be Void if the result is just used to notify success/failure.
|
||||
*
|
||||
* @author James Seibel
|
||||
* @version 2022-11-12
|
||||
* @version 2022-11-24
|
||||
*/
|
||||
public class DhApiResult<T>
|
||||
{
|
||||
/** True if the action succeeded, false otherwise. */
|
||||
public final boolean success;
|
||||
|
||||
/** If the action failed this contains the reason as to why. */
|
||||
public final String errorMessage; // TODO rename to just "message"
|
||||
/**
|
||||
* If the action failed this will contain the reason as to why. <br>
|
||||
* If the action was successful this will generally be the empty string.
|
||||
*/
|
||||
public final String message;
|
||||
|
||||
/**
|
||||
* Whatever object the API Method generated/returned. <br>
|
||||
@@ -25,19 +28,20 @@ public class DhApiResult<T>
|
||||
|
||||
|
||||
// these constructors are private because the create... methods below are easier to understand
|
||||
private DhApiResult(boolean newSuccess, String newErrorMessage) { this(newSuccess, newErrorMessage, null); }
|
||||
private DhApiResult(boolean newSuccess, String newErrorMessage, T payload)
|
||||
private DhApiResult(boolean success, String message) { this(success, message, null); }
|
||||
private DhApiResult(boolean success, String message, T payload)
|
||||
{
|
||||
this.success = newSuccess;
|
||||
this.errorMessage = newErrorMessage;
|
||||
this.success = success;
|
||||
// don't allow null messages, in the case of a null message return the empty string to prevent potential null pointers
|
||||
this.message = (message == null) ? "" : message;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <Pt> DhApiResult<Pt> createSuccess() { return new DhApiResult<>(true, ""); }
|
||||
public static <Pt> DhApiResult<Pt> createSuccess(String message) { return new DhApiResult<>(true, message); }
|
||||
public static <Pt> DhApiResult<Pt> createSuccess(Pt payload) { return new DhApiResult<Pt>(true, "", payload); }
|
||||
// There is no createSuccess(String message) method because it would be too easy to confuse with createSuccess(Pt payload) when returning null
|
||||
public static <Pt> DhApiResult<Pt> createSuccess(String message, Pt payload) { return new DhApiResult<Pt>(true, message, payload); }
|
||||
|
||||
public static <Pt> DhApiResult<Pt> createFail() { return new DhApiResult<>(false, ""); }
|
||||
|
||||
+4
-11
@@ -11,10 +11,7 @@ import com.seibel.lod.core.datatype.ILodDataSource;
|
||||
import com.seibel.lod.core.datatype.full.FullDataPoint;
|
||||
import com.seibel.lod.core.datatype.full.FullDataPointIdMap;
|
||||
import com.seibel.lod.core.datatype.full.accessor.SingleFullArrayView;
|
||||
import com.seibel.lod.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.lod.core.level.DhClientServerLevel;
|
||||
import com.seibel.lod.core.level.IDhLevel;
|
||||
import com.seibel.lod.core.pos.DhBlockPos;
|
||||
import com.seibel.lod.core.pos.DhLodPos;
|
||||
import com.seibel.lod.core.pos.DhSectionPos;
|
||||
import com.seibel.lod.core.util.*;
|
||||
@@ -22,15 +19,11 @@ import com.seibel.lod.core.util.math.Vec3d;
|
||||
import com.seibel.lod.core.util.math.Vec3f;
|
||||
import com.seibel.lod.core.util.math.Vec3i;
|
||||
import com.seibel.lod.core.wrapperInterfaces.block.IBlockStateWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.minecraft.IMinecraftRenderWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IBiomeWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.IClientLevelWrapper;
|
||||
import com.seibel.lod.core.wrapperInterfaces.world.ILevelWrapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
@@ -117,11 +110,11 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
|
||||
DhApiResult<DhApiTerrainDataPoint[]> result = getTerrainDataColumnArray(levelWrapper, requestedColumnPos, blockYPos);
|
||||
if (result.success && result.payload.length > 0)
|
||||
{
|
||||
return DhApiResult.createSuccess(result.errorMessage, result.payload[0]);
|
||||
return DhApiResult.createSuccess(result.message, result.payload[0]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return DhApiResult.createFail(result.errorMessage);
|
||||
return DhApiResult.createFail(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,7 +149,7 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
|
||||
}
|
||||
else
|
||||
{
|
||||
return DhApiResult.createFail(result.errorMessage, returnArray);
|
||||
return DhApiResult.createFail(result.message, returnArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -330,7 +323,7 @@ public class DhApiTerrainDataRepo implements IDhApiTerrainDataRepo
|
||||
if (!result.success)
|
||||
{
|
||||
// if there was an error, stop and return it
|
||||
return DhApiResult.createFail(result.errorMessage);
|
||||
return DhApiResult.createFail(result.message);
|
||||
}
|
||||
|
||||
// is there a LOD at this position?
|
||||
|
||||
Reference in New Issue
Block a user