Remove Twitter links.
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / util / SerializedPath.java
blob107ff0051d68b3fc9b291c68fc58032d43484d87
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;
20 /**
21 * A serialized path for use with Gradle.
23 * @since 2022/09/11
25 @SuppressWarnings("UseOfClone")
26 public final class SerializedPath
27 implements Comparable<SerializedPath>, Cloneable, Serializable
29 /** Serialization ID. */
30 private static final long serialVersionUID =
31 12893674786663984L;
33 /** The represented path. */
34 public final Path path;
36 /**
37 * Initializes the serialized path.
39 * @param __path The path to use.
40 * @throws NullPointerException On null arguments.
41 * @since 2022/09/11
43 public SerializedPath(Path __path)
44 throws NullPointerException
46 if (__path == null)
47 throw new NullPointerException("NARG");
49 this.path = __path;
52 /**
53 * {@inheritDoc}
54 * @since 2022/09/11
56 @Override
57 protected SerializedPath clone()
58 throws CloneNotSupportedException
60 return new SerializedPath(this.path);
63 /**
64 * {@inheritDoc}
65 * @since 2022/09/11
67 @Override
68 public int compareTo(SerializedPath __o)
70 return this.path.compareTo(__o.path);
73 /**
74 * {@inheritDoc}
75 * @since 2022/09/11
77 @Override
78 public int hashCode()
80 return this.path.hashCode();
83 /**
84 * {@inheritDoc}
85 * @since 2022/09/11
87 @Override
88 public boolean equals(Object __o)
90 if (this == __o)
91 return true;
92 if (!(__o instanceof SerializedPath))
93 return false;
95 return this.path.equals(((SerializedPath)__o).path);
98 /**
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.
106 * @since 2022/09/11
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()));
118 * {@inheritDoc}
119 * @since 2022/09/11
121 @Override
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.
132 * @since 2022/09/11
134 private void writeObject(ObjectOutputStream __out)
135 throws IOException
137 __out.writeObject(this.path.toString());
141 * Boxes all the paths.
143 * @param __paths The paths to box.
144 * @return The boxed paths.
145 * @since 2022/09/11
147 public static SerializedPath[] boxPaths(Path... __paths)
148 throws NullPointerException
150 if (__paths == null)
151 throw new NullPointerException("NARG");
153 // Process each one
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]);
159 return result;
163 * Unboxes all the paths.
165 * @param __paths The paths to unbox.
166 * @return The unboxed paths.
167 * @since 2022/09/11
169 public static Path[] unboxPaths(SerializedPath... __paths)
170 throws NullPointerException
172 if (__paths == null)
173 throw new NullPointerException("NARG");
175 // Process each one
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;
181 return result;