Skip to content

Commit

Permalink
Merge #120
Browse files Browse the repository at this point in the history
120: fix: fixed for the issue (#117) r=myConsciousness a=myConsciousness

# 1. Description

<!-- Provide a description of what this PR is doing.
If you're modifying existing behavior, describe the existing behavior, how this PR is changing it,
and what motivated the change. If this is a breaking change, specify explicitly which APIs have been
changed. -->

## 1.1. Checklist

<!-- Before you create this PR confirm that it meets all requirements listed below by checking the
relevant checkboxes (`[x]`). This will ensure a smooth and quick review process. -->

- [x] The title of my PR starts with a [Conventional Commit] prefix (`fix:`, `feat:`, `docs:` etc).
- [x] I have read the [Contributor Guide] and followed the process outlined for submitting PRs.
- [x] I have updated/added tests for ALL new/updated/fixed functionality.
- [x] I have updated/added relevant documentation in `docs` and added dartdoc comments with `///`.
- [x] I have updated/added relevant examples in `examples`.

## 1.2. Breaking Change

<!-- Does your PR require batch.dart users to manually update their apps to accommodate your change?

If the PR is a breaking change this should be indicated with suffix "!"  (for example, `feat!:`, `fix!:`). See [Conventional Commit] for details.
-->

- [ ] Yes, this is a breaking change.
- [x] No, this is _not_ a breaking change.

## 1.3. Related Issues

<!-- Provide a list of issues related to this PR from the [issue database].
Indicate which of these issues are resolved or fixed by this PR, i.e. Fixes #xxxx* !-->

<!-- Links -->

[issue database]: https://github.com/batch-dart/batch.dart/issues
[contributor guide]: https://github.com/batch-dart/batch.dart/blob/main/CONTRIBUTING.md
[batch.dart style guide]: https://github.com/batch-dart/batch.dart/blob/main/STYLEGUIDE.md
[conventional commit]: https://conventionalcommits.org


Co-authored-by: myConsciousness <kato.shinya.dev@gmail.com>
  • Loading branch information
bors[bot] and myConsciousness authored Apr 10, 2022
2 parents 3345ada + ad88984 commit a5d2e30
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## v0.9.0

- Improved schedule checking process. ([#118](https://github.com/batch-dart/batch.dart/issues/118))
- Fixed handling of duplicate keys in `Parameters`. ([#117](https://github.com/batch-dart/batch.dart/issues/117))

## v0.8.1

Expand Down
8 changes: 6 additions & 2 deletions lib/src/job/parameter/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ class Parameters {
}

/// Adds [value] as a parameter associated with [key].
void operator []=(final String key, final dynamic value) =>
_objects.add(Parameter(key: key, value: value));
void operator []=(final String key, final dynamic value) => _objects
..removeWhere((parameter) => parameter.key == key)
..add(Parameter(key: key, value: value));

/// Removes all parameters.
void removeAll() => _objects.removeRange(0, _objects.length);
Expand All @@ -46,6 +47,9 @@ class Parameters {
/// Returns true if this object has parameter, otherwise false.
bool get isNotEmpty => _objects.isNotEmpty;

/// Returns the number of parameters.
int get length => _objects.length;

@override
String toString() => _objects.toString();
}
14 changes: 14 additions & 0 deletions test/src/job/parameter/parameters_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ void main() {
expect(parameters.isNotEmpty, false);
expect(parameters.contains('testKey'), false);
});

test('Test duplicated keys', () {
final parameters = Parameters();
parameters['duplicatedKey'] = false;
parameters['duplicatedKey'] = true;

expect(parameters['duplicatedKey'], isTrue);
expect(parameters.length == 1, isTrue);

parameters['duplicatedKey'] = false;

expect(parameters['duplicatedKey'], isFalse);
expect(parameters.length == 1, isTrue);
});
}

0 comments on commit a5d2e30

Please sign in to comment.