Skip to content
Snippets Groups Projects

titanbitstring methods implemented

Merged Eclipse Webmaster requested to merge github/fork/GergoUjhelyi/master into master
1 file
+ 108
5
Compare changes
  • Side-by-side
  • Inline
@@ -250,10 +250,113 @@ public class TitanBitString_template extends Base_Template {
}
}
//TODO: implement BITSTRING_template::valueof
//TODO: implement BITSTRING_template::lengthof
//TODO: implement BITSTRING_template::list_item
//TODO: implement BITSTRING_template::ispresent
//TODO: implement BITSTRING_template::match_omit
//originally valueof
public TitanBitString valueOf(){
if(templateSelection != template_sel.SPECIFIC_VALUE || is_ifPresent){
throw new TtcnError("Performing a valueof or send operation on a non-specific bitstring template.");
}
return single_value;
}
//originally lengthof
public int lengthOf(){
if(is_ifPresent){
throw new TtcnError("Performing lengthof() operation on a bitstring template which has an ifpresent attribute.");
}
int min_length = 0;
boolean has_any_or_none = false;
switch (templateSelection) {
case SPECIFIC_VALUE:
min_length = single_value.lengthOf();
has_any_or_none = false;
break;
case OMIT_VALUE:
throw new TtcnError("Performing lengthof() operation on a bitstring template containing omit value.");
case ANY_VALUE:
case ANY_OR_OMIT:
min_length = 0;
has_any_or_none = true;
break;
case VALUE_LIST:
// error if any element does not have length or the lengths differ
if(value_list.isEmpty()){
throw new TtcnError("Internal error: Performing lengthof() operation on a bitstring template containing an empty list.");
}
int item_length = value_list.get(0).lengthOf();
for (int i = 1; i < value_list.size(); i++) {
if(value_list.get(i).lengthOf() != item_length){
throw new TtcnError("Performing lengthof() operation on a bitstring template containing a value list with different lengths.");
}
}
min_length = item_length;
has_any_or_none = false;
break;
case COMPLEMENTED_LIST:
throw new TtcnError("Performing lengthof() operation on a bitstring template containing complemented list.");
case STRING_PATTERN:
min_length = 0;
has_any_or_none = false;
for (int i = 0; i < pattern_value.size(); i++) {
if(pattern_value.get(i) < 3){ // case of 1, 0, ?
min_length++;
} else {
has_any_or_none = true;
}
}
break;
default:
throw new TtcnError("Performing lengthof() operation on an uninitialized/unsupported bitstring template.");
}
return min_length;
}
public TitanBitString_template listItem(final int listIndex){
if(templateSelection != template_sel.VALUE_LIST && templateSelection != template_sel.COMPLEMENTED_LIST){
throw new TtcnError("Accessing a list element of a non-list bitstring template.");
}
if(listIndex >= value_list.size()){
throw new TtcnError("Index overflow in a bitstring value list template.");
}
return value_list.get(listIndex);
}
//originally is_present
public boolean isPresent(boolean legacy){
if(templateSelection == template_sel.UNINITIALIZED_TEMPLATE){
return false;
}
return !match_omit(legacy);
}
public boolean match_omit(){
return match_omit(false);
}
public boolean match_omit(boolean legacy){
if(is_ifPresent){
return true;
}
switch (templateSelection) {
case OMIT_VALUE:
case ANY_OR_OMIT:
return true;
case VALUE_LIST:
case COMPLEMENTED_LIST:
if(legacy){
// legacy behavior: 'omit' can appear in the value/complement list
for (int i = 0; i < value_list.size(); i++) {
if(value_list.get(i).match_omit()){
return templateSelection == template_sel.VALUE_LIST;
}
}
return templateSelection == template_sel.COMPLEMENTED_LIST;
}
// else fall through
}
return false;
}
}
Loading