Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
initial files
  • Loading branch information
codeayra authored Mar 29, 2017
1 parent 3fd2825 commit 1201b3a
Show file tree
Hide file tree
Showing 25 changed files with 1,580 additions and 0 deletions.
72 changes: 72 additions & 0 deletions AllocationOverwrite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
*
*/
package com.ankit.gcexamples;

import java.util.Random;

/**
* After running this program do following steps
* 1) run jps command to find out the process id of this program <pid>
* 2) jstat -gcutil <pid> => shoes space in %
* 3) jstat -gccause <pid> => cause of garbage collection
* 4) jstat -gccapacity <pid> => amount of memory allocated min max and current
* 5) jstat -gc <pid> => capacity and utilization of memory
* 6) jstat -gc <pid> <ms> <no of rows> => shows total rows after each ms provided.
*
* This program uses default gc which allocates memory fast as uses pointer
* use VM argument -XX:+UseG1GC to use G1 gc which allocate memory slowly as 1/3.
*
* in place of jstat use "jvisualvm" tool and its visualgc plugin which is default supplied by jdk.
* @author ankitkumar
*
*/
public class AllocationOverwrite {

/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {

int arraySize=1000000;
GCMe gcmes[]=new GCMe[arraySize];

int count=0;
Random random=new Random();
while(true){

gcmes[random.nextInt(arraySize)]=new GCMe();
if(count%arraySize==0){
//2 million allocation a second
//if(count%2000000==0){
System.out.print(".");
//GCMxBeanExample.workingMXBean();
}
count++;

//added to see easily what happening in "visualgc"
//to see visualgc run "visualvm" command on cmd as its comes with jdk.
Thread.sleep(1);
}

}

}

class GCMe{
long a;
long aa;
long aaa;
long aaaa;
long aaaaa;
long aaaaaa;
long aaaaaaa;
long aaaaaaaa;
long aaaaaaaaa;
long aaaaaaaaaa;
long aaaaaaaaaaa;
long aaaaaaaaaaaa;
long aaaaaaaaaaaaa;
long aaaaaaaaaaaaaa;
}
98 changes: 98 additions & 0 deletions ArrayLeftRotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
*
*/
package org.gradle;

import java.util.Scanner;

/**
* @author ankitkumar
*
*/
public class ArrayLeftRotation {

private final static String EMPTY_STRING=" ";
private final static int MAX_NO_OF_INTEGERS=100000;
private final static int MAX_ELEMENT_VALUE=1000000;

/**
* @param args
*/
public static void main(String[] args) {

ArrayLeftRotation.Arguments input=new ArrayLeftRotation.Arguments();
ArrayLeftRotation mySolution=new ArrayLeftRotation();

mySolution.readInput(input);

if(!(input.inputArray.length==input.noOfRotations)){
mySolution.rotate(input);
}
for(int element:input.inputArray){
System.out.print(element+EMPTY_STRING);
}

}

private void rotate(Arguments input){
int length=input.inputArray.length;
for(int pass=0;pass<input.noOfRotations;pass++){
int element=input.inputArray[0];
for(int index=0;index<length-1;index++){
input.inputArray[index]=input.inputArray[index+1];
}
input.inputArray[length-1]=element;
}
}

private void readInput(Arguments input) {

Scanner inputScanner=new Scanner(System.in);
try{
String line=inputScanner.nextLine();
String[] firstArg=line.split(EMPTY_STRING);
if(firstArg.length!=2){
throw new IllegalArgumentException("Invalid Input");
}
int inputArrayLength=Integer.parseInt(firstArg[0]);
input.noOfRotations=Integer.parseInt(firstArg[1]);
if(!(1<=inputArrayLength && inputArrayLength<=MAX_NO_OF_INTEGERS)){
throw new IllegalArgumentException("Invalid Array Length");
}
if(!(1<=input.noOfRotations && input.noOfRotations<=inputArrayLength)){
throw new IllegalArgumentException("Invalid No of Rotations");
}

String[] inputArrayString=inputScanner.nextLine().split(EMPTY_STRING);

if(inputArrayLength!=inputArrayString.length){
throw new IllegalArgumentException("Invalid input array");
}

input.inputArray=new int[inputArrayLength];

for(int index=0;index<inputArrayLength;index++){
int element=Integer.parseInt(inputArrayString[index]);
if(!(1<=element && element<=MAX_ELEMENT_VALUE)){
throw new IllegalArgumentException("Invalid input array element");
}else{
input.inputArray[index]=element;
}

}

} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid input array");
}finally{
inputScanner.close();
}
}

