Skip to content

these are the more complicated code improvements#233

Open
Elyahu41 wants to merge 3 commits into
KosherJava:masterfrom
Elyahu41:complicated-code-improvements
Open

these are the more complicated code improvements#233
Elyahu41 wants to merge 3 commits into
KosherJava:masterfrom
Elyahu41:complicated-code-improvements

Conversation

@Elyahu41
Copy link
Copy Markdown
Contributor

No description provided.

return Long.valueOf(firstTime).compareTo(Long.valueOf(secondTime));
}
};
public static final Comparator<Zman> DATE_ORDER = (zman1, zman2) -> {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Elyahu41 , how about this using Lambda?
public static final Comparator DATE_ORDER = Comparator.comparingLong(
zman -> zman == null || zman.getZman() == null ? Long.MAX_VALUE : zman.getZman().getTime()
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just double checked this code with IntelliJ. If you want to code the method that way, I recommend this:

public static final Comparator<Zman> DATE_ORDER = Comparator.comparingLong(zman ->
			zman == null || zman.getZman() == null ? Long.MAX_VALUE : zman.getZman().toEpochMilli()
	);

return firstLabel.compareTo(secondLabel);
}
};
public static final Comparator<Zman> NAME_ORDER = (zman1, zman2) -> {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this?

public static final Comparator NAME_ORDER = Comparator.comparing(
zman -> zman == null || zman.getLabel() == null ? "" : zman.getLabel()
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. I think you're just missing the typing tag for no warnings to show:

public static final Comparator<Zman> NAME_ORDER = Comparator.comparing(zman ->
			zman == null || zman.getLabel() == null ? "" : zman.getLabel()
	);

return firstDuration == secondDuration ? 0 : firstDuration > secondDuration ? 1 : -1;
}
};
public static final Comparator<Zman> DURATION_ORDER = (zman1, zman2) -> {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this

public static final Comparator DURATION_ORDER = Comparator.comparingLong(
zman -> zman == null ? Long.MAX_VALUE : zman.getDuration()
);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here @KosherJava :

public static final Comparator<Zman> DURATION_ORDER = Comparator.comparingLong(
			zman -> zman == null ? Long.MAX_VALUE : zman.getDuration()
	);

@KosherJava
Copy link
Copy Markdown
Owner

@Elyahu41 , I will leave it up to you.

@Elyahu41
Copy link
Copy Markdown
Contributor Author

Ok, then let's go with the methods you proposed just with the type included.

Should I fix the conflicts with this branch so that you can merge it?

@KosherJava
Copy link
Copy Markdown
Owner

@Elyahu41 , yes please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants