1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.complex;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.hipparchus.CalculusFieldElement;
23 import org.hipparchus.Field;
24
25
26
27
28
29
30
31
32 public class FieldComplexField<T extends CalculusFieldElement<T>> implements Field<FieldComplex<T>> {
33
34
35 private static final Map<Field<?>, FieldComplexField<?>> CACHE = new HashMap<>();
36
37
38 private final FieldComplex<T> zero;
39
40
41 private final FieldComplex<T> one;
42
43
44
45
46 private FieldComplexField(final Field<T> field) {
47 zero = FieldComplex.getZero(field);
48 one = FieldComplex.getOne(field);
49 }
50
51
52
53
54
55
56 public static <T extends CalculusFieldElement<T>> FieldComplexField<T> getField(final Field<T> partsField) {
57 FieldComplexField<?> cachedField;
58 synchronized (CACHE) {
59 cachedField = CACHE.get(partsField);
60 if (cachedField == null) {
61 cachedField = new FieldComplexField<>(partsField);
62 CACHE.put(partsField, cachedField);
63 }
64 }
65
66 @SuppressWarnings("unchecked")
67 final FieldComplexField<T> tCached = (FieldComplexField<T>) cachedField;
68 return tCached;
69
70 }
71
72
73 @Override
74 public FieldComplex<T> getOne() {
75 return one;
76 }
77
78
79 @Override
80 public FieldComplex<T> getZero() {
81 return zero;
82 }
83
84
85 @SuppressWarnings("unchecked")
86 @Override
87 public Class<FieldComplex<T>> getRuntimeClass() {
88 return (Class<FieldComplex<T>>) getZero().getClass();
89 }
90
91
92 @Override
93 public boolean equals(final Object other) {
94 return this == other;
95 }
96
97
98 @Override
99 public int hashCode() {
100 return 0xd368f208;
101 }
102
103 }