/* * [GoList.java] * * Summary: Data for a go to List of URLs sorted by humanname. * * Copyright: (c) 2001-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2001-03-08 initial * 1.1 2006-01-01 * 1.2 2006-03-05 reformat with IntelliJ, add Javadoc */ package com.mindprod.go; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.Serializable; /** * Data for a go to List of URLs sorted by humanname. *

* Originally worked even under JDK 1.1, thus no ArrayLists. * Even though we no longer display the index in an Applet, SeeSort uses the index to patch links. * * @author Roedy Green, Canadian Mind Products * @version 1.2 2006-03-05 reformat with IntelliJ, add Javadoc * @since 2001-03-08 */ public final class GoList implements Serializable { /** * version number for the class */ static final long serialVersionUID = 1L; /** * list of the webroot-relative filenames of the places to jump to. Three separate arrays is more RAM efficient * than a single array to a triple * e.g. jgloss/certificate.html */ private final String[] filenames; /** * list of human names for the places to jump to e.g. "updating certificate roots" */ private final String[] humannames; /** * list of target parts of the URL to jump to e.g. ROOT */ private final String[] targets; /** * how many elements we have added so far */ private int size = 0; /** * @param size How many elements in the list. */ public GoList( int size ) { filenames = new String[ size ]; targets = new String[ size ]; humannames = new String[ size ]; } /** * Read a previously serialised Golist. Corresponding Write is part of com.mindprod.qf.BuildIndexes. * * @param is InputStream (not ObjectInputStream) to read the golist from. * * @return GoList object from serialised object in file * @throws IOException if cannot fetch the gotlist resource * @throws ClassNotFoundException if stream contains unknown classes. */ public static GoList getData( InputStream is ) throws IOException, ClassNotFoundException { // O P E N // look in jar, on classpath, locally or server as appropriate, will // have package name prepended ObjectInputStream ois = new ObjectInputStream( is ); // R E A D GoList goList = ( GoList ) ois.readObject(); // C L O S E ois.close(); return goList; } /** * Add a triple to the GoList. All parameters are presumed to be trimmed. * * @param filename Filename part of the URL. without lead mindprod/jgloss, with trailing .html Cross links will * have form ../bgloss/voip.html. No trailing #XXXX. * @param target target part of the URL, without the # * @param humanname Humanname for the link. No entities! */ public void add( String filename, String target, String humanname ) { filenames[ size ] = filename; targets[ size ] = target; humannames[ size ] = humanname; size++; } /** * Get the filename portion of the URL * * @param index Which element do you want? * * @return Filename as a trimmed string. */ public String getFilename( int index ) { return filenames[ index ]; } /** * Get the human description of the link * * @param index Which element do you want? * * @return Human name as a trimmed string. */ public String getHumanname( int index ) { return humannames[ index ]; } /** * Get the target part of the URL * * @param index Which element do you want? * * @return Target as a trimmed string. */ public String getTarget( int index ) { return targets[ index ]; } /** * How many elements are currently in the GoList? * * @return size of of the GoList */ public int size() { return size; } }