1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.plugin
.util
;
12 import java
.io
.IOException
;
13 import java
.io
.ObjectInputStream
;
14 import java
.io
.ObjectOutputStream
;
15 import java
.io
.Serializable
;
16 import java
.lang
.reflect
.Field
;
17 import java
.nio
.file
.Path
;
18 import java
.nio
.file
.Paths
;
21 * A serialized path for use with Gradle.
25 @SuppressWarnings("UseOfClone")
26 public final class SerializedPath
27 implements Comparable
<SerializedPath
>, Cloneable
, Serializable
29 /** Serialization ID. */
30 private static final long serialVersionUID
=
33 /** The represented path. */
34 public final Path path
;
37 * Initializes the serialized path.
39 * @param __path The path to use.
40 * @throws NullPointerException On null arguments.
43 public SerializedPath(Path __path
)
44 throws NullPointerException
47 throw new NullPointerException("NARG");
57 protected SerializedPath
clone()
58 throws CloneNotSupportedException
60 return new SerializedPath(this.path
);
68 public int compareTo(SerializedPath __o
)
70 return this.path
.compareTo(__o
.path
);
80 return this.path
.hashCode();
88 public boolean equals(Object __o
)
92 if (!(__o
instanceof SerializedPath
))
95 return this.path
.equals(((SerializedPath
)__o
).path
);
99 * Reads the serialization object.
101 * @param __in The input object.
102 * @throws NoSuchFieldException If the field does not exist.
103 * @throws IOException On read errors.
104 * @throws ClassNotFoundException If our class is not valid?
105 * @throws IllegalAccessException If we cannot write a final field.
108 private void readObject(ObjectInputStream __in
)
109 throws NoSuchFieldException
, IOException
, ClassNotFoundException
,
110 IllegalAccessException
112 Field path
= this.getClass().getDeclaredField("path");
113 path
.setAccessible(true);
114 path
.set(this, Paths
.get(__in
.readObject().toString()));
122 public String
toString()
124 return this.path
.toString();
128 * Serializes the path.
130 * @param __out The stream to write to.
131 * @throws IOException On write errors.
134 private void writeObject(ObjectOutputStream __out
)
137 __out
.writeObject(this.path
.toString());
141 * Boxes all the paths.
143 * @param __paths The paths to box.
144 * @return The boxed paths.
147 public static SerializedPath
[] boxPaths(Path
... __paths
)
148 throws NullPointerException
151 throw new NullPointerException("NARG");
154 int count
= __paths
.length
;
155 SerializedPath
[] result
= new SerializedPath
[count
];
156 for (int i
= 0; i
< count
; i
++)
157 result
[i
] = new SerializedPath(__paths
[i
]);
163 * Unboxes all the paths.
165 * @param __paths The paths to unbox.
166 * @return The unboxed paths.
169 public static Path
[] unboxPaths(SerializedPath
... __paths
)
170 throws NullPointerException
173 throw new NullPointerException("NARG");
176 int count
= __paths
.length
;
177 Path
[] result
= new Path
[count
];
178 for (int i
= 0; i
< count
; i
++)
179 result
[i
] = __paths
[i
].path
;