cz.muni.fi.pa165.creatures.rest.client.utils.OptionsProvider.java Source code

Java tutorial

Introduction

Here is the source code for cz.muni.fi.pa165.creatures.rest.client.utils.OptionsProvider.java

Source

/*
 * Copyright 2012 Faculty of Informatics - Masaryk University.
 *
 * 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 cz.muni.fi.pa165.creatures.rest.client.utils;

import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;

/**
 * This class represent a way how we obtain built
 * {@link org.apache.commons.cli.Options}.
 *
 * @author smikloso
 */
public class OptionsProvider {

    private static Options options;

    private OptionsProvider() {
    }

    private static class OptionsProviderHolder {

        public static final OptionsProvider INSTANCE = new OptionsProvider();
    }

    public static OptionsProvider getInstance() {
        return OptionsProviderHolder.INSTANCE;
    }

    public Options getOptions() {
        if (options != null) {
            return OptionsProvider.options;
        }

        OptionsProvider.options = new Options();

        Option help = new Option("h", "prints this help");

        Option uri = OptionBuilder.withArgName("uri").hasArg().withDescription("uri of the resource we query")
                .create("u");

        Option operation = OptionBuilder.withArgName("operation").hasArg()
                .withDescription("operation, C, R, U, D, A or N").create("o");

        Option idOfEntity = OptionBuilder.withArgName("id").hasArg().withDescription("id of an entity to deal with")
                .create("i");

        Option name = OptionBuilder.withArgName("name").hasArg()
                .withDescription("name of an entity of a choosen mode").create("n");

        // WEAPON
        Option weapon = OptionBuilder.withDescription("weapon mode").create("w");

        Option ammunition = OptionBuilder.withArgName("ammunition").hasArg()
                .withDescription("ammunition of a weapon in bullets").create("m");

        Option range = OptionBuilder.withArgName("range").hasArg().withDescription("range of a weapon in meters")
                .create("g");

        // REGION
        Option region = OptionBuilder.withDescription("region mode").create("r");

        Option description = OptionBuilder.withArgName("description").hasArg()
                .withDescription("description of a region").create("d");

        Option area = OptionBuilder.withArgName("area").hasArg()
                .withDescription("area of region in square kilometers").create("a");

        options.addOption(help);
        options.addOption(uri);
        options.addOption(weapon);
        options.addOption(region);
        options.addOption(operation);
        options.addOption(idOfEntity);
        options.addOption(name);
        options.addOption(ammunition);
        options.addOption(range);
        options.addOption(description);
        options.addOption(area);

        return OptionsProvider.options;

    }
}