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.parameters;
 
 import  org.apache.hadoop.mapred.JobConf;
 import  org.apache.hadoop.mapred.JobConfigurable;
 
Meta information and accessors for configuring a job.
 
 public interface Parametered extends JobConfigurable {
 
   Logger log = LoggerFactory.getLogger(Parametered.class);
 
EXPERT: consumers should never have to call this method. It would be friendly visible to ParameteredGeneralizations if java supported it. Calling this method should create a new list of parameters and is called

Parameters:
prefix ends with a dot if not empty.
jobConf configuration used for retreiving values
See also:
ParameteredGeneralizations.configureParameters(String,Parametered,org.apache.hadoop.mapred.JobConf) invoking method
ParameteredGeneralizations.configureParametersRecusivly(Parametered,String,org.apache.hadoop.mapred.JobConf) invoking method
 
   void createParameters(String prefix, JobConf jobConf);


  
"multiple inheritance"
 
     private ParameteredGeneralizations() {
     }


    

Parameters:
parametered instance to be configured
jobConf configuration used for retreiving values
See also:
configureParameters(Parametered,org.apache.hadoop.mapred.JobConf) Uses parametered simple class name as prefix.
 
     public static void configureParameters(Parametered parametered, JobConf jobConf) {
       configureParameters(parametered.getClass().getSimpleName() + '.'parameteredjobConf);
 
     }

    
Calls org.apache.mahout.common.parameters.Parametered.createParameters(String,org.apache.hadoop.mapred.JobConf) on parameter parmetered, and then recurse down its composite tree to invoke org.apache.mahout.common.parameters.Parametered.createParameters(String,org.apache.hadoop.mapred.JobConf) and org.apache.hadoop.mapred.JobConfigurable.configure(org.apache.hadoop.mapred.JobConf) on each composite part.

Parameters:
prefix ends with a dot if not empty.
parametered instance to be configured
jobConf configuration used for retreiving values
 
     public static void configureParameters(String prefixParametered parametered, JobConf jobConf) {
       parametered.createParameters(prefixjobConf);
       configureParametersRecusivly(parameteredprefixjobConf);
     }
 
     private static void configureParametersRecusivly(Parametered parameteredString prefix, JobConf jobConf) {
       for (Parameter<?> parameter : parametered.getParameters()) {
         if (.isDebugEnabled()) {
           .debug("Configuring " + prefix + parameter.name());
         }
         String name = prefix + parameter.name() + '.';
         parameter.createParameters(namejobConf);
         parameter.configure(jobConf);
         if (!parameter.getParameters().isEmpty()) {
           configureParametersRecusivly(parameternamejobConf);
         }
       }
     }
 
     public static String help(Parametered parametered) {
       return new Help(parametered).toString();
     }
 
    public static String conf(Parametered parametered) {
      return new Conf(parametered).toString();
    }
    private static class Help {
      private final StringBuilder sb;
      @Override
      public String toString() {
        return .toString();
      }
      private int longestName = 0;
      private int numChars = 100; // a few extra just to be sure
      static final int distanceBetweenNameAndDescription = 8;
      // todo: hmmm in the end this is 5 letters less that it says.. not sure why
      private void recurseCount(Parametered parametered) {
        for (Parameter<?> parameter : parametered.getParameters()) {
          int parameterNameLength = parameter.name().length();
          if (parameterNameLength > ) {
             = parameterNameLength;
          }
          recurseCount(parameter);
           += parameter.description().length();
        }
      }
      private Help(Parametered parametered) {
        recurseCount(parametered);
         += ( + ) * parametered.getParameters().size();
         = new StringBuilder();
        recurseWrite(parametered);
      }
      private void recurseWrite(Parametered parametered) {
        for (Parameter<?> parameter : parametered.getParameters()) {
          .append(parameter.prefix());
          .append(parameter.name());
          int max =  - parameter.name().length() - parameter.prefix().length() + ;
          for (int i = 0; i < maxi++) {
            .append(' ');
          }
          .append(parameter.description());
          if (parameter.defaultValue() != null) {
            .append(" (default value '");
            .append(parameter.defaultValue());
            .append("')");
          }
          .append('\n');
          recurseWrite(parameter);
        }
      }
    }
    private static class Conf {
      private final StringBuilder sb;
      @Override
      public String toString() {
        return .toString();
      }
      private int longestName = 0;
      private int numChars = 100; // a few extra just to be sure
      //int distanceBetweenNameAndDescription = 4;
      private void recurseCount(Parametered parametered) {
        for (Parameter<?> parameter : parametered.getParameters()) {
          int parameterNameLength = parameter.prefix().length() + parameter.name().length();
          if (parameterNameLength > ) {
             = parameterNameLength;
          }
           += parameterNameLength;
           += 5; // # $0\n$1 = $2\n\n
           += parameter.description().length();
          if (parameter.getStringValue() != null) {
             += parameter.getStringValue().length();
          }
          recurseCount(parameter);
        }
      }
      private Conf(Parametered parametered) {
        recurseCount(parametered);
         = new StringBuilder();
        recurseWrite(parametered);
      }
      private void recurseWrite(Parametered parametered) {
        for (Parameter<?> parameter : parametered.getParameters()) {
          .append("# ");
          .append(parameter.description());
          .append('\n');
          .append(parameter.prefix());
          .append(parameter.name());
          .append(" = ");
          if (parameter.getStringValue() != null) {
            .append(parameter.getStringValue());
          }
          .append('\n');
          .append('\n');
          recurseWrite(parameter);
        }
      }
    }
  }
New to GrepCode? Check out our FAQ X