SlideShare a Scribd company logo
1 of 7
Download to read offline
Java Programming: Must implement a storage manager that maintains a series of data objects in
each data file. This assignment provides you with a set of incomplete classes (, see SlottedPage,
FileManager, and BufferedFileManager which contain methods currently throwing an
UnsupportedOperationException). You will need to write code for these classes. Your code will be
graded by running a set of unit tests and then examining your code (see SlottedPageTest and
FileManagerTest which use JUnit1, as well as BufferedFileManagerTest which produces output
messages). Note that passing unit tests does NOT necessarily guarantee that your
implementation is correct and efficient. Please make sure that your code will not cause any
problem in other cases not covered by the unit tests. Below are the files and make sure there are
no errors and show the output as well.
BufferedFileManager.java
package mypack;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
public class BufferedFileManager extends FileManager {
private int bufferSize;
private Map<Integer, SlottedPage> buffer;
public BufferedFileManager(int bufferSize) {
this.bufferSize = bufferSize;
buffer = new LinkedHashMap<Integer, SlottedPage>(bufferSize);
}
@Override
public void put(int fileID, Long location, Object o) throws IOException, InvalidLocationException {
if (buffer.containsKey(first(location))) {
SlottedPage p = buffer.get(first(location));
p.put(second(location), o);
buffer.put(first(location), p);
} else {
if (buffer.size() == bufferSize) {
// Evict the least recently used page
buffer.remove(buffer.keySet().iterator().next());
}
SlottedPage p = page(fileID, first(location));
p.put(second(location), o);
updated(p, fileID);
buffer.put(first(location), p);
}
}
@Override
public Object get(int fileID, Long location) throws IOException, InvalidLocationException {
if (buffer.containsKey(first(location))) {
return buffer.get(first(location)).get(second(location));
}
SlottedPage p = page(fileID, first(location));
if (buffer.size() == bufferSize) {
// Evict the least recently used page
buffer.remove(buffer.keySet().iterator().next());
}
buffer.put(first(location), p);
return p.get(second(location));
}
@Override
public Object remove(int fileID, Long location) throws IOException, InvalidLocationException {
if (buffer.containsKey(first(location))) {
SlottedPage p = buffer.get(first(location));
Object o = p.remove(second(location));
buffer.put(first(location), p);
return o;
}
SlottedPage p = page(fileID, first(location));
Object o = p.remove(second(location));
updated(p, fileID);
if (buffer.size() == bufferSize) {
// Evict the least recently used page
buffer.remove(buffer.keySet().iterator().next());
}
buffer.put(first(location), p);
return o;
}
@Override
public Iterator<Object> iterator(int fileID) throws IOException {
SlottedPage[] pages = pages(fileID);
return new BufferedPageIterator(pages, buffer);
}
}
BufferedPageIterator.java
package mypack;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
public class BufferedPageIterator implements Iterator<Object>{
private SlottedPage[] pages;
private int currPage = 0;
private int currIndex = 0;
private Map<Integer, SlottedPage> buffer;
public BufferedPageIterator(SlottedPage[] pages, Map<Integer, SlottedPage> buffer) {
this.pages = pages;
this.buffer = buffer;
}
@Override
public boolean hasNext() {
if (currPage == pages.length) {
return false;
}
return !(currIndex == pages[currPage].entryCount() && currPage == pages.length - 1);
}
@Override
public Object next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Object o;
if (buffer.containsKey(currPage)) {
o = buffer.get(currPage).get(currIndex);
} else {
o = pages[currPage].get(currIndex);
}
currIndex++;
if (currIndex == pages[currPage].entryCount()) {
currPage++;
currIndex = 0;
}
return o;
}
}
FileManager.java
package mypack;
import java.io.IOException;
import java.util.Iterator;
public class FileManager {
public void put(int fileID, Long location, Object o) throws IOException, InvalidLocationException {
if (first(location) < 0) {
throw new InvalidLocationException();
}
SlottedPage p = page(fileID, first(location));
p.put(second(location), o);
updated(p, fileID);
}
public Object get(int fileID, Long location) throws IOException, InvalidLocationException {
if (first(location) < 0) {
throw new InvalidLocationException();
}
SlottedPage p = page(fileID, first(location));
return p.get(second(location));
}
public Object remove(int fileID, Long location) throws IOException, InvalidLocationException {
if (first(location) < 0) {
throw new InvalidLocationException();
}
SlottedPage p = page(fileID, first(location));
return p.remove(second(location));
}
public Iterator<Object> iterator(int fileID) throws IOException {
SlottedPage[] pages = pages(fileID);
return new PageIterator(pages);
}
}
InvalidLocationException.java
package mypack;
public class InvalidLocationException extends Exception {
}
PageIterator.java
package mypack;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class PageIterator implements Iterator<Object> {
private SlottedPage[] pages;
private int currPage = 0;
private int currIndex = 0;
public PageIterator(SlottedPage[] pages) {
this.pages = pages;
}
@Override
public boolean hasNext() {
if (currPage == pages.length) {
return false;
}
return !(currIndex == pages[currPage].entryCount() && currPage == pages.length - 1);
}
@Override
public Object next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Object o = pages[currPage].get(currIndex);
currIndex++;
if (currIndex == pages[currPage].entryCount()) {
currPage++;
currIndex = 0;
}
return o;
}
}
SlottedPage.java
package mypack;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class SlottedPage {
public void add(Object o) throws IOException, NotEnoughSpaceException {
int loc = save(o);
setEntryCount(entryCount() + 1);
saveLocation(entryCount() - 1, loc);
}
public Object get(int index) {
int loc = getLocation(index);
if (loc == -1) {
return null;
}
return toObject(b, loc);
}
public Object remove(int index) {
int loc = getLocation(index);
if (loc == -1) {
return null;
}
Object o = toObject(b, loc);
saveLocation(index, -1);
return o;
}
public Iterator<Object> iterator() {
return new SlottedPageIterator(this);
}
public void compact() {
int offset = 0;
for (int i = 0; i < entryCount(); i++) {
int loc = getLocation(i);
if (loc != -1) {
int size = size(toObject(b, loc));
if (offset + size >= b.length) {
throw new NotEnoughSpaceException();
}
move(loc, offset);
saveLocation(i, offset);
offset += size;
}
}
}
public int entryCount() {
// TODO Auto-generated method stub
return 0;
}
}
SlottedPageIterator.java
package mypack;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class SlottedPageIterator implements Iterator<Object>{
private SlottedPage page;
private int currIndex = 0;
public SlottedPageIterator(SlottedPage page) {
this.page = page;
}
@Override
public boolean hasNext() {
return !(currIndex == page.entryCount());
}
@Override
public Object next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
Object o = page.get(currIndex);
currIndex++;
return o;
}
}

