summaryrefslogtreecommitdiffstats
path: root/sched
diff options
context:
space:
mode:
Diffstat (limited to 'sched')
-rw-r--r--sched/src/com/android/sched/util/codec/ConvertCodec.java14
-rw-r--r--sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java16
-rw-r--r--sched/src/com/android/sched/util/codec/ParsingException.java13
3 files changed, 37 insertions, 6 deletions
diff --git a/sched/src/com/android/sched/util/codec/ConvertCodec.java b/sched/src/com/android/sched/util/codec/ConvertCodec.java
index e32a293..60cbd83 100644
--- a/sched/src/com/android/sched/util/codec/ConvertCodec.java
+++ b/sched/src/com/android/sched/util/codec/ConvertCodec.java
@@ -16,14 +16,16 @@
package com.android.sched.util.codec;
+import com.android.sched.util.config.ConfigurationError;
+
import java.util.List;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
/**
- * This {@link StringCodec} is used to convert a {@link StringCodec<SRC>} to a {@link StringCodec
- * <DST>}.
+ * This {@link StringCodec} is used to convert a {@code StringCodec<SRC>} to a
+ * {@code StringCodec<DST>}.
*/
public abstract class ConvertCodec<SRC, DST> implements StringCodec<DST> {
@Nonnull
@@ -34,13 +36,17 @@ public abstract class ConvertCodec<SRC, DST> implements StringCodec<DST> {
}
@Nonnull
- protected abstract DST convert(@Nonnull SRC src);
+ protected abstract DST convert(@Nonnull SRC src) throws ParsingException;
@Override
@Nonnull
public DST parseString(@Nonnull CodecContext context, @Nonnull String string) {
- return convert(codec.parseString(context, string));
+ try {
+ return convert(codec.parseString(context, string));
+ } catch (ParsingException e) {
+ throw new ConfigurationError(e);
+ }
}
@Override
diff --git a/sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java b/sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java
index daa3a4a..b4867f0 100644
--- a/sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java
+++ b/sched/src/com/android/sched/util/codec/PairListToMapCodecConverter.java
@@ -16,6 +16,8 @@
package com.android.sched.util.codec;
+import com.android.sched.util.config.ChainedException.ChainedExceptionBuilder;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -47,12 +49,22 @@ public class PairListToMapCodecConverter<T, U> extends
@Override
@Nonnull
- protected Map<T, U> convert(@Nonnull List<Entry<T, U>> list) {
+ protected Map<T, U> convert(@Nonnull List<Entry<T, U>> list) throws ParsingException {
+ ChainedExceptionBuilder<ParsingException> exceptions =
+ new ChainedExceptionBuilder<ParsingException>();
Map<T, U> map = new HashMap<T, U>(Math.round(list.size() / 0.75f), 0.75f);
+ int index = 1;
for (Entry<T, U> entry : list) {
- map.put(entry.getKey(), entry.getValue());
+ if (!map.containsKey(entry.getKey())) {
+ map.put(entry.getKey(), entry.getValue());
+ } else {
+ exceptions.appendException(new ListParsingException(index, "Value for '"
+ + entry.getKey() + "' is already defined"));
+ }
+ index++;
}
+ exceptions.throwIfNecessary();
return map;
}
diff --git a/sched/src/com/android/sched/util/codec/ParsingException.java b/sched/src/com/android/sched/util/codec/ParsingException.java
index 759f978..78b1962 100644
--- a/sched/src/com/android/sched/util/codec/ParsingException.java
+++ b/sched/src/com/android/sched/util/codec/ParsingException.java
@@ -18,6 +18,8 @@ package com.android.sched.util.codec;
import com.android.sched.util.config.ChainedException;
+import java.util.Iterator;
+
import javax.annotation.Nonnull;
@@ -39,4 +41,15 @@ public class ParsingException extends ChainedException {
public ParsingException(@Nonnull String message, @Nonnull Throwable cause) {
super(message, cause);
}
+
+ public ParsingException(@Nonnull ChainedException causes) {
+ this((Throwable) causes);
+
+ Iterator<ChainedException> iter = causes.iterator();
+ iter.next();
+ while (iter.hasNext()) {
+ new ParsingException(iter.next()).putAsLastExceptionOf(this);
+ }
+ }
+
}