Skip to content

Commit

Permalink
Merge pull request square#133 from roman-mazur/roman/fix-intent-flags
Browse files Browse the repository at this point in the history
Fix hasFlags method in IntentAssert
  • Loading branch information
JakeWharton committed Sep 25, 2014
2 parents 9efe9e3 + 3e95ae6 commit ee1e5d4
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.assertj.android.internal;

import android.util.SparseArray;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.LinkedHashMap;
import java.util.Map;
import org.assertj.core.util.Strings;

public final class IntegerUtils {
Expand All @@ -21,22 +21,19 @@ public static NamedValueStringBuilder buildNamedValueString(int value) {

public static final class BitMaskStringBuilder {
private final int value;
private final Set<String> parts = new LinkedHashSet<>();
private int flags;
private final Map<Integer, String> parts = new LinkedHashMap<>();

private BitMaskStringBuilder(int value) {
this.value = value;
}

public BitMaskStringBuilder flag(int flag, String flagName) {
if ((flags & flag) != 0) {
throw new IllegalStateException(
"Duplicate flag detected: " + flagName + " with value " + Integer.toHexString(flag));
}
flags |= flag;

if ((value & flag) != 0) {
parts.add(flagName);
if (parts.containsKey(flag)) {
parts.put(flag, parts.get(flag) + "|" + flagName);
} else {
parts.put(flag, flagName);
}
}
return this;
}
Expand All @@ -45,7 +42,7 @@ public String get() {
if (value == 0) {
return "none";
}
return Strings.join(parts).with(", ");
return Strings.join(parts.values()).with(", ");
}
}

Expand Down

0 comments on commit ee1e5d4

Please sign in to comment.