Skip to content

Commit c7ad32a

Browse files
authored
Adds toString method to Attributes. Refreshes dependencies. (#4)
Signed-off-by: Laird Nelson <[email protected]>
1 parent 0a780fa commit c7ad32a

File tree

3 files changed

+67
-26
lines changed

3 files changed

+67
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ changes, regardless of project version and without notice.**
1515

1616
# Requirements
1717

18-
microBean™ Attributes requires a Java runtime of version 23 or higher.
18+
microBean™ Attributes requires a Java runtime of version 17 or higher.
1919

2020
# Installation
2121

@@ -27,7 +27,7 @@ dependency:
2727
<groupId>org.microbean</groupId>
2828
<artifactId>microbean-attributes</artifactId>
2929
<!-- Always check https://search.maven.org/artifact/org.microbean/microbean-attributes for up-to-date available versions. -->
30-
<version>0.0.2</version>
30+
<version>0.0.3</version>
3131
</dependency>
3232
```
3333

pom.xml

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
<java.util.logging.config.file>${project.basedir}/src/test/java/logging.properties</java.util.logging.config.file>
7474

7575
<!-- maven-compiler-plugin properties -->
76-
<maven.compiler.release>23</maven.compiler.release>
76+
<maven.compiler.release>17</maven.compiler.release>
7777
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
7878
<maven.compiler.showWarnings>true</maven.compiler.showWarnings>
7979

@@ -125,7 +125,7 @@
125125
<dependency>
126126
<groupId>org.junit</groupId>
127127
<artifactId>junit-bom</artifactId>
128-
<version>5.11.4</version>
128+
<version>5.13.1</version>
129129
<type>pom</type>
130130
<scope>import</scope>
131131
</dependency>
@@ -292,7 +292,7 @@
292292
</plugin>
293293
<plugin>
294294
<artifactId>maven-clean-plugin</artifactId>
295-
<version>3.4.0</version>
295+
<version>3.5.0</version>
296296
<configuration>
297297
<filesets>
298298
<fileset>
@@ -307,7 +307,7 @@
307307
</plugin>
308308
<plugin>
309309
<artifactId>maven-compiler-plugin</artifactId>
310-
<version>3.13.0</version>
310+
<version>3.14.0</version>
311311
<configuration>
312312
<compilerArgs>
313313
<arg>-Xlint:all</arg>
@@ -328,7 +328,7 @@
328328
</plugin>
329329
<plugin>
330330
<artifactId>maven-deploy-plugin</artifactId>
331-
<version>3.1.3</version>
331+
<version>3.1.4</version>
332332
</plugin>
333333
<plugin>
334334
<artifactId>maven-enforcer-plugin</artifactId>
@@ -341,7 +341,7 @@
341341
</plugin>
342342
<plugin>
343343
<artifactId>maven-install-plugin</artifactId>
344-
<version>3.1.3</version>
344+
<version>3.1.4</version>
345345
</plugin>
346346
<plugin>
347347
<artifactId>maven-jar-plugin</artifactId>
@@ -377,7 +377,7 @@
377377
</plugin>
378378
<plugin>
379379
<artifactId>maven-project-info-reports-plugin</artifactId>
380-
<version>3.8.0</version>
380+
<version>3.9.0</version>
381381
</plugin>
382382
<plugin>
383383
<artifactId>maven-release-plugin</artifactId>
@@ -414,14 +414,7 @@
414414
</plugin>
415415
<plugin>
416416
<artifactId>maven-surefire-plugin</artifactId>
417-
<version>3.5.2</version>
418-
<dependencies>
419-
<dependency>
420-
<groupId>org.apache.maven.surefire</groupId>
421-
<artifactId>surefire-junit-platform</artifactId>
422-
<version>3.5.2</version>
423-
</dependency>
424-
</dependencies>
417+
<version>3.5.3</version>
425418
</plugin>
426419
<plugin>
427420
<artifactId>maven-toolchains-plugin</artifactId>
@@ -430,7 +423,7 @@
430423
<plugin>
431424
<groupId>com.github.spotbugs</groupId>
432425
<artifactId>spotbugs-maven-plugin</artifactId>
433-
<version>4.8.6.6</version>
426+
<version>4.9.3.0</version>
434427
</plugin>
435428
<plugin>
436429
<groupId>org.codehaus.mojo</groupId>
@@ -440,7 +433,7 @@
440433
<plugin>
441434
<groupId>io.smallrye</groupId>
442435
<artifactId>jandex-maven-plugin</artifactId>
443-
<version>3.2.3</version>
436+
<version>3.3.1</version>
444437
</plugin>
445438
<plugin>
446439
<groupId>org.sonatype.plugins</groupId>

src/main/java/org/microbean/attributes/Attributes.java

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.function.Predicate;
2424

2525
import java.util.Arrays;
26+
import java.util.Iterator;
2627
import java.util.List;
2728
import java.util.Map;
2829
import java.util.Map.Entry;
@@ -42,14 +43,20 @@
4243
* An {@linkplain Attributed attributed} {@link Value} with a {@linkplain #name() name}, {@linkplain #values() named
4344
* values}, and {@linkplain #notes() non-normative named values}.
4445
*
45-
* @param name a non-{@code null} name of this {@link Attributes}
46+
* @param name a non-{@code null} name of this {@link Attributes}; names that begin with the {@code $} character are
47+
* reserved for internal use
4648
*
47-
* @param values a non-{@code null} {@link Map} of named {@linkplain Value values} associated with this {@link Attributes}
49+
* @param values a non-{@code null} {@link Map} of named {@linkplain Value values} associated with this {@link
50+
* Attributes}; keys in this {@link Map} that begin with the {@code $} character are reserved for internal use
4851
*
4952
* @param notes a non-{@code null} {@link Map} of non-normative named {@linkplain Value values} associated with this
50-
* {@link Attributes}
53+
* {@link Attributes}; keys in this {@link Map} that begin with the {@code $} character are reserved for internal use
5154
*
52-
* @param attributesMap a non-{@code null} {@link Map} of named metadata associated with this {@link Attributes}
55+
* @param attributesMap a non-{@code null} {@link Map} of named metadata associated with this {@link Attributes}; any
56+
* {@link List} stored under a key that is equal to the supplied {@code name} is considered to be a list of {@link
57+
* Attributes} pertaining to this {@link Attributes} itself; other keys are normally (but are not required to be) the
58+
* names of keys in the supplied {@code values} or {@code notes} {@link Map}s; keys that begin with the {@code $}
59+
* character are reserved for internal use
5360
*
5461
* @author <a href="https://about.me/lairdnelson" target="_top">Laird Nelson</a>
5562
*/
@@ -64,12 +71,17 @@ public final record Attributes(String name,
6471
*
6572
* @param name a non-{@code null} name of this {@link Attributes}
6673
*
67-
* @param values a non-{@code null} {@link Map} of named {@linkplain Value values} associated with this {@link Attributes}
74+
* @param values a non-{@code null} {@link Map} of named {@linkplain Value values} associated with this {@link
75+
* Attributes}; keys in this {@link Map} that begin with the {@code $} character are reserved for internal use
6876
*
6977
* @param notes a non-{@code null} {@link Map} of non-normative named {@linkplain Value values} associated with this
70-
* {@link Attributes}
78+
* {@link Attributes}; keys in this {@link Map} that begin with the {@code $} character are reserved for internal use
7179
*
72-
* @param attributesMap a non-{@code null} {@link Map} of named metadata associated with this {@link Attributes}
80+
* @param attributesMap a non-{@code null} {@link Map} of named metadata associated with this {@link Attributes}; any
81+
* {@link List} stored under a key that is equal to the supplied {@code name} is considered to be a list of {@link
82+
* Attributes} pertaining to this {@link Attributes} itself; other keys are normally (but are not required to be) the
83+
* names of keys in the supplied {@code values} or {@code notes} {@link Map}s; keys in this {@link Map} that begin
84+
* with the {@code $} character are reserved for internal use
7385
*
7486
* @exception NullPointerException if any argument is {@code null}
7587
*/
@@ -234,6 +246,42 @@ public final int hashCode() {
234246
return hashCode;
235247
}
236248

249+
@Override // Record
250+
public final String toString() {
251+
final StringBuilder sb = new StringBuilder();
252+
sb.append("@").append(this.name());
253+
final Map<String, Value<?>> values = this.values();
254+
final Map<String, Value<?>> notes = this.notes();
255+
if (values.isEmpty() && notes.isEmpty()) {
256+
return sb.toString();
257+
}
258+
sb.append("(");
259+
if (!values.isEmpty()) {
260+
final Iterator<Entry<String, Value<?>>> i = values.entrySet().iterator();
261+
while (i.hasNext()) {
262+
final Entry<String, Value<?>> e = i.next();
263+
sb.append(e.getKey()).append(" = ").append(e.getValue());
264+
if (i.hasNext()) {
265+
sb.append(", ");
266+
}
267+
}
268+
}
269+
if (!notes.isEmpty()) {
270+
sb.append(" (");
271+
final Iterator<Entry<String, Value<?>>> i = notes.entrySet().iterator();
272+
while (i.hasNext()) {
273+
final Entry<String, Value<?>> e = i.next();
274+
sb.append(e.getKey()).append(" = ").append(e.getValue());
275+
if (i.hasNext()) {
276+
sb.append(", ");
277+
}
278+
}
279+
sb.append(")");
280+
}
281+
sb.append(")");
282+
return sb.toString();
283+
}
284+
237285
/**
238286
* Returns a suitably-typed {@link Value} indexed under the supplied {@code name}, or {@code null} if no such {@link
239287
* Value} exists.

0 commit comments

Comments
 (0)