0

I have the following CharSequence defined:

final CharSequence[] videoQualities = {"any", "medium", "high", "hd"};

I am getting two string values: availableQuality and requestedQuality. Both can contain values from the CharSequence above only.

How can I check if availableQuality more or equal to requestedQuality?

LA_
  • 19,823
  • 58
  • 172
  • 308

2 Answers2

2

Try using an ArrayList instead of CharSequence[]. You can then use ArrayList.indexOf() to return a numeric index that you can use to compare position in the ArrayList.

Squonk
  • 48,735
  • 19
  • 103
  • 135
1

Enum to rescue.

define videoQualities as enum

public enum VideoQualities { any, medium, high, hd }

VideoQualities availableQuality; VideoQualities requestedQuality;

if (availableQuality.ordinal() >= requestedQuality.ordinal()) { .... }

Yonatan Maman
  • 2,428
  • 1
  • 24
  • 34
  • I thought this originally but the OP's values are strings not integers. – Squonk Apr 25 '11 at 20:15
  • what do you mean by OP ? you can always convert String into enum using valueOf method: VideoQualities hd = VideoQualities.valueOf("hd") – Yonatan Maman Apr 25 '11 at 20:54
  • OP = 'Original post' or 'original poster' (the question or person who asked the question). By the way, I didn't think of using enum that way, thanks for teaching me something (+1). – Squonk Apr 25 '11 at 22:47