Hit.java 1.44 KB
/*
 * Decompiled with CFR 0_118.
 */
package com.day.cq.wcm.core.contentfinder;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Hit
implements Comparable<Hit> {
    private Map<String, Object> map = new HashMap<String, Object>();

    public Object get(String name) {
        return this.map.get(name);
    }

    public void set(String name, Object value) {
        this.map.put(name, value);
    }

    public Iterator<String> getKeys() {
        return this.map.keySet().iterator();
    }

    @Override
    public int compareTo(Hit other) {
        long otherLastModified;
        long lastModified = Hit.getLastModified(this);
        if (lastModified < (otherLastModified = Hit.getLastModified(other))) {
            return -1;
        }
        if (lastModified > otherLastModified) {
            return 1;
        }
        String path = Hit.getPath(this);
        String otherPath = Hit.getPath(other);
        return path.compareTo(otherPath);
    }

    private static long getLastModified(Hit hit) {
        Object cal = hit.get("lastModified");
        if (cal instanceof Calendar) {
            return ((Calendar)cal).getTimeInMillis();
        }
        return 0;
    }

    private static String getPath(Hit hit) {
        Object path = hit.get("path");
        if (path instanceof String) {
            return (String)path;
        }
        return "";
    }
}