VIBE v5.1.6
Search Engine
Loading...
Searching...
No Matches
edu.usfca.cs272.JsonWriter Class Reference

Static Public Member Functions

static void writeIndent (Writer writer, int indent) throws IOException
 
static void writeIndent (String element, Writer writer, int indent) throws IOException
 
static void writeQuote (String element, Writer writer, int indent) throws IOException
 
static void writeArray (Collection<? extends Number > elements, Writer writer, int indent) throws IOException
 
static void writeArray (Collection<? extends Number > elements, Path path) throws IOException
 
static String writeArray (Collection<? extends Number > elements)
 
static void writeObject (Map< String, ? extends Number > elements, Writer writer, int indent) throws IOException
 
static void writeObject (Map< String, ? extends Number > elements, Path path) throws IOException
 
static String writeObject (Map< String, ? extends Number > elements)
 
static void writeObjectArrays (Map< String, ? extends Collection<? extends Number > > elements, Writer writer, int indent) throws IOException
 
static void writeObjectArrays (Map< String, ? extends Collection<? extends Number > > elements, Path path) throws IOException
 
static String writeObjectArrays (Map< String, ? extends Collection<? extends Number > > elements)
 
static void writeArrayObjects (Collection<? extends Map< String, ? extends Number > > elements, Writer writer, int indent) throws IOException
 
static void writeArrayObjects (Collection<? extends Map< String, ? extends Number > > elements, Path path) throws IOException
 
static String writeArrayObjects (Collection<? extends Map< String, ? extends Number > > elements)
 
static String writeIndex (Map< String, ? extends Map< String, ? extends Set<? extends Number > > > index)
 
static void writeIndex (Map< String, ? extends Map< String, ? extends Set<? extends Number > > > index, Path path) throws IOException
 
static void writeIndex (Map< String, ? extends Map< String, ? extends Set<? extends Number > > > index, Writer writer, int indent) throws IOException
 
static String writeSearch (Map< String, ? extends Collection< InvertedIndex.Score > > searchMap)
 
static void writeSearch (Map< String, ? extends Collection< InvertedIndex.Score > > searchMap, Path path) throws IOException
 
static void writeSearch (Map< String, ? extends Collection< InvertedIndex.Score > > searchMap, Writer writer, int indent) throws IOException
 
static void writeScore (Writer writer, int indent, InvertedIndex.Score map) throws IOException
 
static void writeScores (Writer writer, int indent, Collection< InvertedIndex.Score > scores) throws IOException
 

Detailed Description

Outputs several simple data structures in "pretty" JSON format where newlines are used to separate elements and nested elements are indented using spaces.

Warning: This class is not thread-safe. If multiple threads access this class concurrently, access must be synchronized externally.

Author
CS 272 Software Development (University of San Francisco)
Ravneet Singh Bhatia
Version
Spring 2024

Member Function Documentation

◆ writeArray() [1/3]

static String edu.usfca.cs272.JsonWriter.writeArray ( Collection<? extends Number > elements)
static

Returns the elements as a pretty JSON array.

Parameters
elementsthe elements to use
Returns
a String containing the elements in pretty JSON format
See also
StringWriter
#writeArray(Collection, Writer, int)

◆ writeArray() [2/3]

static void edu.usfca.cs272.JsonWriter.writeArray ( Collection<? extends Number > elements,
Path path ) throws IOException
static

Writes the elements as a pretty JSON array to file.

Parameters
elementsthe elements to write
paththe file path to use
Exceptions
IOExceptionif an IO error occurs
See also
Files::newBufferedReader(Path, java.nio.charset.Charset)
StandardCharsets::UTF_8
#writeArray(Collection, Writer, int)

◆ writeArray() [3/3]

static void edu.usfca.cs272.JsonWriter.writeArray ( Collection<? extends Number > elements,
Writer writer,
int indent ) throws IOException
static

Writes the elements as a pretty JSON array.

Parameters
elementsthe elements to write
writerthe writer to use
indentthe initial indent level; the first bracket is not indented, inner elements are indented by one, and the last bracket is indented at the initial indentation level
Exceptions
IOExceptionif an IO error occurs
See also
Writer::write(String)
#writeIndent(Writer, int)
#writeIndent(String, Writer, int)

◆ writeArrayObjects() [1/3]

