Skip to content

Commit

Permalink
Use var less in favor of final
Browse files Browse the repository at this point in the history
  • Loading branch information
JosefWN committed Apr 19, 2022
1 parent 21ab7b7 commit beeed5c
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion example/cancel_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ FutureOr<void> main(List<String> args) async {
final helloRespFuture = client.get('hello');

print('Sending async get /doesNotExist to ${uri.host}');
var ignoreThisFuture = client.send(cancelThisReq);
final ignoreThisFuture = client.send(cancelThisReq);

print('Cancelling get /doesNotExist retries');
client.cancel(cancelThisReq);
Expand Down
2 changes: 1 addition & 1 deletion example/post_resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FutureOr<void> main(List<String> args) async {
final uri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
final client = CoapClient(uri, conf);

var opt = CoapOption.createUriQuery(
final opt = CoapOption.createUriQuery(
'${CoapLinkFormat.title}=This is an SJH Post request');

try {
Expand Down
2 changes: 1 addition & 1 deletion example/put_resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FutureOr<void> main(List<String> args) async {
final uri = Uri(scheme: 'coap', host: 'coap.me', port: conf.defaultPort);
final client = CoapClient(uri, conf);

var opt = CoapOption.createUriQuery(
final opt = CoapOption.createUriQuery(
'${CoapLinkFormat.title}=This is an SJH Put request');

try {
Expand Down
2 changes: 1 addition & 1 deletion example/sync_vs_async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ FutureOr main() async {

print('Sending 10 sync requests...');
for (var i = 0; i < 10; i++) {
var resp = await client.get('test');
final resp = await client.get('test');
if (resp.code != CoapCode.content) {
print('Request failed!');
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/coap_media_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ class CoapMediaType {
return null;
}
final res = <int>[];
var regex1 = regex.trim().substring(0, regex.indexOf('*')).trim();
regex1 += '.*';
final regex1 = regex.substring(0, regex.indexOf('*')).trim() + '.*';
final r = RegExp(regex1);
_registry.forEach((int key, List<String> value) {
final mime = value[0];
Expand Down
4 changes: 2 additions & 2 deletions lib/src/coap_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ class CoapMessage {

/// URI path
String get uriPath {
var join = CoapOption.join(
final join = CoapOption.join(
getOptions(optionTypeUriPath) as List<CoapOption>?, '/')!;
return join += '/';
return join + '/';
}

/// Sets a number of Uri path options from a string, ignores any trailing / character
Expand Down
24 changes: 9 additions & 15 deletions lib/src/coap_option.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ class CoapOption {
@override
int get hashCode {
const prime = 31;
var result = 1;
return result = prime * result + _type;
return prime + _type;
}

@override
Expand Down Expand Up @@ -268,22 +267,17 @@ class CoapOption {

/// Joins the string values of a set of options.
static String? join(List<CoapOption>? options, String delimiter) {
String? s;
if (null == options) {
return s;
} else {
final sb = StringBuffer();
var append = false;
for (final opt in options) {
if (append) {
sb.write(delimiter);
} else {
append = true;
}
sb.write(opt.stringValue);
return null;
}
final sb = StringBuffer();
for (final opt in options) {
if (opt != options.first) {
sb.write(delimiter);
}
return sb.toString();
sb.write(opt.stringValue);
}
return sb.toString();
}

/// Returns a string representation of the option type.
Expand Down
17 changes: 6 additions & 11 deletions lib/src/endpoint/resources/coap_endpoint_resource.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,14 @@ abstract class CoapEndpointResource {

/// Gets the URI of this resource.
String get path {
var sb = StringBuffer();
sb.write(name);
if (_parent == null) {
sb.write('/');
} else {
var res = _parent;
while (res != null) {
final tmp = StringBuffer('${res.name}/${sb.toString()}');
sb = tmp;
res = res._parent;
}
return '/$name';
}
var names = [name];
for (var res = _parent; res != null; res = res._parent) {
names.add(res.name);
}
return sb.toString();
return names.reversed.join('/');
}

/// Attributes
Expand Down
2 changes: 1 addition & 1 deletion lib/src/net/coap_matcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ class CoapMatcher implements CoapIMatcher {
void _removeNotificatoinsOf(CoapObserveRelation relation) {
for (final previous in relation.clearNotifications()) {
// Notifications are local MID namespace
var keyId = CoapKeyId(previous!.id);
final keyId = CoapKeyId(previous!.id);
_exchangesById.remove(keyId);
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/coap_base_class_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void main() {
test('Negotiation Content', () {
const defaultContentType = 10;
final supported = <int>[11, 5];
var accepted = <CoapOption>[];
final accepted = <CoapOption>[];
final opt1 = CoapOption.createVal(optionTypeMaxAge, 10);
final opt2 = CoapOption.createVal(optionTypeContentFormat, 5);
accepted.add(opt1);
Expand Down

0 comments on commit beeed5c

Please sign in to comment.