public static class Arguments {

private int noOfRotations;
private int[] inputArray;

}

}
76 changes: 76 additions & 0 deletions ArraysDS.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
*
*/
package org.gradle;

import java.util.Arrays;
import java.util.Scanner;

/**
* @author ankitkumar
*
*/
public class ArraysDS {

private final static String EMPTY_STRING=" ";

/**
* @param args
*/
public static void main(String[] args) {

ArraysDS.Arguments input=new ArraysDS.Arguments();
ArraysDS mySolution=new ArraysDS();

mySolution.readInput(input);


mySolution.doReverse(input);

}

private void doReverse(Arguments input){
for(int index=input.length-1;index>=0;index--){
System.out.print(input.inputArray[index]+EMPTY_STRING);
}

}

private void readInput(Arguments input) {

Scanner inputScanner=new Scanner(System.in);
try{
input.length=Integer.parseInt(inputScanner.nextLine());
if(!(1<=input.length && input.length<=1000)){
throw new IllegalArgumentException("Invalid length");
}
String[] inputArrayString=inputScanner.nextLine().split(EMPTY_STRING);
if(input.length!=inputArrayString.length){
throw new IllegalArgumentException("Invalid input array");
}
input.inputArray=new int[input.length];
for(int index=0;index<input.length;index++){
int element=Integer.parseInt(inputArrayString[index]);
if(!(1<=element && element<=10000)){
throw new IllegalArgumentException("Invalid input array element");
}else{
input.inputArray[index]=element;
}

}

} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid input array");
}finally{
inputScanner.close();
}
}

public static class Arguments {

private int length;
private int[] inputArray;

}

}
49 changes: 49 additions & 0 deletions CombinedPropertyDataLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
*
*/
package com.tangoe.components;

import java.util.HashMap;
import java.util.Map;

/**
* @author ankitkumar
*
*/
public class CombinedPropertyDataLoader implements PropertyDataLoader {

private JDBCPropertyDataLoader jdbcPropertyDataLoader;
private FilePropertyDataLoader filePropertyDataLoader;


public CombinedPropertyDataLoader(JDBCPropertyDataLoader jdbcPropertyDataLoader,
FilePropertyDataLoader filePropertyDataLoader) {

this.jdbcPropertyDataLoader = jdbcPropertyDataLoader;
this.filePropertyDataLoader = filePropertyDataLoader;

}

@Override
public void startLoading() {
jdbcPropertyDataLoader.startLoading();
filePropertyDataLoader.startLoading();

}

@Override
public void stopLoading() {
jdbcPropertyDataLoader.stopLoading();
filePropertyDataLoader.stopLoading();
}

@Override
public Map<String, String> getProps() {
Map<String, String> props = new HashMap<>();
//Database property takes precedence in case of clash.
props.putAll(filePropertyDataLoader.getProps());
props.putAll(jdbcPropertyDataLoader.getProps());
return props;
}

}
32 changes: 32 additions & 0 deletions Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.triplepoint.code.components;

public abstract class Command {

protected String name;
protected String description;

public Command(String name,String description) {
this.name=name;
this.description=description;
}


public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

protected abstract void execute(String... input);


@Override
public String toString() {
return name + " , description: " + description ;
}



}
16 changes: 16 additions & 0 deletions DateCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.triplepoint.code.components;

import java.util.Date;

public class DateCommand extends Command {

public DateCommand(String name,String description){
super(name,description);
}

@Override
protected void execute(String... input) {
System.out.println(new Date());
}

}
26 changes: 26 additions & 0 deletions ExitCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
*
*/
package com.triplepoint.code.components;

/**
* @author ankitkumar
*
*/
public class ExitCommand extends Command {

public ExitCommand(String name,String description) {
super(name,description);
}

/* (non-Javadoc)
* @see com.triplepoint.code.components.Command#execute(java.lang.String[])
*/
@Override
protected void execute(String... input) {

System.exit(0);

}

}
Loading

0 comments on commit 1201b3a

Please sign in to comment.