static String edu.usfca.cs272.JsonWriter.writeArrayObjects ( Collection<? extends Map< String, ? extends Number > > elements)
static

Returns the elements as a pretty JSON array with nested objects.

Parameters
elementsthe elements to use
Returns
a String containing the elements in pretty JSON format
See also
StringWriter
#writeArrayObjects(Collection)

◆ writeArrayObjects() [2/3]

static void edu.usfca.cs272.JsonWriter.writeArrayObjects ( Collection<? extends Map< String, ? extends Number > > elements,
Path path ) throws IOException
static

Writes the elements as a pretty JSON array with nested objects to file.

Parameters
elementsthe elements to write
paththe file path to use
Exceptions
IOExceptionif an IO error occurs
See also
Files::newBufferedReader(Path, java.nio.charset.Charset)
StandardCharsets::UTF_8
#writeArrayObjects(Collection)

◆ writeArrayObjects() [3/3]

static void edu.usfca.cs272.JsonWriter.writeArrayObjects ( Collection<? extends Map< String, ? extends Number > > elements,
Writer writer,
int indent ) throws IOException
static

Writes the elements as a pretty JSON array with nested objects. The generic notation used allows this method to be used for any type of collection with any type of nested map of String keys to number objects.

Parameters
elementsthe elements to write
writerthe writer to use
indentthe initial indent level; the first bracket is not indented, inner elements are indented by one, and the last bracket is indented at the initial indentation level
Exceptions
IOExceptionif an IO error occurs
See also
Writer::write(String)
#writeIndent(Writer, int)
#writeIndent(String, Writer, int)
#writeObject(Map)

◆ writeIndent() [1/2]

static void edu.usfca.cs272.JsonWriter.writeIndent ( String element,
Writer writer,
int indent ) throws IOException
static

Indents and then writes the String element.

Parameters
elementthe element to write
writerthe writer to use
indentthe number of times to indent
Exceptions
IOExceptionif an IO error occurs

◆ writeIndent() [2/2]

static void edu.usfca.cs272.JsonWriter.writeIndent ( Writer writer,
int indent ) throws IOException
static

Indents the writer by the specified number of times. Does nothing if the indentation level is 0 or less.

Parameters
writerthe writer to use
indentthe number of times to indent
Exceptions
IOExceptionif an IO error occurs

◆ writeIndex() [1/3]

static String edu.usfca.cs272.JsonWriter.writeIndex ( Map< String, ? extends Map< String, ? extends Set<? extends Number > > > index)
static

Writes InvertedIndex as a pretty JSON.

Parameters
indexInvertedIndex
Returns
null if exception.

◆ writeIndex() [2/3]

static void edu.usfca.cs272.JsonWriter.writeIndex ( Map< String, ? extends Map< String, ? extends Set<? extends Number > > > index,
Path path ) throws IOException
static

Writes InvertedIndex as a pretty JSON.

Parameters
indexInvertedIndex
pathpath of output file.
Exceptions
IOExceptionif BufferedWriter error.

◆ writeIndex() [3/3]

static void edu.usfca.cs272.JsonWriter.writeIndex ( Map< String, ? extends Map< String, ? extends Set<? extends Number > > > index,
Writer writer,
int indent ) throws IOException
static

Writes InvertedIndex as a pretty JSON

Parameters
indexInvertedIndex
writerWriter
indentindent value
Exceptions
IOExceptionif writer error.

◆ writeObject() [1/3]

static String edu.usfca.cs272.JsonWriter.writeObject ( Map< String, ? extends Number > elements)
static

Returns the elements as a pretty JSON object.

Parameters
elementsthe elements to use
Returns
a String containing the elements in pretty JSON format
See also
StringWriter
#writeObject(Map, Writer, int)

◆ writeObject() [2/3]

static void edu.usfca.cs272.JsonWriter.writeObject ( Map< String, ? extends Number > elements,
Path path ) throws IOException
static

Writes the elements as a pretty JSON object to file.

Parameters
elementsthe elements to write
paththe file path to use
Exceptions
IOExceptionif an IO error occurs
See also
Files::newBufferedReader(Path, java.nio.charset.Charset)
StandardCharsets::UTF_8
#writeObject(Map, Writer, int)

◆ writeObject() [3/3]

