Skip to content

Commit

Permalink
NUTCH-3073 Address Java compiler warning
Browse files Browse the repository at this point in the history
- add missing type arguments (Collections, etc.)
- remove unnecessary casts
- remove unused variables
  • Loading branch information
sebastian-nagel committed Oct 4, 2024
1 parent 13fcef8 commit e678777
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/java/org/apache/nutch/service/NutchReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public interface NutchReader {
public interface NutchReader {

static final Logger LOG = LoggerFactory
.getLogger(MethodHandles.lookup().lookupClass());
public static final Configuration conf = NutchConfiguration.create();

public List read(String path) throws FileNotFoundException;
public List head(String path, int nrows) throws FileNotFoundException;
public List slice(String path, int start, int end) throws FileNotFoundException;
public List<?> read(String path) throws FileNotFoundException;
public List<?> head(String path, int nrows) throws FileNotFoundException;
public List<?> slice(String path, int start, int end) throws FileNotFoundException;
public int count(String path) throws FileNotFoundException;
}
14 changes: 7 additions & 7 deletions src/java/org/apache/nutch/service/impl/LinkReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import org.apache.nutch.scoring.webgraph.LinkDatum;
import org.apache.nutch.service.NutchReader;

public class LinkReader implements NutchReader{
public class LinkReader implements NutchReader {

@Override
public List read(String path) throws FileNotFoundException {
List<HashMap> rows= new ArrayList<>();
public List<HashMap<String, String>> read(String path) throws FileNotFoundException {
List<HashMap<String, String>> rows= new ArrayList<>();
Path file = new Path(path);
SequenceFile.Reader reader;
try{
Expand Down Expand Up @@ -69,8 +69,8 @@ public List read(String path) throws FileNotFoundException {
}

@Override
public List head(String path, int nrows) throws FileNotFoundException {
List<HashMap> rows= new ArrayList<>();
public List<HashMap<String, String>> head(String path, int nrows) throws FileNotFoundException {
List<HashMap<String, String>> rows= new ArrayList<>();
Path file = new Path(path);
SequenceFile.Reader reader;
try{
Expand Down Expand Up @@ -101,9 +101,9 @@ public List head(String path, int nrows) throws FileNotFoundException {
}

@Override
public List slice(String path, int start, int end)
public List<HashMap<String, String>> slice(String path, int start, int end)
throws FileNotFoundException {
List<HashMap> rows= new ArrayList<>();
List<HashMap<String, String>> rows= new ArrayList<>();
Path file = new Path(path);
SequenceFile.Reader reader;
try{
Expand Down
12 changes: 6 additions & 6 deletions src/java/org/apache/nutch/service/impl/NodeReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
public class NodeReader implements NutchReader {

@Override
public List read(String path) throws FileNotFoundException {
List<HashMap> rows= new ArrayList<>();
public List<HashMap<String, String>> read(String path) throws FileNotFoundException {
List<HashMap<String, String>> rows= new ArrayList<>();
Path file = new Path(path);
SequenceFile.Reader reader;
try{
Expand Down Expand Up @@ -70,8 +70,8 @@ public List read(String path) throws FileNotFoundException {
}

@Override
public List head(String path, int nrows) throws FileNotFoundException {
List<HashMap> rows= new ArrayList<>();
public List<HashMap<String, String>> head(String path, int nrows) throws FileNotFoundException {
List<HashMap<String, String>> rows= new ArrayList<>();
Path file = new Path(path);
SequenceFile.Reader reader;
try{
Expand Down Expand Up @@ -102,9 +102,9 @@ public List head(String path, int nrows) throws FileNotFoundException {
}

@Override
public List slice(String path, int start, int end)
public List<HashMap<String, String>> slice(String path, int start, int end)
throws FileNotFoundException {
List<HashMap> rows= new ArrayList<>();
List<HashMap<String, String>> rows= new ArrayList<>();
Path file = new Path(path);
SequenceFile.Reader reader;
try{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public class ArbitraryIndexingFilter implements IndexingFilter {
public NutchDocument filter(NutchDocument doc, Parse parse, Text url,
CrawlDatum datum, Inlinks inlinks) throws IndexingException {

Class theClass = null;
Class<?> theClass = null;
Method theMethod = null;
Constructor<?> theConstructor = null;
Object instance = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ public void testBasicIndexingFilter() throws Exception {
Assert.assertEquals("test content", "this is a sample foo",
doc.getField("content").getValues().get(0));
Assert.assertEquals("test fetch time", new Date(100L),
(Date) doc.getField("tstamp").getValues().get(0));
doc.getField("tstamp").getValues().get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static synchronized BoilerpipeExtractor getExtractor(String boilerpipeExt
// Attempt to load the class
try {
ClassLoader loader = BoilerpipeExtractor.class.getClassLoader();
Class extractorClass = loader.loadClass(boilerpipeExtractorName);
Class<?> extractorClass = loader.loadClass(boilerpipeExtractorName);

// Add an instance to the repository
extractorRepository.put(boilerpipeExtractorName, (BoilerpipeExtractor)extractorClass.getConstructor().newInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public class MetadataScoringFilter extends AbstractScoringFilter {
private static String[] datumMetadata;
private static String[] contentMetadata;
private static String[] parseMetadata;
private Configuration conf;

/**
* This will take the metadata that you have listed in your "scoring.parse.md"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void distributeScoreToOutlinks() throws ScoringFilterException {
parseData.getParseMeta().add("parent",parentMD);
parseData.getParseMeta().add("depth",depthMD);

HashMap<Text,CrawlDatum> targets = new HashMap();
HashMap<Text,CrawlDatum> targets = new HashMap<>();
targets.put(new Text("https://nutch.apache.org/downloads.html"),new CrawlDatum());
targets.put(new Text("https://wiki.apache.org/nutch"),new CrawlDatum());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static CollectionManager getCollectionManager(Configuration conf) {
* @return Named SubCollection (or null if not existing)
*/
public Subcollection getSubColection(final String id) {
return (Subcollection) collectionMap.get(id);
return collectionMap.get(id);
}

/**
Expand Down Expand Up @@ -180,10 +180,10 @@ public Subcollection createSubCollection(final String id, final String name) {
*/
public List<Subcollection> getSubCollections(final String url) {
List<Subcollection> collections = new ArrayList<Subcollection>();
final Iterator iterator = collectionMap.values().iterator();
final Iterator<Subcollection> iterator = collectionMap.values().iterator();

while (iterator.hasNext()) {
final Subcollection subCol = (Subcollection) iterator.next();
final Subcollection subCol = iterator.next();
if (subCol.filter(url) != null) {
collections.add(subCol);
}
Expand All @@ -200,7 +200,7 @@ public List<Subcollection> getSubCollections(final String url) {
*
* @return All collections CollectionManager knows about
*/
public Collection getAll() {
public Collection<Subcollection> getAll() {
return collectionMap.values();
}

Expand All @@ -219,10 +219,10 @@ public void save() throws IOException {
final Document doc = new DocumentImpl();
final Element collections = doc
.createElement(Subcollection.TAG_COLLECTIONS);
final Iterator iterator = collectionMap.values().iterator();
final Iterator<Subcollection> iterator = collectionMap.values().iterator();

while (iterator.hasNext()) {
final Subcollection subCol = (Subcollection) iterator.next();
final Subcollection subCol = iterator.next();
final Element collection = doc
.createElement(Subcollection.TAG_COLLECTION);
collections.appendChild(collection);
Expand Down
5 changes: 2 additions & 3 deletions src/test/org/apache/nutch/crawl/CrawlDbUpdateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,15 @@ public Path getWorkingDirectory() throws IOException {
* list of input CrawlDatums
* @return list of resulting CrawlDatum(s) in CrawlDb
*/
@SuppressWarnings("unchecked")
public List<CrawlDatum> update(List<CrawlDatum> values) {
if (values == null || values.size() == 0) {
return new ArrayList<CrawlDatum>(0);
}
Collections.shuffle(values); // sorting of values should have no influence
DummyContext context = new DummyContext();
try {
Iterable<CrawlDatum> iterable_values = (Iterable)values;
reducer.reduce(dummyURL, iterable_values, (Reducer<Text, CrawlDatum, Text, CrawlDatum>.Context) context);
Iterable<CrawlDatum> iterable_values = values;
reducer.reduce(dummyURL, iterable_values, context);
} catch (IOException e) {
LOG.error(StringUtils.stringifyException(e));
} catch (InterruptedException e) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/org/apache/nutch/crawl/TestCrawlDbStates.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ public void testCrawlDbStateTransitionMatrix() {
LOG.info("Test CrawlDatum state transitions");
Reducer<Text, CrawlDatum, Text, CrawlDatum>.Context context = CrawlDBTestUtil.createContext();
Configuration conf = context.getConfiguration();
CrawlDbUpdateUtil updateDb = null;
CrawlDbUpdateUtil<CrawlDbReducer> updateDb = null;
try {
updateDb = new CrawlDbUpdateUtil(
updateDb = new CrawlDbUpdateUtil<>(
new CrawlDbReducer(), context);
} catch (IOException e) {
e.printStackTrace();
Expand Down

0 comments on commit e678777

Please sign in to comment.