18
18
namespace Contractor.ContractMatcher {
20
* get contracts which support the passed MIME types
22
* @param mime_types the MIME types which have to be supported by the returned contracts
23
* @param contracts_to_filter a list of contracts to filter
25
* @return a Collection of Contract objects which support the file size
19
27
public Gee.Collection<Contract> get_contracts_for_types (string[] mime_types,
20
28
Gee.Collection<Contract> contracts_to_filter) throws ContractorError
22
30
var valid_contracts = new Gee.LinkedList<Contract> ();
23
31
var valid_mime_types = String.clean_array (mime_types);
25
if (valid_mime_types.length == 0)
33
if (valid_mime_types.length == 0) {
26
34
throw new ContractorError.NO_MIMETYPES_GIVEN ("No mimetypes were provided.");
28
37
foreach (var contract in contracts_to_filter) {
29
38
// Check if the contract supports ALL the types listed in mime_types
39
if (all_types_supported)
40
valid_contracts.add (contract);
48
if (all_types_supported) {
49
valid_contracts.add (contract);
53
return valid_contracts;
57
* get contracts which support the passed file size
59
* @param file_size the file size which has to be supported by the returned contracts
60
* @param contracts_to_filter a list of contracts to filter
62
* @return a Collection of Contract objects which support the file size
64
public Gee.Collection<Contract> get_contracts_for_file_size (int64 file_size,
65
Gee.Collection<Contract> contracts_to_filter) throws ContractorError
67
var valid_contracts = new Gee.LinkedList<Contract> ();
69
foreach (var contract in contracts_to_filter) {
70
bool file_size_supported = true;
72
if (!contract.supports_file_size (file_size)) {
73
file_size_supported = false;
76
if (file_size_supported)
77
valid_contracts.add (contract);
80
return valid_contracts;
84
* get contracts which support the passed MIME types and file size
86
* @param mime_types the MIME types which have to be supported by the returned contracts
87
* @param file_size the file size which has to be supported by the returned contracts
88
* @param contracts_to_filter a list of contracts to filter
90
* @return a Collection of Contract objects which support the MIME types and the file size
92
public Gee.Collection<Contract> get_contracts_for_types_and_file_size (string[] mime_types,
93
int64 file_size, Gee.Collection<Contract> contracts_to_filter) throws ContractorError
95
var contracts_for_types = get_contracts_for_types (mime_types, contracts_to_filter);
96
var valid_contracts = get_contracts_for_file_size (file_size, contracts_for_types);
43
98
return valid_contracts;