Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getPageTags() and similar methods rewritten #1

Open
wants to merge 2 commits into
base: draft
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/edu/launua/URLManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,17 @@ public String getPageContent() {
return res;
}

public Object[] getPageTags() {
public String[] getPageTags(Collection<String> collection) {
String res = getPageContent();
Pattern pattern = Pattern.compile("<[\\w]+");
Matcher matcher = pattern.matcher(res);
ArrayList<Object> tags = new ArrayList<>();
while(matcher.find()) {
tags.add(res.substring(matcher.start(), matcher.end()) + ">");
}
return tags.toArray();
while(matcher.find())
collection.add(res.substring(matcher.start(), matcher.end()) + ">");
return collection.toArray(new String[collection.size()]);
}

public Object[] getPageTagsSortedSet() {
String res = getPageContent();
Pattern pattern = Pattern.compile("<[\\w]+");
Matcher matcher = pattern.matcher(res);
Set<String> tags = new TreeSet<>();
while(matcher.find())
tags.add(res.substring(matcher.start(), matcher.end()) + ">");
return tags.toArray();
public String[] getPageTagsSortedSet() {
return getPageTags(new TreeSet<>());
}

public Object[] getPageTagsSortedByCountSetOld() {
Expand Down Expand Up @@ -85,8 +77,8 @@ public int compare(Map.Entry<String, Integer> a, Map.Entry<String, Integer> b) {
}

// More clean version
public String[] getPageTagsSortedByCountSet() {
Object[] tags = getPageTags();
public Object[] getPageTagsSortedByCountSet() {
Object[] tags = getPageTags(new ArrayList<String>());
Map<Object, Integer> tagsCount= new HashMap<>();
for (Object tag : tags) {
if(tagsCount.containsKey(tag))
Expand Down
15 changes: 9 additions & 6 deletions tests/edu/launua/URLManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@
import org.junit.Before;
import org.junit.Test;

import java.util.*;
import java.util.regex.Pattern;

import java.net.MalformedURLException;
import java.util.Map;
import java.util.regex.Pattern;
import static org.junit.Assert.*;

public class URLManagerTest {
String url;
URLManager urlManager;

@Before
public void testSetUp() throws Exception {
urlManager = new URLManager("file:///C:/Users/Air/IdeaProjects/IT-62/Collector/index.html");
// urlManager = new URLManager("http://kinogo.cc/7232-astral-4-posledniy-klyuchs-2018.html");
url = "file:////C://Users//San//IdeaProjects//Collector//index.html";
urlManager = new URLManager(url);
}

@After
Expand All @@ -24,12 +27,12 @@ public void testTearDown() throws Exception {

@Test
public void testGetUrl() {
assertEquals("file:///C:/Users/Air/IdeaProjects/IT-62/Collector/index.html", urlManager.getUrl());
assertNotEquals("file:///C:/Users/Air/IdeaProjects/IT-62/Colector/index.html", urlManager.getUrl());
assertEquals(url, urlManager.getUrl());
}

@Test
public void testSetUrl() {
urlManager.setUrl("something wrong");
}

@Test
Expand Down