Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ecomod
zmt-jscience
Commits
7d392b30
Commit
7d392b30
authored
Jun 28, 2016
by
mey
Browse files
EnumToAmountMap.java: fixed synchronization issue in inspector
MyProperties gets enum constant via key set instead class
parent
15c8e7b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/zmt/params/def/EnumToAmountMap.java
View file @
7d392b30
package
de.zmt.params.def
;
import
java.util.ArrayList
;
import
java.util.EnumMap
;
import
javax.measure.quantity.Quantity
;
...
...
@@ -30,8 +31,6 @@ public class EnumToAmountMap<K extends Enum<K>, Q extends Quantity> extends Enum
implements
ProvidesInspector
{
private
static
final
long
serialVersionUID
=
1L
;
/** The runtime type of enum used. */
private
final
Class
<
K
>
enumType
;
/** The {@link Unit} amounts are converted when stored in the map. */
private
final
Unit
<
Q
>
storeUnit
;
/**
...
...
@@ -60,8 +59,6 @@ public class EnumToAmountMap<K extends Enum<K>, Q extends Quantity> extends Enum
*/
public
EnumToAmountMap
(
Class
<
K
>
enumType
,
Unit
<
Q
>
storeUnit
,
Unit
<
Q
>
displayUnit
)
{
super
(
enumType
);
this
.
enumType
=
enumType
;
this
.
storeUnit
=
storeUnit
;
this
.
displayUnit
=
displayUnit
;
}
...
...
@@ -143,8 +140,6 @@ public class EnumToAmountMap<K extends Enum<K>, Q extends Quantity> extends Enum
private
class
MyProperties
extends
Properties
{
private
static
final
long
serialVersionUID
=
1L
;
private
final
K
[]
enumConstants
=
enumType
.
getEnumConstants
();
@Override
public
boolean
isVolatile
()
{
return
false
;
...
...
@@ -157,7 +152,7 @@ public class EnumToAmountMap<K extends Enum<K>, Q extends Quantity> extends Enum
@Override
public
Object
getValue
(
int
index
)
{
return
get
(
e
numConstant
s
[
index
]
).
to
(
displayUnit
).
toString
();
return
get
(
getE
numConstant
(
index
)
).
to
(
displayUnit
).
toString
();
}
@Override
...
...
@@ -170,7 +165,7 @@ public class EnumToAmountMap<K extends Enum<K>, Q extends Quantity> extends Enum
@Override
public
String
getName
(
int
index
)
{
return
e
numConstant
s
[
index
]
.
name
();
return
getE
numConstant
(
index
)
.
name
();
}
@Override
...
...
@@ -181,9 +176,24 @@ public class EnumToAmountMap<K extends Enum<K>, Q extends Quantity> extends Enum
@Override
protected
Object
_setValue
(
int
index
,
Object
value
)
{
Amount
<
Q
>
amount
=
AmountUtil
.
parseAmount
(
value
.
toString
(),
displayUnit
);
put
(
e
numConstant
s
[
index
]
,
amount
.
to
(
storeUnit
));
put
(
getE
numConstant
(
index
)
,
amount
.
to
(
storeUnit
));
return
amount
;
}
/**
* Returns the enum constant of given index.
*
* @param index
* the index
* @return the enum constant
*/
private
K
getEnumConstant
(
int
index
)
{
/*
* According to EnumMap documentation, iteration order of keySet()
* matches that of the enum. The set is wrapped into ArrayList to
* make it accessible via index.
*/
return
new
ArrayList
<>(
keySet
()).
get
(
index
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment