mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8321545: Override toString() for Format subclasses
Reviewed-by: naoto, rriggs
This commit is contained in:
parent
edfee7f348
commit
96607df7f0
12 changed files with 419 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -614,6 +614,17 @@ public class ChoiceFormat extends NumberFormat {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a string identifying this {@code ChoiceFormat}, for debugging}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return
|
||||
"""
|
||||
ChoiceFormat [pattern: "%s"]
|
||||
""".formatted(toPattern());
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the specified object with this {@code ChoiceFormat} for equality.
|
||||
* Returns true if the object is also a {@code ChoiceFormat} and the
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -2391,6 +2391,17 @@ public final class CompactNumberFormat extends NumberFormat {
|
|||
+ Boolean.hashCode(parseBigDecimal);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a string identifying this {@code CompactNumberFormat}, for debugging}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return
|
||||
"""
|
||||
CompactNumberFormat [locale: "%s", decimal pattern: "%s", compact patterns: "%s"]
|
||||
""".formatted(symbols.getLocale().getDisplayName(), decimalPattern, Arrays.toString(compactPatterns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns a copy of this {@code CompactNumberFormat}
|
||||
* instance.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -2996,6 +2996,17 @@ public class DecimalFormat extends NumberFormat {
|
|||
// just enough fields for a reasonable distribution
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a string identifying this {@code DecimalFormat}, for debugging}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return
|
||||
"""
|
||||
DecimalFormat [locale: "%s", pattern: "%s"]
|
||||
""".formatted(symbols.getLocale().getDisplayName(), toPattern());
|
||||
}
|
||||
|
||||
/**
|
||||
* Synthesizes a pattern string that represents the current state
|
||||
* of this Format object.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -530,7 +530,7 @@ public final class ListFormat extends Format {
|
|||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* {@return a string identifying this {@code ListFormat}, for debugging}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -1184,6 +1184,17 @@ public class MessageFormat extends Format {
|
|||
return pattern.hashCode(); // enough for reasonable distribution
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a string identifying this {@code MessageFormat}, for debugging}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return
|
||||
"""
|
||||
MessageFormat [locale: %s, pattern: "%s"]
|
||||
""".formatted(locale == null ? null : '"' + locale.getDisplayName() + '"', toPattern());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Defines constants that are used as attribute keys in the
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -2422,6 +2422,17 @@ public class SimpleDateFormat extends DateFormat {
|
|||
// just enough fields for a reasonable distribution
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return a string identifying this {@code SimpleDateFormat}, for debugging}
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return
|
||||
"""
|
||||
SimpleDateFormat [locale: %s, pattern: "%s"]
|
||||
""".formatted(locale == null ? null : '"' + locale.getDisplayName() + '"', toPattern());
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the specified object with this {@code SimpleDateFormat} for equality.
|
||||
* Returns true if the object is also a {@code SimpleDateFormat} and the
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue