-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathVarSelHandler.java
More file actions
58 lines (52 loc) · 1.84 KB
/
VarSelHandler.java
File metadata and controls
58 lines (52 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* This file is part of choco-parsers, http://choco-solver.org/
*
* Copyright (c) 2023, IMT Atlantique. All rights reserved.
*
* Licensed under the BSD 4-clause license.
*
* See LICENSE file in the project root for full license information.
*/
package org.chocosolver.parser.handlers;
import org.chocosolver.solver.search.strategy.SearchParams;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.OptionDef;
import org.kohsuke.args4j.spi.Messages;
import org.kohsuke.args4j.spi.OneArgumentOptionHandler;
import org.kohsuke.args4j.spi.Setter;
/**
* <br/>
*
* @author Charles Prud'homme
* @since 15/06/2020
*/
public class VarSelHandler extends OneArgumentOptionHandler<SearchParams.VarSelConf> {
public VarSelHandler(CmdLineParser parser, OptionDef option, Setter<? super SearchParams.VarSelConf> setter) {
super(parser, option, setter);
}
/**
* Returns {@code "STRING[]"}.
*
* @return return "STRING[]";
*/
@Override
public String getDefaultMetaVariable() {
return "[String,String,int]";
}
@Override
protected SearchParams.VarSelConf parse(String argument) throws NumberFormatException, CmdLineException {
if (argument.startsWith("[")) argument = argument.substring(1);
if (argument.endsWith("]")) argument = argument.substring(0, argument.length() - 1);
String[] pars = argument.split(",");
if (pars.length == 3) {
return new SearchParams.VarSelConf(
SearchParams.VariableSelection.valueOf(pars[0].toUpperCase()),
SearchParams.VariableTieBreaker.valueOf(pars[1].toUpperCase()),
Integer.parseInt(pars[2])
);
}
throw new CmdLineException(owner,
Messages.ILLEGAL_UUID, argument);
}
}