Home | History | Annotate | Download | only in config
      1 /*
      2  * Copyright (C) 2012 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.caliper.config;
     18 
     19 import static com.google.common.base.Preconditions.checkNotNull;
     20 
     21 import com.google.common.base.MoreObjects;
     22 import com.google.common.base.Objects;
     23 import com.google.common.collect.ImmutableMap;
     24 
     25 import java.util.Map;
     26 
     27 /**
     28  * This is the configuration passed to the {@link com.google.caliper.api.ResultProcessor} by the
     29  * user.
     30  *
     31  * @author gak (at) google.com (Gregory Kick)
     32  */
     33 public class ResultProcessorConfig {
     34   private final String className;
     35   private final ImmutableMap<String, String> options;
     36 
     37   private ResultProcessorConfig(Builder builder) {
     38     this.className = builder.className;
     39     this.options = builder.optionsBuilder.build();
     40   }
     41 
     42   public String className() {
     43     return className;
     44   }
     45 
     46   public ImmutableMap<String, String> options() {
     47     return options;
     48   }
     49 
     50 
     51   @Override public boolean equals(Object obj) {
     52     if (obj == this) {
     53       return true;
     54     } else if (obj instanceof ResultProcessorConfig) {
     55       ResultProcessorConfig that = (ResultProcessorConfig) obj;
     56       return this.className.equals(that.className)
     57           && this.options.equals(that.options);
     58     } else {
     59       return false;
     60     }
     61   }
     62 
     63   @Override public int hashCode() {
     64     return Objects.hashCode(className, options);
     65   }
     66 
     67   @Override public String toString() {
     68     return MoreObjects.toStringHelper(this)
     69         .add("className", className)
     70         .add("options", options)
     71         .toString();
     72   }
     73 
     74   static final class Builder {
     75     private String className;
     76     private ImmutableMap.Builder<String, String> optionsBuilder = ImmutableMap.builder();
     77 
     78     public Builder className(String className) {
     79       this.className = checkNotNull(className);
     80       return this;
     81     }
     82 
     83     public Builder addOption(String option, String value) {
     84       this.optionsBuilder.put(option, value);
     85       return this;
     86     }
     87 
     88     public Builder addAllOptions(Map<String, String> options) {
     89       this.optionsBuilder.putAll(options);
     90       return this;
     91     }
     92 
     93     public ResultProcessorConfig build() {
     94       return new ResultProcessorConfig(this);
     95     }
     96   }
     97 }
     98