1919
2020package com .aliyun .oss .model ;
2121
22+ import com .aliyun .oss .common .utils .StringUtils ;
2223import java .util .ArrayList ;
2324import java .util .HashMap ;
2425import java .util .List ;
@@ -41,6 +42,7 @@ enum TupleType {
4142 private TupleType tupleType ;
4243 private long minimum ;
4344 private long maximum ;
45+ private String [] contain ;
4446
4547 public ConditionItem (String name , String value ) {
4648 this .matchMode = MatchMode .Exact ;
@@ -64,6 +66,13 @@ public ConditionItem(MatchMode matchMode, String name, String value) {
6466 this .tupleType = TupleType .Three ;
6567 }
6668
69+ public ConditionItem (MatchMode matchMode , String name , String [] contain ) {
70+ this .matchMode = matchMode ;
71+ this .name = name ;
72+ this .contain = contain ;
73+ this .tupleType = TupleType .Three ;
74+ }
75+
6776 public String jsonize () {
6877 String jsonizedCond = null ;
6978 switch (tupleType ) {
@@ -81,6 +90,12 @@ public String jsonize() {
8190 case Range :
8291 jsonizedCond = String .format ("[\" content-length-range\" ,%d,%d]," , minimum , maximum );
8392 break ;
93+ case In :
94+ jsonizedCond = String .format ("[\" in\" ,\" $%s\" ,[\" %s\" ]]," , name , StringUtils .join ("\" ,\" " ,contain ));
95+ break ;
96+ case NotIn :
97+ jsonizedCond = String .format ("[\" not-in\" ,\" $%s\" ,[\" %s\" ]]," , name , StringUtils .join ("\" ,\" " ,contain ));
98+ break ;
8499 default :
85100 throw new IllegalArgumentException (String .format ("Unsupported match mode %s" , matchMode .toString ()));
86101 }
@@ -162,6 +177,8 @@ public class PolicyConditions {
162177 List <MatchMode > ordinaryMatchModes = new ArrayList <MatchMode >();
163178 ordinaryMatchModes .add (MatchMode .Exact );
164179 ordinaryMatchModes .add (MatchMode .StartWith );
180+ ordinaryMatchModes .add (MatchMode .In );
181+ ordinaryMatchModes .add (MatchMode .NotIn );
165182 List <MatchMode > specialMatchModes = new ArrayList <MatchMode >();
166183 specialMatchModes .add (MatchMode .Range );
167184
@@ -224,6 +241,21 @@ public void addConditionItem(String name, long min, long max) {
224241 _conds .add (new ConditionItem (name , min , max ));
225242 }
226243
244+ /**
245+ * Adds a condition item with specified {@link MatchMode} value.
246+ *
247+ * @param matchMode
248+ * Conditions match mode.
249+ * @param name
250+ * Condition name.
251+ * @param contain
252+ * Condition contain.
253+ */
254+ public void addConditionItem (MatchMode matchMode , String name , String [] contain ) {
255+ checkMatchModes (matchMode , name );
256+ _conds .add (new ConditionItem (matchMode , name .toLowerCase (), contain ));
257+ }
258+
227259 private void checkMatchModes (MatchMode matchMode , String condName ) {
228260 if (_supportedMatchRules .containsKey (condName )) {
229261 List <MatchMode > mms = _supportedMatchRules .get (condName );
0 commit comments