public static void addToSqlWhere(final SqlBuilder sqlBuilder, final int listId) {

        if (listId == PseudoList.HISTORY_LIST.id) {
            sqlBuilder.addWhere("( visiteddate > 0 OR geocode IN (SELECT geocode FROM " + DataStore.dbTableLogsOffline + ") )");
        } else if (listId > 0) {
            final String clId = sqlBuilder.getNewTableId();
            sqlBuilder.addWhere(sqlBuilder.getMainTableId() + ".geocode IN (SELECT " + clId + ".geocode FROM " + DataStore.dbTableCachesLists + " " + clId + " WHERE list_id " +
                    (listId != PseudoList.ALL_LIST.id ? "=" + listId : ">= " + StoredList.STANDARD_LIST_ID) + ")");
        } else {
            sqlBuilder.addWhereTrue();
        }
    }
filters for any one listid. Supports Storedlist as well as Psuedolist
main/src/main/java/cgeo/geocaching/filters/core/ListIdGeocacheFilter.java