Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You 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.apache.mahout.common;
import  org.apache.hadoop.conf.Configuration;
import  org.apache.hadoop.io.DefaultStringifier;
import  org.apache.hadoop.util.GenericsUtil;
public class Parameters {
  private static final Logger log = LoggerFactory.getLogger(Parameters.class);
  private Map<StringStringparams = new HashMap<StringString>();
  //private Configuration conf = new Configuration();
  public Parameters() {
  }
  private Parameters(Map<StringStringparams) {
    this. = params;
  }
  public String get(String key) {
    return .get(key);
  }
  public String get(String keyString defaultValue) {
    String ret = .get(key);
    return ret == null ? defaultValue : ret;
  }
  public void set(String keyString value) {
    .put(keyvalue);
  }
  public String toString() {
    Configuration conf = new Configuration();
    conf.set("io.serializations",
        "org.apache.hadoop.io.serializer.JavaSerialization,org.apache.hadoop.io.serializer.WritableSerialization");
    DefaultStringifier<Map<StringString>> mapStringifier = new DefaultStringifier<Map<StringString>>(conf,
        GenericsUtil.getClass());
    try {
      return mapStringifier.toString();
    } catch (IOException e) {
      .info("Encountered IOException while deserializing returning empty string"e);
      return "";
    }
  }
  public String print() {
    return .toString();
  }
  public static Parameters fromString(String serializedStringthrows IOException {
    Configuration conf = new Configuration();
    conf.set("io.serializations",
        "org.apache.hadoop.io.serializer.JavaSerialization,org.apache.hadoop.io.serializer.WritableSerialization");
    Map<StringStringparams = new HashMap<StringString>();
    DefaultStringifier<Map<StringString>> mapStringifier = new DefaultStringifier<Map<StringString>>(conf,
        GenericsUtil.getClass(params));
    params = mapStringifier.fromString(serializedString);
    return new Parameters(params);
  }
New to GrepCode? Check out our FAQ X