-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Created physical property enum type to replace string (#1149)
* feat: Created physical property enum type to replace string * test: add test * feat: support the old names * doc
- Loading branch information
1 parent
e8e19d8
commit 793eea2
Showing
20 changed files
with
276 additions
and
117 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/main/java/neqsim/physicalproperties/PhysicalPropertyType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package neqsim.physicalproperties; | ||
|
||
import neqsim.util.exception.InvalidInputException; | ||
|
||
/** | ||
* Types of PhysicalProperties, e.g. mass density, dynamic viscosity, thermal conductivity. | ||
* | ||
* @author ASMF | ||
*/ | ||
|
||
public enum PhysicalPropertyType { | ||
MASS_DENSITY, DYNAMIC_VISCOSITY, THERMAL_CONDUCTIVITY; | ||
|
||
// We know we'll never mutate this, so we can keep | ||
// a local copy for fast lookup in byName | ||
private static final PhysicalPropertyType[] copyOfValues = values(); | ||
|
||
/** | ||
* Get PhysicalPropertyType by name. | ||
* | ||
* @param name Name to get PhysicalPropertyType for. | ||
* @return PhysicalPropertyType object | ||
*/ | ||
public static PhysicalPropertyType byName(String name) { | ||
// suport old names | ||
name = name.toUpperCase(); | ||
if (name.equals("DENSITY")) { | ||
name = "MASS_DENSITY"; | ||
} | ||
if (name.equals("VISCOSITY")) { | ||
name = "DYNAMIC_VISCOSITY"; | ||
} | ||
if (name.equals("CONDUCTIVITY")) { | ||
name = "THERMAL_CONDUCTIVITY"; | ||
} | ||
|
||
// todo: consider replacing this function with built-in valueOf | ||
for (PhysicalPropertyType pt : copyOfValues) { | ||
if (pt.name().equals(name)) { | ||
return pt; | ||
} | ||
} | ||
throw new RuntimeException( | ||
new InvalidInputException("PhysicalPropertyType", "byName", "name", "is not valid.")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.