Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   *
   * Copyright 2012 Red Hat, Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package org.jboss.classfilewriter.code;
 
 import java.util.List;
builder class used to build a lookupswitch statement.

Author(s):
Stuart Douglas
 
 public class LookupSwitchBuilder {
 
     private final CodeLocation defaultLocation;
     private final AtomicReference<BranchEnddefaultBranchEnd;
     private final List<ValuePairvalues = new ArrayList<ValuePair>();

    
Builds a lookup switch statement with no specified default location. When the lookup switch is added to the code attribute a BranchEnd will be returned that can be used to set the location.
 
     public LookupSwitchBuilder() {
          = new AtomicReference<BranchEnd>();
          = null;
     }

    
Builds a lookup switch statement, specifying the default location

Parameters:
defaultLocation The default location
 
     public LookupSwitchBuilder(final CodeLocation defaultLocation) {
         this. = defaultLocation;
          = null;
     }

    
Adds a value to the table that is at a location yet to be written. After this lookup switch has been written then the BranchEnd can be retrieved from the returned reference.

Parameters:
value The value to add to the lookup table
Returns:
A reference to the BranchEnd that will be created.
 
     public AtomicReference<BranchEndadd(int value) {
         final AtomicReference<BranchEndend = new AtomicReference<BranchEnd>();
         ValuePair vp = new ValuePair(valueend);
         .add(vp);
         return end;
     }
    
Adds a value to the table

Parameters:
value The value to add to the lookup table
 
     public LookupSwitchBuilder add(int valuefinal CodeLocation location) {
         .add(new ValuePair(valuelocation));
         return this;
     }
 
     public CodeLocation getDefaultLocation() {
         return ;
     }
 
         return ;
     }
 
     public List<ValuePairgetValues() {
         return Collections.unmodifiableList();
     }
 
     public static class ValuePair implements Comparable<ValuePair> {
         private final int value;
         private final CodeLocation location;
         private final AtomicReference<BranchEndbranchEnd;
 
        public ValuePair(final int valuefinal AtomicReference<BranchEndbranchEnd) {
            this. = value;
            this. = null;
            this. = branchEnd;
        }
        public ValuePair(final int valuefinal CodeLocation location) {
            this. = value;
            this. = location;
            this. = null;
        }
        @Override
        public int compareTo(final ValuePair o) {
            return Integer.valueOf().compareTo(Integer.valueOf(o.value));
        }
        public int getValue() {
            return ;
        }
        public CodeLocation getLocation() {
            return ;
        }
        public AtomicReference<BranchEndgetBranchEnd() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X