MCPcopy Create free account
hub / github.com/MenoData/Time4J / apply

Method apply

base/src/main/java/net/time4j/DayPeriod.java:1151–1203  ·  view source on GitHub ↗
(ChronoDisplay context)

Source from the content-addressed store, hash-verified

1149 //~ Methoden ------------------------------------------------------
1150
1151 @Override
1152 public String apply(ChronoDisplay context) {
1153
1154 PlainTime time = context.get(PlainTime.COMPONENT);
1155 DayPeriod dp = DayPeriod.this;
1156 Locale locale = dp.locale;
1157
1158 if (this.fixed) {
1159 String code = getFixedCode(time);
1160
1161 if (dp.isPredefined()) {
1162 Map<String, String> textForms = loadTextForms(locale, dp.calendarType);
1163 String key = createKey(textForms, this.width, this.outputContext, code);
1164 if (!textForms.containsKey(key)) {
1165 if (code.equals("midnight")) {
1166 key = createKey(textForms, this.width, this.outputContext, "am");
1167 } else if (code.equals("noon")) {
1168 key = createKey(textForms, this.width, this.outputContext, "pm");
1169 }
1170 }
1171 if (textForms.containsKey(key)) {
1172 return textForms.get(key);
1173 }
1174 } else {
1175 return code;
1176 }
1177 } else {
1178 if (dp.isPredefined()) {
1179 Map<String, String> textForms = loadTextForms(locale, dp.calendarType);
1180 if (time.isMidnight()) {
1181 String key = createKey(textForms, this.width, this.outputContext, "midnight");
1182 if (textForms.containsKey(key)) {
1183 return textForms.get(key);
1184 }
1185 } else if (time.isSimultaneous(PlainTime.of(12))) {
1186 String key = createKey(textForms, this.width, this.outputContext, "noon");
1187 if (textForms.containsKey(key)) {
1188 return textForms.get(key);
1189 }
1190 }
1191 String code = dp.codeMap.get(dp.getStart(time));
1192 String key = createKey(textForms, this.width, this.outputContext, code);
1193 if (textForms.containsKey(key)) {
1194 return textForms.get(key);
1195 }
1196 } else {
1197 return dp.codeMap.get(dp.getStart(time));
1198 }
1199 }
1200
1201 return time.get(PlainTime.AM_PM_OF_DAY).getDisplayName((locale == null) ? Locale.ROOT : locale); // fallback
1202
1203 }
1204
1205 }
1206

Callers

nothing calls this directly

Calls 12

isPredefinedMethod · 0.95
isMidnightMethod · 0.95
isSimultaneousMethod · 0.95
ofMethod · 0.95
getStartMethod · 0.95
getFixedCodeMethod · 0.80
loadTextFormsMethod · 0.80
containsKeyMethod · 0.80
getMethod · 0.65
getDisplayNameMethod · 0.65
createKeyMethod · 0.45
equalsMethod · 0.45

Tested by

no test coverage detected