Skip to content

Commit 2cf9697

Browse files
authored
Merge pull request #492 from albertotn/description-italian
fixed some tests in italian
2 parents 2c25b4b + 9fcb6e4 commit 2cf9697

4 files changed

Lines changed: 580 additions & 552 deletions

File tree

Lines changed: 82 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,82 @@
1-
package com.cronutils.descriptor.refactor;
2-
3-
import com.cronutils.model.Cron;
4-
import com.cronutils.model.field.CronField;
5-
import com.cronutils.model.field.CronFieldName;
6-
import com.cronutils.model.field.expression.Always;
7-
import com.cronutils.model.field.expression.Every;
8-
import com.cronutils.model.field.expression.On;
9-
import com.cronutils.utils.Preconditions;
10-
import com.cronutils.utils.StringUtils;
11-
12-
import java.text.ChoiceFormat;
13-
import java.text.Format;
14-
import java.text.MessageFormat;
15-
import java.text.NumberFormat;
16-
import java.util.Locale;
17-
import java.util.Map;
18-
import java.util.ResourceBundle;
19-
20-
public class TimeDescriptor {
21-
22-
private final ResourceBundle resourceBundle;
23-
24-
public TimeDescriptor(final ResourceBundle resourceBundle) {
25-
this.resourceBundle = Preconditions.checkNotNull(resourceBundle, "The resource bundle must not be null");
26-
}
27-
28-
29-
public String describe(final Cron cron) {
30-
return describe(cron.retrieveFieldsAsMap());
31-
}
32-
33-
private String describe(final Map<CronFieldName, CronField> expressions) {
34-
35-
if (expressions.containsKey(CronFieldName.SECOND)) {
36-
final CronField cronField = expressions.get(CronFieldName.SECOND);
37-
if (cronField.getExpression() instanceof Always) {
38-
return describeEverySecond(1);
39-
} else if (cronField.getExpression() instanceof On) {
40-
return describeAtSecond(((On)cronField.getExpression()).getTime().getValue());
41-
} else if (cronField.getExpression() instanceof Every) {
42-
return describeEverySecond(((Every)cronField.getExpression()).getPeriod().getValue());
43-
}
44-
}
45-
46-
47-
return StringUtils.EMPTY;
48-
}
49-
50-
private String describeEverySecond(final int second) {
51-
final double[] secondsLimit = {1, 2};
52-
final String[] secondsStrings = {
53-
resourceBundle.getString("oneSecond"),
54-
resourceBundle.getString("multipleSeconds")
55-
};
56-
final double[] everyLimit = {1,2};
57-
final String[] everyStrings = {
58-
resourceBundle.getString("every_one"),
59-
resourceBundle.getString("every_multi")
60-
};
61-
62-
final ChoiceFormat secondsChoiceFormat = new ChoiceFormat(secondsLimit, secondsStrings);
63-
final ChoiceFormat everyChoiceFormat = new ChoiceFormat(everyLimit, everyStrings);
64-
final String pattern = resourceBundle.getString("pattern_every_seconds");
65-
66-
final MessageFormat messageFormat = new MessageFormat(pattern, Locale.UK);
67-
68-
final Format[] formats = { everyChoiceFormat, secondsChoiceFormat, NumberFormat.getInstance() };
69-
messageFormat.setFormats(formats);
70-
final Object[] messageArguments = {second, second, second };
71-
final String result = messageFormat.format(messageArguments);
72-
return result;
73-
}
74-
75-
private String describeAtSecond(final int second) {
76-
77-
final String pattern = resourceBundle.getString("pattern_at_second");
78-
79-
final MessageFormat messageFormat = new MessageFormat(pattern, Locale.UK);
80-
final Format[] formats = {NumberFormat.getInstance()};
81-
messageFormat.setFormats(formats);
82-
83-
final Object[] messageArguments = { second };
84-
final String result = messageFormat.format(messageArguments);
85-
return result;
86-
}
87-
88-
}
1+
package com.cronutils.descriptor.refactor;
2+
3+
import java.text.ChoiceFormat;
4+
import java.text.Format;
5+
import java.text.MessageFormat;
6+
import java.text.NumberFormat;
7+
import java.util.Locale;
8+
import java.util.Map;
9+
import java.util.ResourceBundle;
10+
11+
import com.cronutils.model.Cron;
12+
import com.cronutils.model.field.CronField;
13+
import com.cronutils.model.field.CronFieldName;
14+
import com.cronutils.model.field.expression.Always;
15+
import com.cronutils.model.field.expression.Every;
16+
import com.cronutils.model.field.expression.On;
17+
import com.cronutils.utils.Preconditions;
18+
import com.cronutils.utils.StringUtils;
19+
20+
public class TimeDescriptor {
21+
22+
private final ResourceBundle resourceBundle;
23+
24+
public TimeDescriptor(final ResourceBundle resourceBundle) {
25+
this.resourceBundle = Preconditions.checkNotNull(resourceBundle, "The resource bundle must not be null");
26+
}
27+
28+
public String describe(final Cron cron) {
29+
return describe(cron.retrieveFieldsAsMap());
30+
}
31+
32+
private String describe(final Map<CronFieldName, CronField> expressions) {
33+
34+
if (expressions.containsKey(CronFieldName.SECOND)) {
35+
final CronField cronField = expressions.get(CronFieldName.SECOND);
36+
if (cronField.getExpression() instanceof Always) {
37+
return describeEverySecond(1);
38+
} else if (cronField.getExpression() instanceof On) {
39+
return describeAtSecond(((On) cronField.getExpression()).getTime().getValue());
40+
} else if (cronField.getExpression() instanceof Every) {
41+
return describeEverySecond(((Every) cronField.getExpression()).getPeriod().getValue());
42+
}
43+
}
44+
45+
return StringUtils.EMPTY;
46+
}
47+
48+
private String describeEverySecond(final int second) {
49+
final double[] secondsLimit = { 1, 2 };
50+
final String[] secondsStrings = { resourceBundle.getString("oneSecond"),
51+
resourceBundle.getString("multipleSeconds") };
52+
final double[] everyLimit = { 1, 2 };
53+
final String[] everyStrings = { resourceBundle.getString("every_one"),
54+
resourceBundle.getString("every_multi") };
55+
56+
final ChoiceFormat secondsChoiceFormat = new ChoiceFormat(secondsLimit, secondsStrings);
57+
final ChoiceFormat everyChoiceFormat = new ChoiceFormat(everyLimit, everyStrings);
58+
final String pattern = resourceBundle.getString("pattern_every_seconds");
59+
60+
final MessageFormat messageFormat = new MessageFormat(pattern, Locale.UK);
61+
62+
final Format[] formats = { everyChoiceFormat, secondsChoiceFormat, NumberFormat.getInstance() };
63+
messageFormat.setFormats(formats);
64+
final Object[] messageArguments = { second, second, second };
65+
final String result = messageFormat.format(messageArguments);
66+
return result;
67+
}
68+
69+
private String describeAtSecond(final int second) {
70+
71+
final String pattern = resourceBundle.getString("pattern_at_second");
72+
73+
final MessageFormat messageFormat = new MessageFormat(pattern, Locale.UK);
74+
final Format[] formats = { NumberFormat.getInstance() };
75+
messageFormat.setFormats(formats);
76+
77+
final Object[] messageArguments = { second };
78+
final String result = messageFormat.format(messageArguments);
79+
return result;
80+
}
81+
82+
}
Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
/*
2-
* Copyright 2015 jmrozanec
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
* http://www.apache.org/licenses/LICENSE-2.0
8-
* Unless required by applicable law or agreed to in writing, software
9-
* distributed under the License is distributed on an "AS IS" BASIS,
10-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11-
* See the License for the specific language governing permissions and
12-
* limitations under the License.
13-
*/
14-
15-
package com.cronutils.model.field.expression;
16-
17-
import com.cronutils.model.field.expression.visitor.FieldExpressionVisitor;
18-
import com.cronutils.utils.Preconditions;
19-
20-
import java.io.Serializable;
21-
22-
public abstract class FieldExpression implements Serializable {
23-
24-
private static final long serialVersionUID = 5138279438874391617L;
25-
26-
public And and(final FieldExpression exp) {
27-
return new And().and(this).and(exp);
28-
}
29-
30-
/**
31-
* Represents FieldExpression as string.
32-
*
33-
* @return String representation, never null.
34-
*/
35-
public abstract String asString();
36-
37-
/**
38-
* Accept a visitor to perform some action on the instance. Current instance is cloned, so that we ensure immutability. Clone of this
39-
* instance is returned after visitor.visit(clone) was invoked.
40-
*
41-
* @param visitor - FieldExpressionVisitor instance, never null
42-
* @return FieldExpression copied instance with visitor action performed.
43-
*/
44-
public abstract FieldExpression accept(final FieldExpressionVisitor visitor);
45-
46-
public static FieldExpression always() {
47-
return Always.INSTANCE;
48-
}
49-
50-
public static FieldExpression questionMark() {
51-
return QuestionMark.INSTANCE;
52-
}
53-
}
1+
/*
2+
* Copyright 2015 jmrozanec
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.cronutils.model.field.expression;
16+
17+
import java.io.Serializable;
18+
19+
import com.cronutils.model.field.expression.visitor.FieldExpressionVisitor;
20+
21+
public abstract class FieldExpression implements Serializable {
22+
23+
private static final long serialVersionUID = 5138279438874391617L;
24+
25+
public And and(final FieldExpression exp) {
26+
return new And().and(this).and(exp);
27+
}
28+
29+
/**
30+
* Represents FieldExpression as string.
31+
*
32+
* @return String representation, never null.
33+
*/
34+
public abstract String asString();
35+
36+
/**
37+
* Accept a visitor to perform some action on the instance. Current instance is
38+
* cloned, so that we ensure immutability. Clone of this instance is returned
39+
* after visitor.visit(clone) was invoked.
40+
*
41+
* @param visitor - FieldExpressionVisitor instance, never null
42+
* @return FieldExpression copied instance with visitor action performed.
43+
*/
44+
public abstract FieldExpression accept(final FieldExpressionVisitor visitor);
45+
46+
public static FieldExpression always() {
47+
return Always.INSTANCE;
48+
}
49+
50+
public static FieldExpression questionMark() {
51+
return QuestionMark.INSTANCE;
52+
}
53+
}
Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
between_x_and_y=tra {0} e {1}
2-
every=ogni
3-
and=e
4-
at=alle
5-
day=giorno
6-
days=giorni
7-
hour=ora
8-
hours=ore
9-
minute=minuto
10-
minutes=minuti
11-
second=secondo
12-
seconds=secondi
13-
month=mese
14-
months=mesi
15-
year=anno
16-
years=anni
17-
between=tra
18-
of_every_month=di ogni mese
19-
of_the_month=del mese
20-
last=ultimo
21-
the_nearest_weekday_to_the=il giorno della settimana più vicino a
22-
last_day_of_month=ultimo giorno del mese
23-
last_weekday_of_month=ultimo giorno della settimana nel mese
24-
day_before_last_day_of_month=un giorno prima dell'ultimo giorno del mese
25-
days_before_last_day_of_month={0} giorni prima dell'ultimo giorno del mese
1+
between_x_and_y=tra {0} e {1}
2+
every=ogni
3+
and=e
4+
at=alle
5+
day=giorno
6+
days=giorni
7+
hour=ora
8+
hours=ore
9+
minute=minuto
10+
minutes=minuti
11+
second=secondo
12+
seconds=secondi
13+
month=mese
14+
months=mesi
15+
year=anno
16+
years=anni
17+
between=tra
18+
of_every_month=di ogni mese
19+
of_the_month=del mese
20+
last=ultimo
21+
the_nearest_weekday_to_the=il giorno della settimana piu' vicino a
22+
last_day_of_month=ultimo giorno del mese
23+
last_weekday_of_month=ultimo giorno della settimana nel mese
24+
day_before_last_day_of_month=un giorno prima dell'ultimo giorno del mese
25+
days_before_last_day_of_month={0} giorni prima dell'ultimo giorno del mese
26+
27+
pattern_every_seconds = {0} {1}
28+
every_one=ogni
29+
every_multi=ogni
30+
oneSecond=secondo
31+
multipleSeconds={2} secondi
32+
33+
pattern_at_second=al secondo {0}

0 commit comments

Comments
 (0)