25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 2 ■ Working with Classes and Dependencies<br />

Listing 2-4. MySearchEngine.java<br />

package com.apress.isf.java.service;<br />

import java.util.ArrayList;<br />

import java.util.List;<br />

import com.apress.isf.java.model.Document;<br />

import com.apress.isf.java.model.Type;<br />

import com.apress.isf.java.service.SearchEngine;<br />

public class MySearchEngine implements SearchEngine {<br />

@Override<br />

public List findByType(Type documentType) {<br />

List result = new ArrayList();<br />

for(Document document : storage()){<br />

if(document.getType().getName()<br />

.equals(documentType.getName()))<br />

result.add(document);<br />

}<br />

return result;<br />

}<br />

@Override<br />

public List listAll() {<br />

return storage();<br />

}<br />

private List storage(){<br />

List result = new ArrayList();<br />

Type type = new Type();<br />

type.setName("PDF");<br />

type.setDesc("Portable Document Format");<br />

type.setExtension(".pdf");<br />

Document document = new Document();<br />

document.setName("Book Template");<br />

document.setType(type);<br />

document.setLocation("/Documents/Book Template.pdf");<br />

result.add(document);<br />

//More Types and Documents omitted<br />

}<br />

}<br />

return result;<br />

16

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!