More Related Content

Similar to Java Programming Must implement a storage manager that main.pdf

Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257newegg
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureC.T.Co
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Paco de la Cruz
 
I can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxI can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxhamblymarta
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdffatoryoutlets
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 WinterHuahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 WinterRyu Kobayashi
 
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docxDAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docxtheodorelove43763
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2Leonid Maslov
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Librariesjeresig
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesAnkit Rastogi
 

Similar to Java Programming Must implement a storage manager that main.pdf (20)

Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Xml & Java
Xml & JavaXml & Java
Xml & Java
 
Androidaop 170105090257
Androidaop 170105090257Androidaop 170105090257
Androidaop 170105090257
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)Durable functions 2.0 (2019-10-10)
Durable functions 2.0 (2019-10-10)
 
I can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docxI can not get my code to comply it gets mad that I have run declare mo.docx
I can not get my code to comply it gets mad that I have run declare mo.docx
 
Note Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdfNote Use Java Write a web server that is capable of processing only.pdf
Note Use Java Write a web server that is capable of processing only.pdf
 
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 WinterHuahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
Huahin Framework for Hadoop, Hadoop Conference Japan 2013 Winter
 
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docxDAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
DAOFactory.javaDAOFactory.javapublicclassDAOFactory{ this .docx
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Secrets of JavaScript Libraries
Secrets of JavaScript LibrariesSecrets of JavaScript Libraries
Secrets of JavaScript Libraries
 
Ten useful JavaScript tips & best practices
Ten useful JavaScript tips & best practicesTen useful JavaScript tips & best practices
Ten useful JavaScript tips & best practices
 

More from adinathassociates

It is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdfIt is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdfadinathassociates
 
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdfizgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdfadinathassociates
 
Jamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdfJamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdfadinathassociates
 
It is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdfIt is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdfadinathassociates
 
James tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdfJames tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdfadinathassociates
 
It is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdfIt is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdfadinathassociates
 
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdfIt was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdfadinathassociates
 
It is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdfIt is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdfadinathassociates
 
Joe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdfJoe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdfadinathassociates
 
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdfJoan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdfadinathassociates
 
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdfJobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdfadinathassociates
 
It is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdfIt is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdfadinathassociates
 
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdfJoanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdfadinathassociates
 
JKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdfJKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdfadinathassociates
 
Jill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdfJill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdfadinathassociates
 
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdfJennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdfadinathassociates
 
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdfJim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdfadinathassociates
 
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdfJhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdfadinathassociates
 
JAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdfJAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdfadinathassociates
 
Jennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdfJennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdfadinathassociates
 

More from adinathassociates (20)

It is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdfIt is somewhat curious that this documentation does not wind.pdf
It is somewhat curious that this documentation does not wind.pdf
 
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdfizgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
izgi ynteminin ve nceden alanm plakann sonularna gre k.pdf
 
Jamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdfJamie needs a new roof on her house The cash cost is 4100.pdf
Jamie needs a new roof on her house The cash cost is 4100.pdf
 
It is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdfIt is necessary for Marketers to know how the customers feel.pdf
It is necessary for Marketers to know how the customers feel.pdf
 
James tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdfJames tiene la enfermedad celaca Cul de los siguientes a.pdf
James tiene la enfermedad celaca Cul de los siguientes a.pdf
 
It is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdfIt is difficult to quantify a value for certain biological a.pdf
It is difficult to quantify a value for certain biological a.pdf
 
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdfIt was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
It was leaked that Bergdorf Goodman treated Kayla a Hispanic.pdf
 
It is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdfIt is possible to create dynamic GUI applications based on c.pdf
It is possible to create dynamic GUI applications based on c.pdf
 
Joe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdfJoe makes annual income of 5000 for five years Joe withdr.pdf
Joe makes annual income of 5000 for five years Joe withdr.pdf
 
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdfJoan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
Joan Robinson ktisat okumann amac iktisat sorularna bir d.pdf
 
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdfJobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
Jobyde ie alma ilerleme terfi ve tevik etme grevleri gen.pdf
 
It is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdfIt is not option 3 please help What would be the outcome of.pdf
It is not option 3 please help What would be the outcome of.pdf
 
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdfJoanna and Chip Gaines and Michael Dubin got together recent.pdf
Joanna and Chip Gaines and Michael Dubin got together recent.pdf
 
JKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdfJKL Co issues zero coupon bonds on the market at a price of.pdf
JKL Co issues zero coupon bonds on the market at a price of.pdf
 
Jill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdfJill is offered a choice between receiving 50 with certaint.pdf
Jill is offered a choice between receiving 50 with certaint.pdf
 
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdfJennys Froyo INC Balance Sheet For Year Ended December 31.pdf
Jennys Froyo INC Balance Sheet For Year Ended December 31.pdf
 
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdfJim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
Jim y Sue se iban a casar y estaban muy enamorados Antes de.pdf
 
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdfJhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
Jhania Bive the muk hroutwes ite p+4i if peras bt in +45 te.pdf
 
JAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdfJAVA Please help me on this method The requirement of the m.pdf
JAVA Please help me on this method The requirement of the m.pdf
 
Jennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdfJennifer invested the profit of his business in an investmen.pdf
Jennifer invested the profit of his business in an investmen.pdf
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 

Java Programming Must implement a storage manager that main.pdf

  • 1. Java Programming: Must implement a storage manager that maintains a series of data objects in each data file. This assignment provides you with a set of incomplete classes (, see SlottedPage, FileManager, and BufferedFileManager which contain methods currently throwing an UnsupportedOperationException). You will need to write code for these classes. Your code will be graded by running a set of unit tests and then examining your code (see SlottedPageTest and FileManagerTest which use JUnit1, as well as BufferedFileManagerTest which produces output messages). Note that passing unit tests does NOT necessarily guarantee that your implementation is correct and efficient. Please make sure that your code will not cause any problem in other cases not covered by the unit tests. Below are the files and make sure there are no errors and show the output as well. BufferedFileManager.java package mypack; import java.io.IOException; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; public class BufferedFileManager extends FileManager { private int bufferSize; private Map<Integer, SlottedPage> buffer; public BufferedFileManager(int bufferSize) { this.bufferSize = bufferSize; buffer = new LinkedHashMap<Integer, SlottedPage>(bufferSize); } @Override public void put(int fileID, Long location, Object o) throws IOException, InvalidLocationException { if (buffer.containsKey(first(location))) { SlottedPage p = buffer.get(first(location)); p.put(second(location), o); buffer.put(first(location), p); } else { if (buffer.size() == bufferSize) { // Evict the least recently used page buffer.remove(buffer.keySet().iterator().next()); } SlottedPage p = page(fileID, first(location)); p.put(second(location), o); updated(p, fileID); buffer.put(first(location), p); } } @Override public Object get(int fileID, Long location) throws IOException, InvalidLocationException {
  • 2. if (buffer.containsKey(first(location))) { return buffer.get(first(location)).get(second(location)); } SlottedPage p = page(fileID, first(location)); if (buffer.size() == bufferSize) { // Evict the least recently used page buffer.remove(buffer.keySet().iterator().next()); } buffer.put(first(location), p); return p.get(second(location)); } @Override public Object remove(int fileID, Long location) throws IOException, InvalidLocationException { if (buffer.containsKey(first(location))) { SlottedPage p = buffer.get(first(location)); Object o = p.remove(second(location)); buffer.put(first(location), p); return o; } SlottedPage p = page(fileID, first(location)); Object o = p.remove(second(location)); updated(p, fileID); if (buffer.size() == bufferSize) { // Evict the least recently used page buffer.remove(buffer.keySet().iterator().next()); } buffer.put(first(location), p); return o; } @Override public Iterator<Object> iterator(int fileID) throws IOException { SlottedPage[] pages = pages(fileID); return new BufferedPageIterator(pages, buffer); } } BufferedPageIterator.java package mypack; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; public class BufferedPageIterator implements Iterator<Object>{ private SlottedPage[] pages;
  • 3. private int currPage = 0; private int currIndex = 0; private Map<Integer, SlottedPage> buffer; public BufferedPageIterator(SlottedPage[] pages, Map<Integer, SlottedPage> buffer) { this.pages = pages; this.buffer = buffer; } @Override public boolean hasNext() { if (currPage == pages.length) { return false; } return !(currIndex == pages[currPage].entryCount() && currPage == pages.length - 1); } @Override public Object next() { if (!hasNext()) { throw new NoSuchElementException(); } Object o; if (buffer.containsKey(currPage)) { o = buffer.get(currPage).get(currIndex); } else { o = pages[currPage].get(currIndex); } currIndex++; if (currIndex == pages[currPage].entryCount()) { currPage++; currIndex = 0; } return o; } } FileManager.java package mypack; import java.io.IOException; import java.util.Iterator; public class FileManager { public void put(int fileID, Long location, Object o) throws IOException, InvalidLocationException { if (first(location) < 0) { throw new InvalidLocationException(); }
  • 4. SlottedPage p = page(fileID, first(location)); p.put(second(location), o); updated(p, fileID); } public Object get(int fileID, Long location) throws IOException, InvalidLocationException { if (first(location) < 0) { throw new InvalidLocationException(); } SlottedPage p = page(fileID, first(location)); return p.get(second(location)); } public Object remove(int fileID, Long location) throws IOException, InvalidLocationException { if (first(location) < 0) { throw new InvalidLocationException(); } SlottedPage p = page(fileID, first(location)); return p.remove(second(location)); } public Iterator<Object> iterator(int fileID) throws IOException { SlottedPage[] pages = pages(fileID); return new PageIterator(pages); } } InvalidLocationException.java package mypack; public class InvalidLocationException extends Exception { } PageIterator.java package mypack; import java.util.Iterator; import java.util.NoSuchElementException; public class PageIterator implements Iterator<Object> { private SlottedPage[] pages; private int currPage = 0; private int currIndex = 0; public PageIterator(SlottedPage[] pages) { this.pages = pages; } @Override public boolean hasNext() { if (currPage == pages.length) { return false;
  • 5. } return !(currIndex == pages[currPage].entryCount() && currPage == pages.length - 1); } @Override public Object next() { if (!hasNext()) { throw new NoSuchElementException(); } Object o = pages[currPage].get(currIndex); currIndex++; if (currIndex == pages[currPage].entryCount()) { currPage++; currIndex = 0; } return o; } } SlottedPage.java package mypack; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class SlottedPage { public void add(Object o) throws IOException, NotEnoughSpaceException { int loc = save(o); setEntryCount(entryCount() + 1); saveLocation(entryCount() - 1, loc); } public Object get(int index) { int loc = getLocation(index); if (loc == -1) { return null; } return toObject(b, loc); } public Object remove(int index) { int loc = getLocation(index); if (loc == -1) { return null; } Object o = toObject(b, loc);
  • 6. saveLocation(index, -1); return o; } public Iterator<Object> iterator() { return new SlottedPageIterator(this); } public void compact() { int offset = 0; for (int i = 0; i < entryCount(); i++) { int loc = getLocation(i); if (loc != -1) { int size = size(toObject(b, loc)); if (offset + size >= b.length) { throw new NotEnoughSpaceException(); } move(loc, offset); saveLocation(i, offset); offset += size; } } } public int entryCount() { // TODO Auto-generated method stub return 0; } } SlottedPageIterator.java package mypack; import java.util.Iterator; import java.util.NoSuchElementException; public class SlottedPageIterator implements Iterator<Object>{ private SlottedPage page; private int currIndex = 0; public SlottedPageIterator(SlottedPage page) { this.page = page; } @Override public boolean hasNext() { return !(currIndex == page.entryCount()); } @Override
  • 7. public Object next() { if (!hasNext()) { throw new NoSuchElementException(); } Object o = page.get(currIndex); currIndex++; return o; } }