static void edu.usfca.cs272.JsonWriter.writeObject ( Map< String, ? extends Number > elements,
Writer writer,
int indent ) throws IOException
static

Writes the elements as a pretty JSON object.

Parameters
elementsthe elements to write
writerthe writer to use
indentthe initial indent level; the first bracket is not indented, inner elements are indented by one, and the last bracket is indented at the initial indentation level
Exceptions
IOExceptionif an IO error occurs
See also
Writer::write(String)
#writeIndent(Writer, int)
#writeIndent(String, Writer, int)

◆ writeObjectArrays() [1/3]

static String edu.usfca.cs272.JsonWriter.writeObjectArrays ( Map< String, ? extends Collection<? extends Number > > elements)
static

Returns the elements as a pretty JSON object with nested arrays.

Parameters
elementsthe elements to use
Returns
a String containing the elements in pretty JSON format
See also
StringWriter
#writeObjectArrays(Map, Writer, int)

◆ writeObjectArrays() [2/3]

static void edu.usfca.cs272.JsonWriter.writeObjectArrays ( Map< String, ? extends Collection<? extends Number > > elements,
Path path ) throws IOException
static

Writes the elements as a pretty JSON object with nested arrays to file.

Parameters
elementsthe elements to write
paththe file path to use
Exceptions
IOExceptionif an IO error occurs
See also
Files::newBufferedReader(Path, java.nio.charset.Charset)
StandardCharsets::UTF_8
#writeObjectArrays(Map, Writer, int)

◆ writeObjectArrays() [3/3]

static void edu.usfca.cs272.JsonWriter.writeObjectArrays ( Map< String, ? extends Collection<? extends Number > > elements,
Writer writer,
int indent ) throws IOException
static

Writes the elements as a pretty JSON object with nested arrays. The generic notation used allows this method to be used for any type of map with any type of nested collection of number objects.

Parameters
elementsthe elements to write
writerthe writer to use
indentthe initial indent level; the first bracket is not indented, inner elements are indented by one, and the last bracket is indented at the initial indentation level
Exceptions
IOExceptionif an IO error occurs
See also
Writer::write(String)
#writeIndent(Writer, int)
#writeIndent(String, Writer, int)
#writeArray(Collection)

◆ writeQuote()

static void edu.usfca.cs272.JsonWriter.writeQuote ( String element,
Writer writer,
int indent ) throws IOException
static

Indents and then writes the text element surrounded by " " quotation marks.

Parameters
elementthe element to write
writerthe writer to use
indentthe number of times to indent
Exceptions
IOExceptionif an IO error occurs

◆ writeScore()

static void edu.usfca.cs272.JsonWriter.writeScore ( Writer writer,
int indent,
InvertedIndex.Score map ) throws IOException
static

Writes the score map to writer.

Parameters
writerwriter
indentindent value
mapscoreMap
Exceptions
IOExceptionif the writing fails.

◆ writeScores()

static void edu.usfca.cs272.JsonWriter.writeScores ( Writer writer,
int indent,
Collection< InvertedIndex.Score > scores ) throws IOException
static

Writes a collection of scores in pretty JSON

Parameters
writerWriter
indentindentation
scoresCollection of scores
Exceptions
IOExceptionif the writing fails.

◆ writeSearch() [1/3]

static String edu.usfca.cs272.JsonWriter.writeSearch ( Map< String, ? extends Collection< InvertedIndex.Score > > searchMap)
static

Writes search results in pretty Json

Parameters
searchMapsearch results map
Returns
pretty Json or null if IOException is thrown.

◆ writeSearch() [2/3]

static void edu.usfca.cs272.JsonWriter.writeSearch ( Map< String, ? extends Collection< InvertedIndex.Score > > searchMap,
Path path ) throws IOException
static

Writes search results in pretty Json

Parameters
searchMapsearch results map
pathoutput file.
Exceptions
IOExceptionif unable to write to file.

◆ writeSearch() [3/3]

static void edu.usfca.cs272.JsonWriter.writeSearch ( Map< String, ? extends Collection< InvertedIndex.Score > > searchMap,
Writer writer,
int indent ) throws IOException
static

Writes Search Results in pretty Json

Parameters
searchMapSearch results
writerwriter
indentindent value
Exceptions
IOExceptionif unable to write to path.

The documentation for this class was generated from the following file: