Example usage for java.util Scanner next

List of usage examples for java.util Scanner next

Introduction

In this page you can find the example usage for java.util Scanner next.

Prototype

public String next() 

Source Link

Document

Finds and returns the next complete token from this scanner.

Usage

From source file:org.apache.tajo.engine.planner.physical.TestPhysicalPlanner.java

@Test
public final void testPartitionedStorePlan() throws IOException, PlanningException {
    FileFragment[] frags = FileStorageManager.splitNG(conf, "default.score", score.getMeta(),
            new Path(score.getPath()), Integer.MAX_VALUE);
    TaskAttemptId id = LocalTajoTestingUtility.newTaskAttemptId(masterPlan);
    TaskAttemptContext ctx = new TaskAttemptContext(new QueryContext(conf), id, new FileFragment[] { frags[0] },
            CommonTestingUtil.getTestDir("target/test-data/testPartitionedStorePlan"));
    ctx.setEnforcer(new Enforcer());
    Expr context = analyzer.parse(QUERIES[7]);
    LogicalPlan plan = planner.createPlan(defaultContext, context);

    int numPartitions = 3;
    Column key1 = new Column("default.score.deptname", Type.TEXT);
    Column key2 = new Column("default.score.class", Type.TEXT);
    DataChannel dataChannel = new DataChannel(masterPlan.newExecutionBlockId(),
            masterPlan.newExecutionBlockId(), ShuffleType.HASH_SHUFFLE, numPartitions);
    dataChannel.setShuffleKeys(new Column[] { key1, key2 });
    ctx.setDataChannel(dataChannel);/*from   ww  w .  j av  a  2  s.c  om*/
    LogicalNode rootNode = optimizer.optimize(plan);

    TableMeta outputMeta = CatalogUtil.newTableMeta(dataChannel.getStoreType());

    FileSystem fs = sm.getFileSystem();
    QueryId queryId = id.getTaskId().getExecutionBlockId().getQueryId();
    ExecutionBlockId ebId = id.getTaskId().getExecutionBlockId();

    PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf);
    PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode);
    exec.init();
    exec.next();
    exec.close();
    ctx.getHashShuffleAppenderManager().close(ebId);

    String executionBlockBaseDir = queryId.toString() + "/output" + "/" + ebId.getId() + "/hash-shuffle";
    Path queryLocalTmpDir = new Path(conf.getVar(ConfVars.WORKER_TEMPORAL_DIR) + "/" + executionBlockBaseDir);
    FileStatus[] list = fs.listStatus(queryLocalTmpDir);

    List<Fragment> fragments = new ArrayList<Fragment>();
    for (FileStatus status : list) {
        assertTrue(status.isDirectory());
        FileStatus[] files = fs.listStatus(status.getPath());
        for (FileStatus eachFile : files) {
            fragments.add(new FileFragment("partition", eachFile.getPath(), 0, eachFile.getLen()));
        }
    }

    assertEquals(numPartitions, fragments.size());
    Scanner scanner = new MergeScanner(conf, rootNode.getOutSchema(), outputMeta, TUtil.newList(fragments));
    scanner.init();

    Tuple tuple;
    int i = 0;
    while ((tuple = scanner.next()) != null) {
        assertEquals(6, tuple.get(2).asInt4()); // sum
        assertEquals(3, tuple.get(3).asInt4()); // max
        assertEquals(1, tuple.get(4).asInt4()); // min
        i++;
    }
    assertEquals(10, i);
    scanner.close();

    // Examine the statistics information
    assertEquals(10, ctx.getResultStats().getNumRows().longValue());

    fs.delete(queryLocalTmpDir, true);
}

From source file:codeu.chat.client.commandline.Chat.java

private void doOneCommand(Scanner lineScanner) {

    final Scanner tokenScanner = new Scanner(lineScanner.nextLine());
    if (!tokenScanner.hasNext()) {
        return;//  w w  w. j a v  a 2  s  .c o m
    }
    final String token = tokenScanner.next();

    if (token.equals("exit")) {

        alive = false;

    } else if (token.equals("help")) {

        help();

    } else if (token.equals("sign-in")) {

        if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: No user name supplied.");
        } else {
            signInUser(tokenScanner.nextLine().trim());

            // Check whether the bot/convo already exist
            if (clientContext.user.lookup(BOT_NAME) == null) {
                addUser(BOT_NAME);
                clientContext.conversation.startConversation(BOT_CONVO, clientContext.user.getCurrent().id);
            }
        }

    } else if (token.equals("sign-out")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            signOutUser();
        }

    } else if (token.equals("current")) {

        showCurrent();

    } else if (token.equals("u-add")) {

        if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: Username not supplied.");
        } else {
            addUser(tokenScanner.nextLine().trim());
        }

    } else if (token.equals("u-list-all")) {

        showAllUsers();

    } else if (token.equals("c-add")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: Conversation title not supplied.");
            } else {
                final String title = tokenScanner.nextLine().trim();
                clientContext.conversation.startConversation(title, clientContext.user.getCurrent().id);
            }
        }

    } else if (token.equals("c-list-all")) {

        clientContext.conversation.showAllConversations();

    } else if (token.equals("c-select")) {

        selectConversation(lineScanner);

    } else if (token.equals("c-search-title")) {

        if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: Conversation title not supplied.");
        } else {
            final String title = tokenScanner.nextLine().trim();
            clientContext.conversation.searchTitle(title);
        }

    } else if (token.equals("m-add")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: Message body not supplied.");
            } else {
                final String body = tokenScanner.nextLine().trim();
                clientContext.message.addMessage(clientContext.user.getCurrent().id,
                        clientContext.conversation.getCurrentId(), body);

                respondAsBot(body, true);
            }
        }

    } else if (token.equals("m-list-all")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            clientContext.message.showAllMessages();
        }

    } else if (token.equals("m-next")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else if (!tokenScanner.hasNextInt()) {
            System.out.println("Command requires an integer message index.");
        } else {
            clientContext.message.selectMessage(tokenScanner.nextInt());
        }

    } else if (token.equals("m-show")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else {
            final int count = (tokenScanner.hasNextInt()) ? tokenScanner.nextInt() : 1;
            clientContext.message.showMessages(count);
        }

    } else if (token.equals("m-search-string")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: String not supplied.");
        } else {
            final String keyword = tokenScanner.nextLine().trim();
            clientContext.message.searchString(keyword);
        }

    } else if (token.equals("m-search-author")) {

        if (!clientContext.conversation.hasCurrent()) {
            System.out.println("ERROR: No conversation selected.");
        } else if (!tokenScanner.hasNext()) {
            System.out.println("ERROR: author body not supplied.");
        } else {
            final String author = tokenScanner.nextLine().trim();
            clientContext.message.searchAuthor(author);
        }

    } else if (token.equals("t-add")) {

        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: tag name not supplied.");
            } else {
                final String name = tokenScanner.nextLine().trim();
                clientContext.tag.addTag(clientContext.user.getCurrent().id, name);
            }
        }

    } else if (token.equals("t-list")) {
        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            if (!tokenScanner.hasNext()) {
                System.out.println("ERROR: tag name not supplied.");
            } else {
                final String name = tokenScanner.nextLine().trim();
                clientContext.tag.listTag(clientContext.user.getCurrent().id, name);
            }
        }

    } else if (token.equals("t-list-all")) {
        showAllTags();

    } else if (token.equals("t-list-user")) {
        if (!clientContext.user.hasCurrent()) {
            System.out.println("ERROR: Not signed in.");
        } else {
            clientContext.tag.showUserTags(clientContext.user.getCurrent().id);
        }
    } else {
        System.out.format("Command not recognized: %s\n", token);
        System.out.format("Command line rejected: %s%s\n", token,
                (tokenScanner.hasNext()) ? tokenScanner.nextLine() : "");
        System.out.println("Type \"help\" for help.");
    }
    tokenScanner.close();
}

From source file:com.joey.software.MoorFLSI.RepeatImageTextReader.java

public void loadTextData(File file) {
    try {//from  w  w  w  .  j av  a  2s  .com
        RandomAccessFile in = new RandomAccessFile(file, "r");

        // Skip header
        in.readLine();
        in.readLine();
        in.readLine();

        // Skip Subject Information
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        String startTimeInput = in.readLine();
        String commentsInput = in.readLine();

        String data = in.readLine();
        while (!data.startsWith("2) System Configuration")) {
            commentsInput += data;
            data = in.readLine();
        }
        // System configuration

        // in.readLine();
        in.readLine();
        String timeCounstantInput = in.readLine();
        String cameraGainInput = in.readLine();
        String exposureTimeInput = in.readLine();
        in.readLine();
        in.readLine();
        in.readLine();
        String resolutionInput = in.readLine();

        // Time Data
        in.readLine();
        String timeDataInput = in.readLine();
        String totalImagesInput = in.readLine();
        in.readLine();
        in.readLine();
        // in.readLine();
        // System.out.println(in.readLine());
        // in.readLine();

        // Parse important Size

        high = (new Scanner(resolutionInput.split(":")[1])).nextInt();
        wide = (new Scanner(resolutionInput.split(",")[1])).nextInt();
        int tot = 1;
        try {
            tot = (new Scanner(totalImagesInput.split(":")[1])).nextInt();
        } catch (Exception e) {

        }
        System.out.println(wide + "," + high);
        // Parse timeInformation
        SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss (dd/MM/yy)");
        Date startTime = null;
        try {
            startTime = format.parse(startTimeInput.split(": ")[1]);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        String[] frameTimeData = timeDataInput.split("information:")[1].split(",");

        Date[] timeInfo = new Date[tot];
        for (int i = 0; i < frameTimeData.length - 1; i++) {
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(startTime);
            String dat = (frameTimeData[i]);
            String[] timeVals = dat.split(":");

            int hour = Integer.parseInt(StringOperations.removeNonNumber(timeVals[0]));
            int min = Integer.parseInt(StringOperations.removeNonNumber(timeVals[1]));
            int sec = Integer.parseInt(StringOperations.removeNonNumber(timeVals[2]));
            int msec = Integer.parseInt(StringOperations.removeNonNumber(timeVals[3]));

            cal.add(Calendar.HOUR_OF_DAY, hour);
            cal.add(Calendar.MINUTE, min);
            cal.add(Calendar.SECOND, sec);
            cal.add(Calendar.MILLISECOND, msec);
            timeInfo[i] = cal.getTime();
        }

        // Parse Image Data
        /*
         * Close Random access file and switch to scanner first store pos
         * then move to correct point.
         */
        long pos = in.getFilePointer();
        in.close();

        FileInputStream fIn = new FileInputStream(file);
        fIn.skip(pos);

        BufferedInputStream bIn = new BufferedInputStream(fIn);
        Scanner sIn = new Scanner(bIn);

        short[][][] holder = new short[tot][wide][high];

        JFrame f = new JFrame();
        f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        StatusBarPanel stat = new StatusBarPanel();
        stat.setMaximum(high);
        f.getContentPane().setLayout(new BorderLayout());
        f.getContentPane().add(stat, BorderLayout.CENTER);
        f.setSize(200, 60);
        f.setVisible(true);

        for (int i = 0; i < tot; i++) {
            // Skip over the heading values
            stat.setStatusMessage("Loading " + i + " of " + tot);
            sIn.useDelimiter("\n");
            sIn.next();
            sIn.next();
            sIn.next();
            if (i != 0) {
                sIn.next();
            }
            sIn.reset();
            for (int y = 0; y < high; y++) {
                stat.setValue(y);
                sIn.nextInt();
                for (int x = 0; x < wide; x++) {
                    holder[i][x][y] = sIn.nextShort();
                }

            }
            addData(timeInfo[i], holder[i]);
        }

        // FrameFactroy.getFrame(new DynamicRangeImage(data[0]));
        // Start Image Data

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:org.apache.tajo.engine.planner.physical.TestPhysicalPlanner.java

@Test
public final void testStorePlan() throws IOException, PlanningException {
    FileFragment[] frags = FileStorageManager.splitNG(conf, "default.score", score.getMeta(),
            new Path(score.getPath()), Integer.MAX_VALUE);
    Path workDir = CommonTestingUtil.getTestDir("target/test-data/testStorePlan");
    TaskAttemptContext ctx = new TaskAttemptContext(new QueryContext(conf),
            LocalTajoTestingUtility.newTaskAttemptId(masterPlan), new FileFragment[] { frags[0] }, workDir);
    ctx.setEnforcer(new Enforcer());
    ctx.setOutputPath(new Path(workDir, "grouped1"));

    Expr context = analyzer.parse(CreateTableAsStmts[0]);
    LogicalPlan plan = planner.createPlan(defaultContext, context);
    LogicalNode rootNode = optimizer.optimize(plan);

    TableMeta outputMeta = CatalogUtil.newTableMeta(StoreType.CSV);

    PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf);
    PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode);
    exec.init();/*from  w  ww  .  j a va  2  s  .com*/
    exec.next();
    exec.close();

    Scanner scanner = ((FileStorageManager) StorageManager.getFileStorageManager(conf))
            .getFileScanner(outputMeta, rootNode.getOutSchema(), ctx.getOutputPath());
    scanner.init();
    Tuple tuple;
    int i = 0;
    while ((tuple = scanner.next()) != null) {
        assertEquals(6, tuple.get(2).asInt4()); // sum
        assertEquals(3, tuple.get(3).asInt4()); // max
        assertEquals(1, tuple.get(4).asInt4()); // min
        i++;
    }
    assertEquals(10, i);
    scanner.close();

    // Examine the statistics information
    assertEquals(10, ctx.getResultStats().getNumRows().longValue());
}

From source file:org.apache.tajo.engine.planner.physical.TestPhysicalPlanner.java

@Test
public final void testStorePlanWithRCFile() throws IOException, PlanningException {
    FileFragment[] frags = FileStorageManager.splitNG(conf, "default.score", score.getMeta(),
            new Path(score.getPath()), Integer.MAX_VALUE);
    Path workDir = CommonTestingUtil.getTestDir("target/test-data/testStorePlanWithRCFile");
    TaskAttemptContext ctx = new TaskAttemptContext(new QueryContext(conf),
            LocalTajoTestingUtility.newTaskAttemptId(masterPlan), new FileFragment[] { frags[0] }, workDir);
    ctx.setEnforcer(new Enforcer());
    ctx.setOutputPath(new Path(workDir, "grouped2"));

    Expr context = analyzer.parse(CreateTableAsStmts[1]);
    LogicalPlan plan = planner.createPlan(defaultContext, context);
    LogicalNode rootNode = optimizer.optimize(plan);

    TableMeta outputMeta = CatalogUtil.newTableMeta(StoreType.RCFILE);

    PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf);
    PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode);
    exec.init();//from   w  w  w. j  a va2 s  .co  m
    exec.next();
    exec.close();

    Scanner scanner = ((FileStorageManager) StorageManager.getFileStorageManager(conf))
            .getFileScanner(outputMeta, rootNode.getOutSchema(), ctx.getOutputPath());
    scanner.init();
    Tuple tuple;
    int i = 0;
    while ((tuple = scanner.next()) != null) {
        assertEquals(6, tuple.get(2).asInt4()); // sum
        assertEquals(3, tuple.get(3).asInt4()); // max
        assertEquals(1, tuple.get(4).asInt4()); // min
        i++;
    }
    assertEquals(10, i);
    scanner.close();

    // Examine the statistics information
    assertEquals(10, ctx.getResultStats().getNumRows().longValue());
}

From source file:org.apache.tajo.engine.planner.physical.TestPhysicalPlanner.java

@Test
public final void testStorePlanWithMaxOutputFileSize()
        throws IOException, PlanningException, CloneNotSupportedException {

    TableStats stats = largeScore.getStats();
    assertTrue("Checking meaningfulness of test", stats.getNumBytes() > StorageUnit.MB);

    FileFragment[] frags = FileStorageManager.splitNG(conf, "default.score_large", largeScore.getMeta(),
            new Path(largeScore.getPath()), Integer.MAX_VALUE);
    Path workDir = CommonTestingUtil.getTestDir("target/test-data/testStorePlanWithMaxOutputFileSize");

    QueryContext queryContext = new QueryContext(conf, session);
    queryContext.setInt(SessionVars.MAX_OUTPUT_FILE_SIZE, 1);

    TaskAttemptContext ctx = new TaskAttemptContext(queryContext,
            LocalTajoTestingUtility.newTaskAttemptId(masterPlan), new FileFragment[] { frags[0] }, workDir);
    ctx.setEnforcer(new Enforcer());
    ctx.setOutputPath(new Path(workDir, "maxOutput"));

    Expr context = analyzer.parse(CreateTableAsStmts[3]);

    LogicalPlan plan = planner.createPlan(queryContext, context);
    LogicalNode rootNode = optimizer.optimize(plan);

    // executing StoreTableExec
    PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf);
    PhysicalExec exec = phyPlanner.createPlan(ctx, rootNode);
    exec.init();//from  ww  w  .j  ava  2s.  c  o m
    exec.next();
    exec.close();

    // checking the number of punctuated files
    int expectedFileNum = (int) (stats.getNumBytes() / (float) StorageUnit.MB);
    FileSystem fs = ctx.getOutputPath().getFileSystem(conf);
    FileStatus[] statuses = fs.listStatus(ctx.getOutputPath().getParent());
    assertEquals(expectedFileNum, statuses.length);

    // checking the file contents
    long totalNum = 0;
    for (FileStatus status : fs.listStatus(ctx.getOutputPath().getParent())) {
        Scanner scanner = ((FileStorageManager) StorageManager.getFileStorageManager(conf)).getFileScanner(
                CatalogUtil.newTableMeta(StoreType.CSV), rootNode.getOutSchema(), status.getPath());

        scanner.init();
        while ((scanner.next()) != null) {
            totalNum++;
        }
        scanner.close();
    }
    assertTrue(totalNum == ctx.getResultStats().getNumRows());
}

From source file:org.fao.geonet.kernel.search.LuceneQueryBuilder.java

/**
 * Build a Lucene query for the {@link LuceneQueryInput}.
 *
 * A AND clause is used for each search criteria and a OR clause if the content of a criteria is "this or that".
 *
 * A Boolean OR between parameters is used if the parameter has the form A_OR_B with content "this", this will
 * produce a query for documents having "this" in field A, B or both.
 *
 * Some search criteria does not support multi-occurences like spatial, temporal criteria or range fields.
 * // w ww .  j  a va  2s. c om
 * @param luceneQueryInput user and system input
 * @return Lucene query
 */
public Query build(LuceneQueryInput luceneQueryInput) {
    if (Log.isDebugEnabled(Geonet.SEARCH_ENGINE))
        Log.debug(Geonet.SEARCH_ENGINE,
                "LuceneQueryBuilder: luceneQueryInput is: \n" + luceneQueryInput.toString());

    // Remember which range fields have been processed
    Set<String> processedRangeFields = new HashSet<String>();

    // top query to hold all sub-queries for each search parameter
    BooleanQuery query = new BooleanQuery();

    // Filter according to user session
    addPrivilegeQuery(luceneQueryInput, query);

    // similarity is passed to textfield-query-creating methods
    String similarity = luceneQueryInput.getSimilarity();

    Map<String, Set<String>> searchCriteria = luceneQueryInput.getSearchCriteria();

    //
    // search criteria fields may contain zero or more _OR_ in their name, in which case the search will be a
    // disjunction of searches for fieldnames separated by that.
    //
    // here such _OR_ fields are parsed, an OR searchCriteria map is created, and theyre removed from vanilla
    // searchCriteria map.
    //
    Map<String, Set<String>> searchCriteriaOR = new HashMap<String, Set<String>>();

    for (Iterator<Entry<String, Set<String>>> i = searchCriteria.entrySet().iterator(); i.hasNext();) {
        Entry<String, Set<String>> entry = i.next();
        String fieldName = entry.getKey();
        Set<String> fieldValues = entry.getValue();
        if (fieldName.contains(FIELD_OR_SEPARATOR)) {
            i.remove();
            if (fieldName.contains(LuceneIndexField.NORTH) || fieldName.contains(LuceneIndexField.SOUTH)
                    || fieldName.contains(LuceneIndexField.EAST) || fieldName.contains(LuceneIndexField.WEST)
                    || fieldName.contains(SearchParameter.RELATION)

                    || fieldName.contains("without") || fieldName.contains("phrase")

                    || fieldName.contains(SearchParameter.EXTTO) || fieldName.contains(SearchParameter.EXTFROM)

                    || fieldName.contains(SearchParameter.FEATURED)
                    || fieldName.contains(SearchParameter.TEMPLATE)

                    || UserQueryInput.RANGE_QUERY_FIELDS.contains(fieldName)

            ) {
                // not supported in field disjunction
                continue;
            }

            Scanner scanner = new Scanner(fieldName).useDelimiter(FIELD_OR_SEPARATOR);
            while (scanner.hasNext()) {
                String field = scanner.next();

                if (field.equals("or")) {
                    // handle as 'any', add ' or ' for space-separated values
                    for (String fieldValue : fieldValues) {
                        field = "any";
                        Scanner whitespaceScan = new Scanner(fieldValue).useDelimiter("\\w");
                        while (whitespaceScan.hasNext()) {
                            fieldValue += " or " + whitespaceScan.next();
                        }
                        fieldValue = fieldValue.substring(" or ".length());
                        Set<String> values = searchCriteriaOR.get(field);
                        if (values == null)
                            values = new HashSet<String>();
                        values.addAll(fieldValues);
                        searchCriteriaOR.put(field, values);
                    }
                } else {
                    Set<String> values = searchCriteriaOR.get(field);
                    if (values == null)
                        values = new HashSet<String>();
                    values.addAll(fieldValues);
                    searchCriteriaOR.put(field, values);
                }
            }
        }
    }
    query = buildORQuery(searchCriteriaOR, query, similarity);
    query = buildANDQuery(searchCriteria, query, similarity, processedRangeFields);
    if (StringUtils.isNotEmpty(_language)) {
        if (Log.isDebugEnabled(Geonet.LUCENE))
            Log.debug(Geonet.LUCENE, "adding locale query for language " + _language);
        return addLocaleTerm(query, _language, luceneQueryInput.isRequestedLanguageOnly());
    } else {
        if (Log.isDebugEnabled(Geonet.LUCENE))
            Log.debug(Geonet.LUCENE, "no language set, not adding locale query");
        return query;
    }
}

From source file:support.plus.reportit.rv.FragmentActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_fragment);

    Toolbar toolbar = (Toolbar) findViewById(R.id.fragment_toolbar);
    setSupportActionBar(toolbar);//from  www.  java 2 s.  co  m
    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_back);

    Intent intent = getIntent();

    createCustomAnimation();

    String intfilename = intent.getStringExtra("filename");
    final int weekID = getIntent().getIntExtra("weekID", 0);

    SharedPreferences prefLast = getSharedPreferences("lastSaved", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = prefLast.edit();
    editor.putString("intfilename", intfilename);
    editor.putInt("weekID", weekID);
    editor.commit();

    TextView filenameText = (TextView) findViewById(R.id.filename);
    final EditText filetag = (EditText) findViewById(R.id.filetag);
    TextView fileauthorboss = (TextView) findViewById(R.id.fileauthorboss);
    Button bStartDate = (Button) findViewById(R.id.bStartDate);
    final EditText filenumber = (EditText) findViewById(R.id.filenumber);
    Button bEndDate = (Button) findViewById(R.id.bEndDate);
    final TextView startDate = (TextView) findViewById(R.id.startDate);
    final TextView endDate = (TextView) findViewById(R.id.endDate);

    bStartDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final SharedPreferences pref = getApplicationContext().getSharedPreferences("buttonsPressed",
                    MODE_APPEND);
            SharedPreferences.Editor editor = pref.edit();
            editor.putBoolean("bstartpressed", true);
            editor.commit();
            DialogFragment newFragment = new DatePickerFragment();
            newFragment.show(getSupportFragmentManager(), "datePicker");
        }
    });

    bEndDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final SharedPreferences pref = getApplicationContext().getSharedPreferences("buttonsPressed",
                    MODE_PRIVATE);
            SharedPreferences.Editor editor = pref.edit();
            editor.putBoolean("bendpressed", true);
            editor.commit();
            DialogFragment newFragment = new DatePickerFragment();
            newFragment.show(getSupportFragmentManager(), "datePicker");
        }
    });

    try {
        File mydirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "ReportIt");
        boolean success = true;
        if (!mydirectory.exists()) {
            success = mydirectory.mkdir();
        }
        if (success) {
            File reportsdirectory = new File(Environment.getExternalStorageDirectory() + File.separator
                    + "ReportIt" + File.separator + "Exported PDF's");
            boolean success2 = true;
            if (!reportsdirectory.exists()) {
                success2 = reportsdirectory.mkdir();
            }

        }

    } catch (Exception e) {
    }

    // Declaration weekdays editfields
    // Monday
    final EditText mondayText1 = (EditText) findViewById(R.id.mondayText1);
    final EditText mondayText2 = (EditText) findViewById(R.id.mondayText2);
    final EditText mondayText3 = (EditText) findViewById(R.id.mondayText3);
    final EditText mondayText4 = (EditText) findViewById(R.id.mondayText4);
    final EditText mondayText5 = (EditText) findViewById(R.id.mondayText5);
    final EditText mondayText6 = (EditText) findViewById(R.id.mondayText6);

    final EditText mondayTextTime1 = (EditText) findViewById(R.id.mondayTextTime1);
    final EditText mondayTextTime2 = (EditText) findViewById(R.id.mondayTextTime2);
    final EditText mondayTextTime3 = (EditText) findViewById(R.id.mondayTextTime3);
    final EditText mondayTextTime4 = (EditText) findViewById(R.id.mondayTextTime4);
    final EditText mondayTextTime5 = (EditText) findViewById(R.id.mondayTextTime5);
    final EditText mondayTextTime6 = (EditText) findViewById(R.id.mondayTextTime6);
    // End monday ---- Start tuesday
    final EditText tuesdayText1 = (EditText) findViewById(R.id.tuesdayText1);
    final EditText tuesdayText2 = (EditText) findViewById(R.id.tuesdayText2);
    final EditText tuesdayText3 = (EditText) findViewById(R.id.tuesdayText3);
    final EditText tuesdayText4 = (EditText) findViewById(R.id.tuesdayText4);
    final EditText tuesdayText5 = (EditText) findViewById(R.id.tuesdayText5);
    final EditText tuesdayText6 = (EditText) findViewById(R.id.tuesdayText6);

    final EditText tuesdayTextTime1 = (EditText) findViewById(R.id.tuesdayTextTime1);
    final EditText tuesdayTextTime2 = (EditText) findViewById(R.id.tuesdayTextTime2);
    final EditText tuesdayTextTime3 = (EditText) findViewById(R.id.tuesdayTextTime3);
    final EditText tuesdayTextTime4 = (EditText) findViewById(R.id.tuesdayTextTime4);
    final EditText tuesdayTextTime5 = (EditText) findViewById(R.id.tuesdayTextTime5);
    final EditText tuesdayTextTime6 = (EditText) findViewById(R.id.tuesdayTextTime6);
    // End tuesday ---- Start wednesday
    final EditText wednesdayText1 = (EditText) findViewById(R.id.wednesdayText1);
    final EditText wednesdayText2 = (EditText) findViewById(R.id.wednesdayText2);
    final EditText wednesdayText3 = (EditText) findViewById(R.id.wednesdayText3);
    final EditText wednesdayText4 = (EditText) findViewById(R.id.wednesdayText4);
    final EditText wednesdayText5 = (EditText) findViewById(R.id.wednesdayText5);
    final EditText wednesdayText6 = (EditText) findViewById(R.id.wednesdayText6);

    final EditText wednesdayTextTime1 = (EditText) findViewById(R.id.wednesdayTextTime1);
    final EditText wednesdayTextTime2 = (EditText) findViewById(R.id.wednesdayTextTime2);
    final EditText wednesdayTextTime3 = (EditText) findViewById(R.id.wednesdayTextTime3);
    final EditText wednesdayTextTime4 = (EditText) findViewById(R.id.wednesdayTextTime4);
    final EditText wednesdayTextTime5 = (EditText) findViewById(R.id.wednesdayTextTime5);
    final EditText wednesdayTextTime6 = (EditText) findViewById(R.id.wednesdayTextTime6);
    // End wednesday ---- Start thursday
    final EditText thursdayText1 = (EditText) findViewById(R.id.thursdayText1);
    final EditText thursdayText2 = (EditText) findViewById(R.id.thursdayText2);
    final EditText thursdayText3 = (EditText) findViewById(R.id.thursdayText3);
    final EditText thursdayText4 = (EditText) findViewById(R.id.thursdayText4);
    final EditText thursdayText5 = (EditText) findViewById(R.id.thursdayText5);
    final EditText thursdayText6 = (EditText) findViewById(R.id.thursdayText6);

    final EditText thursdayTextTime1 = (EditText) findViewById(R.id.thursdayTextTime1);
    final EditText thursdayTextTime2 = (EditText) findViewById(R.id.thursdayTextTime2);
    final EditText thursdayTextTime3 = (EditText) findViewById(R.id.thursdayTextTime3);
    final EditText thursdayTextTime4 = (EditText) findViewById(R.id.thursdayTextTime4);
    final EditText thursdayTextTime5 = (EditText) findViewById(R.id.thursdayTextTime5);
    final EditText thursdayTextTime6 = (EditText) findViewById(R.id.thursdayTextTime6);
    // End thursday ---- Start friday
    final EditText fridayText1 = (EditText) findViewById(R.id.fridayText1);
    final EditText fridayText2 = (EditText) findViewById(R.id.fridayText2);
    final EditText fridayText3 = (EditText) findViewById(R.id.fridayText3);
    final EditText fridayText4 = (EditText) findViewById(R.id.fridayText4);
    final EditText fridayText5 = (EditText) findViewById(R.id.fridayText5);
    final EditText fridayText6 = (EditText) findViewById(R.id.fridayText6);

    final EditText fridayTextTime1 = (EditText) findViewById(R.id.fridayTextTime1);
    final EditText fridayTextTime2 = (EditText) findViewById(R.id.fridayTextTime2);
    final EditText fridayTextTime3 = (EditText) findViewById(R.id.fridayTextTime3);
    final EditText fridayTextTime4 = (EditText) findViewById(R.id.fridayTextTime4);
    final EditText fridayTextTime5 = (EditText) findViewById(R.id.fridayTextTime5);
    final EditText fridayTextTime6 = (EditText) findViewById(R.id.fridayTextTime6);
    // End of friday and declaration weekdays editfields

    filenameText.setText(String.valueOf(cutName(intfilename)));

    com.github.clans.fab.FloatingActionButton bexport_pdf = (com.github.clans.fab.FloatingActionButton) findViewById(
            R.id.export_pdf);
    com.github.clans.fab.FloatingActionButton bexport_rtf = (com.github.clans.fab.FloatingActionButton) findViewById(
            R.id.export_rtf);
    com.github.clans.fab.FloatingActionButton bshare_email = (com.github.clans.fab.FloatingActionButton) findViewById(
            R.id.share_email);

    if (bexport_pdf != null) {
        bexport_pdf.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int weekID = getIntent().getIntExtra("weekID", 0);
                String filename = String.valueOf(AllReportsRV.itemTexte.get(weekID));
                String RESULT = Environment.getExternalStorageDirectory() + File.separator + "ReportIt"
                        + File.separator + "Exported PDF's" + File.separator + cutName(filename)
                        + getString(R.string.pdf_extension);

                export_pdf_class export_pdf_class = new export_pdf_class(FragmentActivity.this,
                        FragmentActivity.this, weekID, RESULT);

            }
        });
    }

    if (bshare_email != null) {
        bshare_email.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int weekID = getIntent().getIntExtra("weekID", 0);
                String filename = String.valueOf(AllReportsRV.itemTexte.get(weekID));
                String RESULT = Environment.getExternalStorageDirectory() + File.separator + "ReportIt"
                        + File.separator + "Exported PDF's" + File.separator + cutName(filename)
                        + getString(R.string.pdf_extension);

                export_email_class export_email_class = new export_email_class(FragmentActivity.this,
                        FragmentActivity.this, weekID, RESULT);

            }
        });
    }

    if (bexport_rtf != null) {
        bexport_rtf.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(FragmentActivity.this, "Coming soon", Toast.LENGTH_LONG).show();
            }
        });
    }

    final SharedPreferences pref = getApplicationContext().getSharedPreferences("userData", MODE_APPEND);
    String TextuserBossNameString = pref.getString("userBoss", "");
    fileauthorboss.setText(getString(R.string.instructor) + String.valueOf(TextuserBossNameString));

    StringBuilder textCatched = new StringBuilder();

    String filename = intfilename;
    Scanner read = null;
    try {
        read = new Scanner(new File(Environment.getExternalStorageDirectory() + File.separator
                + "/ReportIt/Reports" + File.separator + cutName(filename)));

        read.useDelimiter(";;");
        String start, start2, start3, start4, start5;

        while (read.hasNext()) {
            start = read.next();
            filenumber.setText(read.next().toString());
            filetag.setText(read.next().toString());
            startDate.setText(read.next().toString());
            endDate.setText(read.next().toString());
            mondayText1.setText(read.next().toString());
            mondayTextTime1.setText(read.next().toString());
            mondayText2.setText(read.next().toString());
            mondayTextTime2.setText(read.next().toString());
            mondayText3.setText(read.next().toString());
            mondayTextTime3.setText(read.next().toString());
            mondayText4.setText(read.next().toString());
            mondayTextTime4.setText(read.next().toString());
            mondayText5.setText(read.next().toString());
            mondayTextTime5.setText(read.next().toString());
            mondayText6.setText(read.next().toString());
            mondayTextTime6.setText(read.next().toString());

            read.nextLine();
            start2 = read.next();
            tuesdayText1.setText(read.next().toString());
            tuesdayTextTime1.setText(read.next().toString());
            tuesdayText2.setText(read.next().toString());
            tuesdayTextTime2.setText(read.next().toString());
            tuesdayText3.setText(read.next().toString());
            tuesdayTextTime3.setText(read.next().toString());
            tuesdayText4.setText(read.next().toString());
            tuesdayTextTime4.setText(read.next().toString());
            tuesdayText5.setText(read.next().toString());
            tuesdayTextTime5.setText(read.next().toString());
            tuesdayText6.setText(read.next().toString());
            tuesdayTextTime6.setText(read.next().toString());

            read.nextLine();
            start3 = read.next();
            wednesdayText1.setText(read.next().toString());
            wednesdayTextTime1.setText(read.next().toString());
            wednesdayText2.setText(read.next().toString());
            wednesdayTextTime2.setText(read.next().toString());
            wednesdayText3.setText(read.next().toString());
            wednesdayTextTime3.setText(read.next().toString());
            wednesdayText4.setText(read.next().toString());
            wednesdayTextTime4.setText(read.next().toString());
            wednesdayText5.setText(read.next().toString());
            wednesdayTextTime5.setText(read.next().toString());
            wednesdayText6.setText(read.next().toString());
            wednesdayTextTime6.setText(read.next().toString());

            read.nextLine();
            start4 = read.next();
            thursdayText1.setText(read.next().toString());
            thursdayTextTime1.setText(read.next().toString());
            thursdayText2.setText(read.next().toString());
            thursdayTextTime2.setText(read.next().toString());
            thursdayText3.setText(read.next().toString());
            thursdayTextTime3.setText(read.next().toString());
            thursdayText4.setText(read.next().toString());
            thursdayTextTime4.setText(read.next().toString());
            thursdayText5.setText(read.next().toString());
            thursdayTextTime5.setText(read.next().toString());
            thursdayText6.setText(read.next().toString());
            thursdayTextTime6.setText(read.next().toString());

            read.nextLine();
            start5 = read.next();
            fridayText1.setText(read.next().toString());
            fridayTextTime1.setText(read.next().toString());
            fridayText2.setText(read.next().toString());
            fridayTextTime2.setText(read.next().toString());
            fridayText3.setText(read.next().toString());
            fridayTextTime3.setText(read.next().toString());
            fridayText4.setText(read.next().toString());
            fridayTextTime4.setText(read.next().toString());
            fridayText5.setText(read.next().toString());
            fridayTextTime5.setText(read.next().toString());
            fridayText6.setText(read.next().toString());
            fridayTextTime6.setText(read.next().toString());

        }
        read.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

}

From source file:simulation.AureoZauleckAnsLab2.java

/**
 *
 */// ww  w. ja  v  a  2 s.c  om
public AureoZauleckAnsLab2() {
    // TODO code application logic here
    Scanner sc = new Scanner(System.in);
    String choice_s = "";
    int choice = 0;

    do {
        DisplayMenu();
        choice_s = sc.next();
        String title = "";
        Scanner s = new Scanner(System.in);
        //test input
        if (IsNumber(choice_s)) {
            choice = Convert(choice_s);
        } else {
            do {
                System.out.println("Please enter a number only.");
                choice_s = sc.next();
            } while (!IsNumber(choice_s));
            choice = Convert(choice_s);
        }

        if (choice == 1) {
            System.out.println("*** CATEGORICAL ***");
            System.out.println();
            System.out.println("TITLE(title of data set)");
            //sc = new Scanner(System.in);               
            title = s.nextLine();
            System.out.println("this is the title:  " + title);

            ArrayList a = new ArrayList<>();
            ArrayList<Double> percentages = new ArrayList<>();
            ArrayList<ArrayList> all;
            a = GetData();

            Collections.sort(a);
            all = Stratified(a);
            System.out.println("GROUPED DATA:  " + all);
            System.out.println("size  " + all.size());

            double percent = 0.0, sum = 0.0;
            for (int i = 0; i < all.size(); i++) {

                ArrayList inner = new ArrayList<>();
                inner = all.get(i);
                //System.out.println(inner);

                int inner_n = inner.size();
                percent = GetPercentage(N, inner_n);
                percentages.add(percent);
                sum += percent;
                System.out.println("" + inner.get(0) + "\t" + "        " + percent);
            }
            System.out.println("\t" + "total   " + Math.ceil(sum));
            System.out.println("all = " + all);

            JFrame frame = new JFrame();
            //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                        
            JTable table = new JTable();
            table.setModel(new DefaultTableModel((int) (all.size() + 2), 2));

            table.setValueAt("VALUE LABELS", 0, 0);
            table.setValueAt("PERCENTAGE", 0, 1);

            table.setValueAt("TOTAL = 100%", (int) (all.size() + 1), 1);

            for (int i = 0; i < all.size(); i++) {
                table.setValueAt(all.get(i).get(0), i + 1, 0);

                table.setValueAt(new DecimalFormat("#.##").format(percentages.get(i)), i + 1, 1);

            }

            JScrollPane scrollPane = new JScrollPane(table);
            scrollPane.setBorder(BorderFactory.createTitledBorder(title));
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setSize(300, 150);
            frame.setVisible(true);

            int type = 0, testT = 0;
            String typeTest = "";
            do {
                System.out.println("GENERATE GRAPH?");
                System.out.println("[1] YES");
                System.out.println("[2] NO");

                System.out.println();
                System.out.println("Please pick a number from the choices above.");

                typeTest = sc.next();

                if (IsNumber(typeTest)) {
                    testT = Convert(typeTest);
                } else {
                    do {
                        System.out.println("Please enter a number only.");
                        typeTest = sc.next();
                    } while (!IsNumber(typeTest));

                    testT = Convert(typeTest);
                }
                type = testT;
            } while (type < 1 || type > 2);

            if (type == 1) {
                DefaultPieDataset dataset = new DefaultPieDataset();
                for (int i = 0; i < all.size(); i++) {
                    dataset.setValue(
                            all.get(i).get(0).toString() + " = "
                                    + new DecimalFormat("#.##").format(percentages.get(i)) + "%",
                            percentages.get(i));
                }
                JFreeChart chart = ChartFactory.createPieChart(title, // chart title 
                        dataset, // data    
                        true, // include legend   
                        true, false);
                ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
                JFrame l = new JFrame();

                l.setContentPane(chartPanel);
                l.setSize(400, 400);
                l.setVisible(true);

            } else {
                //do nothing?
            }

            int type2 = 0, testT2 = 0;
            String typeTest2 = "";
            do {
                System.out.println("REDISPLAY TABLE?");
                System.out.println("[1] YES");
                System.out.println("[2] NO");
                System.out.println();
                System.out.println("Please pick a number from the choices above.");

                typeTest2 = sc.next();

                if (IsNumber(typeTest2)) {
                    testT2 = Convert(typeTest2);
                } else {
                    do {
                        System.out.println("Please enter a number only.");
                        typeTest2 = sc.next();
                    } while (!IsNumber(typeTest2));

                    testT2 = Convert(typeTest2);
                }
                type2 = testT2;
            } while (type2 < 1 || type2 > 2);

            if (type2 == 1) {
                DisplayTable(all, percentages, title);
            } else {
                //do nothing?
            }

        } else if (choice == 2) {

            System.out.println("*** NUMERICAL ***");
            System.out.println();
            System.out.println("TITLE(title of data set)");
            title = s.nextLine();

            System.out.println("this is the title  " + title);

            ArrayList<Double> a = new ArrayList<>();
            //ArrayList<ArrayList> all; 
            //a = GetData2();

            double[] arr = { 70, 36, 43, 69, 82, 48, 34, 62, 35, 15, 59, 139, 46, 37, 42, 30, 55, 56, 36, 82,
                    38, 89, 54, 25, 35, 24, 22, 9, 55, 19 };

            /*    
                double[] arr = {112, 100, 127,120,134,118,105,110,109,112,
                110, 118, 117, 116, 118, 122, 114, 114, 105, 109,
                107, 112, 114, 115, 118, 117, 118, 122, 106, 110,
                116, 108, 110, 121, 113, 120, 119, 111, 104, 111,
                120, 113, 120, 117, 105, 110, 118, 112, 114, 114};
             */
            N = arr.length;
            double t = 0.0;
            for (int i = 0; i < N; i++) {
                a.add(arr[i]);
            }

            Collections.sort(a);
            System.out.println("sorted a " + a);
            double min = (double) a.get(0);
            double max = (double) a.get(N - 1);

            System.out.println("Min" + min);
            System.out.println("Max" + max);

            double k = Math.ceil(1 + 3.322 * Math.log10(N));
            System.out.println("K " + k);

            double range = GetRange(min, max);
            System.out.println("Range " + range);

            double width = Math.ceil(range / k);
            //todo, i ceiling sa 1st decimal point
            System.out.println("Width " + width);

            ArrayList<Double> cl = new ArrayList<>();
            cl.add(min);
            double rest;
            for (int i = 1; i < k; i++) {
                cl.add(min += width);
            }

            ArrayList<Double> cl2 = new ArrayList<>();
            double cl2min = cl.get(1) - 1;
            cl2.add(cl2min);
            for (int i = 1; i < k; i++) {
                cl2.add(cl2min += width);
            }

            System.out.println("cl 1 " + cl);
            System.out.println("cl 2 " + cl2);

            ArrayList<Double> tlcl = new ArrayList<>();
            double tlclmin = cl.get(0) - Multiplier(cl.get(0));
            tlcl.add(tlclmin);
            for (int i = 1; i < k; i++) {
                tlcl.add(tlclmin += width);
            }

            ArrayList<Double> tucl = new ArrayList<>();
            double tuclmin = cl2.get(0) + Multiplier(cl2.get(0));
            tucl.add(tuclmin);
            for (int i = 1; i < k; i++) {
                tucl.add(tuclmin += width);
            }
            System.out.println("tlcl 1 " + tlcl);
            System.out.println("tucl 2 " + tucl);
            System.out.println("N " + N);

            ArrayList<Double> midList = new ArrayList<>();
            double mid = (cl.get(0) + cl2.get(0)) / 2;
            midList.add(mid);
            for (int i = 1; i < k; i++) {
                midList.add((tlcl.get(i) + tucl.get(i)) / 2);
            }

            for (int i = 0; i < k; i++) {
                System.out.println((tlcl.get(i) + tucl.get(i)) / 2);
            }

            System.out.println("mid" + midList);

            ArrayList<ArrayList<Double>> freq = new ArrayList<>();

            double ctr = 0.0;
            for (int j = 0; j < k; j++) {
                for (int i = 0; i < N; i++) {
                    if ((a.get(i) >= tlcl.get(j)) && (a.get(i) <= tucl.get(j))) {
                        freq.add(new ArrayList<Double>());
                        freq.get(j).add(a.get(i));
                    }
                }
            }

            ArrayList<Double> freqSize = new ArrayList<>();
            double size = 0.0;
            for (int i = 0; i < k; i++) {
                size = (double) freq.get(i).size();
                freqSize.add(size);
            }

            ArrayList<Double> freqPercent = new ArrayList<>();
            for (int i = 0; i < k; i++) {

                freqPercent.add(freqSize.get(i) / N * 100);
            }

            ArrayList<Double> cfs = new ArrayList<>();
            double cf = freqSize.get(0);
            cfs.add(cf);
            for (int i = 1; i < k; i++) {
                cf = freqSize.get(i) + cfs.get(i - 1);
                cfs.add(cf);
            }

            double sum = 0.0;
            for (int i = 1; i < cfs.size(); i++) {
                sum += cfs.get(i);
            }

            ArrayList<Double> cps = new ArrayList<>();
            double cp = 0.0;
            for (int i = 0; i < k; i++) {
                cp = (cfs.get(i) / N) * 100;
                cps.add(cp);
            }

            System.out.println("T o t a l: " + sum);
            System.out.println(cfs);
            System.out.println(cps);

            System.out.println("frequency list " + freq);

            System.out.println("frequency sizes " + freqSize);
            System.out.println("frequency percentages " + freqPercent);

            System.out.println();
            System.out.println(title);

            System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t"
                    + "PERCENT" + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(cl.get(i) + " - " + cl2.get(i) + "\t" + tlcl.get(i) + " - " + tucl.get(i)
                        + "\t" + midList.get(i) + "\t" + freq.get(i).size() + "\t"
                        + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }
            //2
            System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT"
                    + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(">=" + cl.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size()
                        + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }
            //3
            System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT"
                    + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println("<=" + cl2.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size()
                        + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }

            System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t"
                    + "PERCENT" + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(">=" + cl.get(i) + " and <=" + cl2.get(i) + "\t" + " - " + "\t" + " - "
                        + "\t" + freq.get(i).size() + "\t"
                        + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }

            DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title);

            int type = 0, testT = 0;
            String typeTest = "";
            do {
                do {

                    System.out.println();
                    System.out.println("GENERATE GRAPH?");
                    System.out.println("[1] YES");
                    System.out.println("[2] NO");
                    System.out.println();
                    System.out.println("Please pick a number from the choices above.");

                    typeTest = sc.next();

                    if (IsNumber(typeTest)) {
                        testT = Convert(typeTest);
                    } else {
                        do {
                            System.out.println("Please enter a number only.");
                            typeTest = sc.next();
                        } while (!IsNumber(typeTest));

                        testT = Convert(typeTest);
                    }
                    type = testT;
                } while (type < 1 || type > 2);

                if (type == 1) {
                    int bins = (int) k;
                    System.out.println();
                    System.out.println("You may input a label for your X axis:");
                    String x = "";
                    x = s.nextLine();
                    createHistogram(a, bins, title, x);

                    int type2 = 0, testT2 = 0;
                    String typeTest2 = "";
                    do {
                        System.out.println();
                        System.out.println("REDISPLAY TABLE?");
                        System.out.println("[1] YES");
                        System.out.println("[2] NO");
                        System.out.println();
                        System.out.println("Please pick a number from the choices above.");

                        typeTest2 = sc.next();

                        if (IsNumber(typeTest2)) {
                            testT2 = Convert(typeTest2);
                        } else {
                            do {
                                System.out.println("Please enter a number only.");
                                typeTest2 = sc.next();
                            } while (!IsNumber(typeTest2));

                            testT2 = Convert(typeTest2);
                        }
                        type2 = testT2;
                    } while ((type2 < 1 || type2 > 2) && type != 2);

                    if (type2 == 1) {

                        DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title);
                    } else {
                        //do nothing?
                    }
                }
            } while (type != 2);

        } else if (choice == 3) {
            System.out.println("*** QUIT ***");
        }

    } while (choice != 3);

    System.out.println("Thank you for your time.");
    s = new Simulation();

}

From source file:org.openhab.binding.amazonechocontrol.internal.Connection.java

public String convertStream(HttpsURLConnection connection) throws IOException {
    InputStream input = connection.getInputStream();
    if (input == null) {
        return "";
    }//from   ww w  .ja v  a2 s.c  o  m

    InputStream readerStream;
    if (StringUtils.equalsIgnoreCase(connection.getContentEncoding(), "gzip")) {
        readerStream = new GZIPInputStream(connection.getInputStream());
    } else {
        readerStream = input;
    }
    String contentType = connection.getContentType();
    String charSet = null;
    if (contentType != null) {
        Matcher m = charsetPattern.matcher(contentType);
        if (m.find()) {
            charSet = m.group(1).trim().toUpperCase();
        }
    }

    Scanner inputScanner = StringUtils.isEmpty(charSet)
            ? new Scanner(readerStream, StandardCharsets.UTF_8.name())
            : new Scanner(readerStream, charSet);
    Scanner scannerWithoutDelimiter = inputScanner.useDelimiter("\\A");
    String result = scannerWithoutDelimiter.hasNext() ? scannerWithoutDelimiter.next() : null;
    inputScanner.close();
    scannerWithoutDelimiter.close();
    input.close();
    if (result == null) {
        result = "";
    }
    return result;
}