id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
f292022a-17d1-4ddd-a898-369862f35d2f | public InHelloWord() {
texto = "";
} |
9ee23e89-6799-4dfd-8818-9059e89c1161 | public String getTexto() {
return texto;
} |
572d2260-0ef4-4430-926d-4008c7f8af10 | public void setTexto(String texto) {
this.texto = texto;
} |
08928055-0d10-49c8-9a9b-e06b78e24310 | public AppTest( String testName )
{
super( testName );
} |
c9886205-3cda-4594-8288-74c4d27a0668 | public static Test suite()
{
return new TestSuite( AppTest.class );
} |
3529634f-4baf-4217-9913-aa434b24ea02 | public void testApp()
{
assertTrue( true );
} |
f55dc180-52b3-4ef5-904b-f428bd5b24c2 | public OutHelloWord dizerOi(InHelloWord inHelloWord ) throws ServiceNotFoundException; |
29b4c59f-9451-43c9-8d54-d9c3aee47bb4 | public AppTest( String testName )
{
super( testName );
} |
b2395c0a-ddd1-488d-9c87-50c6b854b935 | public static Test suite()
{
return new TestSuite( AppTest.class );
} |
79140e6d-7320-4e07-8857-d634d6297bc8 | public void testApp()
{
assertTrue( true );
} |
7ad3137a-2b25-4fc7-9845-e83640edd2ef | public String printTail(String data, int times){
String resultData = "";
String result[] = data.split("\n");
for(int i = result.length-times; i < result.length ;i++){
resultData = resultData+"\n"+result[i];
}
return resultData;
} |
ca0d21ea-67bc-41dc-bcec-1bed676f946f | public static void main(String[] args) {
String data = null;
int times = 10;
String sCurrentLine;
fs fs = new fs();
if(args.length == 1)
data = fs.readFile(args[0]);
else{
times = Integer.parseInt(args[0]);
data = fs.readFile(args[1]);
}
showTail show_tail = new showTail();
data = show_tail.printTail(data, times);
System.out.println(data);
} |
040f43a5-a2f3-4ff5-b18b-d98ed473c01d | public String remove_extra_space(String data){
return data.replaceAll("\\ +"," ");
} |
87e7daff-684b-41a9-a6b4-34d89a1a7e5f | public static void main(String[] args) {
String data = null;
String sCurrentLine;
fs fs = new fs();
data = fs.readFile(args[0]);
removeSpace removeSpace = new removeSpace();
data = removeSpace.remove_extra_space(data);
fs fileWriter = new fs();
fileWriter.writeFile(args[0],data);
} |
f89fea72-05ce-451f-8a66-62175be9a98d | public String printHead(String data, int times){
String resultData = "";
String result[] = data.split("\n");
for(int i = 1;i<times;i++){
resultData = resultData+"\n"+result[i];
}
return resultData;
} |
57267a52-85b2-4cc9-bcbb-32b6eddc42dd | public static void main(String[] args) {
String data = null;
int times = 10;
String sCurrentLine;
fs fs = new fs();
if(args.length == 1)
data = fs.readFile(args[0]);
else{
times = Integer.parseInt(args[0])+1;
data = fs.readFile(args[1]);
}
showHead show_head = new showHead();
data = show_head.printHead(data,times);
System.out.println(data);
} |
ec3d731a-6f42-4460-97d7-fd2d485eb82b | public String removeCommonLines(String data){
String result="";
int index;
ArrayList list = new ArrayList();
String[] temp = data.split("\n");
int length = temp.length;
for (index = 1 ; index < length ; index++){
if(!temp[index-1].equals(temp[index]))
list.add(temp[index-1]);
}
list.add(temp[index-1]);
for ( int i = 0 ; i < list.size() ; i ++)
result += list.get(i)+"\n";
return result.substring(0,result.length()-1);
} |
661834ba-872f-4ab9-828b-fbcbc9e364da | public static void main(String[] args) {
String data = null;
int times = 10;
String sCurrentLine;
fs fs = new fs();
if(args.length == 1)
data = fs.readFile(args[0]);
else{
times = Integer.parseInt(args[0])+1;
data = fs.readFile(args[1]);
}
removeRedundantLines results = new removeRedundantLines();
data = results.removeCommonLines(data);
fs fileWriter = new fs();
fileWriter.writeFile(args[0],data);
} |
25dfb5c1-df28-41e0-abd4-2c66d78998da | public String showSortedData(String data, int option){
String lines[] = data.split("\n");
String sortedData ="";
if(option == 1)
Arrays.sort(lines, Collections.reverseOrder());
else
Arrays.sort(lines);
for(int i=0;i<lines.length;i++)
sortedData += "\n"+lines[i];
return sortedData;
} |
d3dd9375-f317-4b0c-9496-a83bdfdb66f8 | public static void main(String[] args) {
String data;
int options;
fs fs = new fs();
if(args.length == 2)
options = 1;
else
options = 0;
data = fs.readFile(args[0]);
SortData show_head = new SortData();
data = show_head.showSortedData(data,options);
System.out.println(data);
} |
4376e556-2301-45de-ba46-145c341aa3b3 | public static void main(String[] args) {
String msg = null;
String sCurrentLine;
if(args.length == 0){
System.out.println("filename is not given");
return;}
fs fs = new fs();
msg = fs.readFile(args[0]);
int worlds = msg.split(" ").length;
int lines = msg.split("\n").length-1;
int characters = msg.split("").length;
System.out.println(" "+lines+" "+worlds+" "+characters+" "+args[0]);
} |
c81ec1db-f8ee-43d7-aee8-4bd60718a6a8 | public void cutByField(String data,int field,String delimiter){
String [] lines= data.split("\n");
for(String s :lines){
try{
System.out.println(s.split(delimiter)[field]);
}
catch (ArrayIndexOutOfBoundsException ex){
System.out.println(s.split(delimiter)[0]);
}
}
} |
dc999b39-1c90-454f-84c7-e9363ff944cd | public static void main(String[] args) throws Exception {
Cut cut = new Cut();
fs file = new fs();
String fileData= file.readFile(args[0]);
if(args.length == 3){
if(args[1].startsWith("-f")&&args[2].startsWith("-d")){
int field = Integer.parseInt(args[1].substring(2, args[1].length()));
String delimiter = args[2].substring(2, args[2].length());
cut.cutByField(fileData, field, delimiter);
}
}
if(args.length == 2){
int field = Integer.parseInt(args[1].substring(2, args[1].length()));
String delimiter = " ";
cut.cutByField(fileData,field,delimiter);
}
} |
18bcca07-b8cb-4e91-9d91-c4e38bc28172 | public String readFile(String fileName){
String current_line = null,data="";
try{
BufferedReader reader = new BufferedReader(new FileReader(fileName));
while ((current_line = reader.readLine()) != null) {
data += current_line+"\n";
}
}
catch(Exception e){
System.out.println("file not found");
}
return data.substring(0,data.length()-1);
} |
cf2314ed-9336-40b4-b64c-cea7daca9a8c | public void writeFile(String fileName,String data){
try {
PrintWriter writer = new PrintWriter(fileName, "UTF-8");
String[] temp = data.split("\n");
for(String line : temp)
writer.println(line);
writer.close();
} catch (FileNotFoundException e) {
System.out.println("file not found");
} catch (UnsupportedEncodingException e) {
System.out.println("file not found");
}
} |
e1f6fe36-0f2e-43e7-a31a-0a5a608fd1e1 | public TowerPanel( int diskCount ) {
this.diskCount = diskCount;
firstTowerSelected = false;
towers = new Tower[TowerUtil.NUM_SPACES];
for( int i = 0; i < TowerUtil.NUM_SPACES; ++i )
towers[i] = new Tower( diskCount );
//add all disks of first color to the first tower
for( int i = diskCount - 1; i >= 0; --i )
towers[0].addDisk( new Disk( i + 1, TowerUtil.DISK_COLORS_TOWER_1[i] ) );
//add all disks of second color to the first tower
for( int i = diskCount - 1; i >= 0; --i )
towers[1].addDisk( new Disk( i + 1, TowerUtil.DISK_COLORS_TOWER_2[i] ) );
setBackground( Color.white );
addMouseListener( new MyMouseListener() );
} |
ab884ee7-7508-41df-82e3-2b93fb65239b | @Override
public Dimension getPreferredSize() {
// panel width = largest disk times the number of towers + 2 disk step width
int panelWidth = TowerUtil.MAX_DISKS * TowerUtil.DISK_WIDTH_STEP * TowerUtil.NUM_SPACES + 2 * TowerUtil.DISK_WIDTH_STEP + TowerUtil.NUM_SPACES;
int panelHeight = TowerUtil.DISK_HEIGHT * TowerUtil.MAX_DISKS * TowerUtil.MAX_TOWERS;
panelHeight = Math.round( 1.2f * (float)panelHeight );
return new Dimension( panelWidth, panelHeight );
} |
51a6765d-92d2-4580-b5e5-c07214bc4a7e | @Override
public void paintComponent( Graphics g ) {
super.paintComponent( g );
int towerWidth = getSize().width / TowerUtil.NUM_SPACES;
int towerX = towerWidth / 2 - TowerUtil.TOWER_WIDTH / 2;
int towerY = (int)(0.9 * getSize().height);
for( int i = 0; i < TowerUtil.NUM_SPACES; ++i ) {
towers[i].draw( g, towerX, towerY );
towerX += towerWidth;
}
} |
a0b5ccfa-120f-4363-8a2f-dc79927a1461 | public void setDiskCount( int nDisks ) {
this.diskCount = nDisks;
resetTowers();
} |
a4e5b9b4-de86-4271-8b94-14e80b76ea9a | public void moveDisk( int firstTower, int secondTower ) {
assert towers[firstTower].peek() != null && (towers[secondTower].peek() == null || towers[firstTower].peek().getDiskSize() <= towers[secondTower].peek().getDiskSize());
Disk disk = towers[firstTower].removeDisk();
towers[secondTower].addDisk( disk );
} |
6fe03186-704a-4097-9f39-711eb2505fe9 | public void resetTowers() {
towers = new Tower[TowerUtil.NUM_SPACES];
for( int i = 0; i < TowerUtil.NUM_SPACES; ++i )
towers[i] = new Tower( diskCount );
for( int i = diskCount - 1; i >= 0; --i )
towers[0].addDisk( new Disk( i + 1 , TowerUtil.DISK_COLORS_TOWER_1[i]) );
for( int i = diskCount - 1; i >= 0; --i )
towers[1].addDisk( new Disk( i + 1, TowerUtil.DISK_COLORS_TOWER_2[i] ) );
/* Paint the panel again */
repaint();
} |
953e7d96-ee59-4af0-8448-ec5c9a41ac9a | Tower getTower( int i ) {
return towers[i];
} |
486db4d3-487c-48a1-8c95-d985dc3ea3ce | @Override
public void mousePressed( MouseEvent e ) {
int towerWidth = getSize().width / TowerUtil.NUM_SPACES;
// determine chosen tower
int selectedTower;
int x = e.getX();
if( x < towerWidth )
selectedTower = 0;
else if( x < 2 * towerWidth )
selectedTower = 1;
else
selectedTower = 2;
/* first tower to be selected */
if( !firstTowerSelected )
/* check whether this tower is not isEmpty */
if( towers[selectedTower].isEmpty() )
JOptionPane.showConfirmDialog( null, "Selected tower is empty!",
"", JOptionPane.CLOSED_OPTION, JOptionPane.WARNING_MESSAGE );
else {
firstTower = selectedTower;
firstTowerSelected = true;
Disk disk = towers[firstTower].peek();
disk.setSelected( true );
repaint();
}
else {
firstTowerSelected = false;
/* check whether this is a feasible move */
Disk disk1 = towers[firstTower].peek();
Disk disk2 = towers[selectedTower].peek();
disk1.setSelected( false );
if( disk2 == null || disk1.getDiskSize() <= disk2.getDiskSize() )
moveDisk( firstTower, selectedTower );
else // incorrect move
/* cannot put a larger disk on a smaller one! */
JOptionPane.showConfirmDialog( null, "This move is not allowed!",
"", JOptionPane.CLOSED_OPTION, JOptionPane.WARNING_MESSAGE );
repaint();
}
} |
aaa7f309-8a52-4fd4-8d06-ac11b22b9460 | public static Color randomVibrantColor() {
Random r = new Random();
Color c;
int d = r.nextInt( 128 );
switch( r.nextInt( 6 ) ) {
case 0:
return new Color( 255, 0, d );
case 1:
return new Color( 0, 255, d );
case 2:
return new Color( 255, d, 0 );
case 3:
return new Color( 0, d, 255 );
case 4:
return new Color( d, 0, 255 );
case 5:
return new Color( d, 255, 0 );
default:
throw new AssertionError();
}
} |
24d90bf5-8818-4669-8717-cc3b63f93a5a | public static Color randomPastelColor() {
final Color mix = Color.white;
Random random = new Random();
// mix the color
int red = (random.nextInt( 256 ) + mix.getRed()) / 2;
int green = (random.nextInt( 256 ) + mix.getGreen()) / 2;
int blue = (random.nextInt( 256 ) + mix.getBlue()) / 2;
return new Color( red, green, blue );
} |
b72a0f8c-74fa-468c-ba6f-2031ee2e8c0d | private TowerUtil() {
} |
95d9d210-7d03-4f90-9be2-6eebb3bd80e1 | public TowersOfBerlin() {
super( "Towers of Berlin" );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
hanoiPanel = new TowerPanel( DEFAULT_NUM_DISKS );
getContentPane().add( hanoiPanel, BorderLayout.CENTER );
//create button panel
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout( new GridLayout( 1, 2 ) );
JButton redoButton = new JButton( "<<" );
redoButton.setName( "backward" );
MyButtonListener buttonHandler = new MyButtonListener();
redoButton.addActionListener( buttonHandler );
buttonPanel.add( redoButton );
JButton undoButton = new JButton( ">>" );
undoButton.setName( "forward" );
undoButton.addActionListener( buttonHandler );
buttonPanel.add( undoButton );
MySliderListener sliderHandler = new MySliderListener();
JPanel panelSlider = new JPanel();
panelSlider.setLayout( new BoxLayout( panelSlider, BoxLayout.Y_AXIS ) );
panelSlider.add( buttonPanel );
getContentPane().add( panelSlider, BorderLayout.NORTH );
// create panel and slider for the number of disks
JPanel panelDisks = new JPanel();
JLabel labelDisks = new JLabel( "Number of disks:" );
JSlider sliderDisk = new JSlider();
sliderDisk.setName( "disks" );
sliderDisk.setMinimum( TowerUtil.MIN_DISKS );
sliderDisk.setMaximum( TowerUtil.MAX_DISKS );
sliderDisk.setValue( DEFAULT_NUM_DISKS );
sliderDisk.setMajorTickSpacing( 1 );
sliderDisk.setPaintLabels( true );
sliderDisk.setPaintTicks( true );
sliderDisk.setSnapToTicks( true );
sliderDisk.addMouseListener( sliderHandler );
final JButton automatic = new JButton( "Automatic" );
JButton compute = new JButton( "Calculate solution" );
compute.addActionListener( new ActionListener() {
@Override
public void actionPerformed( ActionEvent e ) {
automatic.setEnabled( false );
solveProblem();
automatic.setEnabled( true );
}
});
automatic.addActionListener( new ActionListener() {
@Override
public void actionPerformed( ActionEvent e ) {
final int delayFactor = TowerUtil.MAX_DELAY/(TowerUtil.MAX_DISKS - TowerUtil.MIN_DISKS);
final int update = -delayFactor*hanoiPanel.getTower( 0 ).getMaxHeight() + TowerUtil.MAX_DELAY + delayFactor * TowerUtil.MIN_DISKS;
timer.setDelay( update );
timer.start();
}
});
panelDisks.add( labelDisks );
panelDisks.add( sliderDisk );
panelDisks.add( compute );
panelDisks.add( automatic );
getContentPane().add( panelDisks, BorderLayout.SOUTH );
pack();
// Set up a timer
int update = (1000/48);
timer = new Timer( update, new ActionListener() {
@Override
public void actionPerformed( ActionEvent e ) {
forward();
if( toDo.empty() )
timer.stop();
repaint();
}
});
} |
69b2b924-825b-4bd7-ac38-b523469c4089 | @Override
public void actionPerformed( ActionEvent e ) {
automatic.setEnabled( false );
solveProblem();
automatic.setEnabled( true );
} |
96c14dbb-2455-4de8-9b2d-b0d9439bd6b1 | @Override
public void actionPerformed( ActionEvent e ) {
final int delayFactor = TowerUtil.MAX_DELAY/(TowerUtil.MAX_DISKS - TowerUtil.MIN_DISKS);
final int update = -delayFactor*hanoiPanel.getTower( 0 ).getMaxHeight() + TowerUtil.MAX_DELAY + delayFactor * TowerUtil.MIN_DISKS;
timer.setDelay( update );
timer.start();
} |
32689f4f-dec1-4d8a-96a7-e0e8c3b14ebe | @Override
public void actionPerformed( ActionEvent e ) {
forward();
if( toDo.empty() )
timer.stop();
repaint();
} |
ee61ec98-d5ad-4af4-b955-1efe14ba9979 | private void solveProblem() {
TowersOfBerlinSolver solver = new TowersOfBerlinSolver(hanoiPanel.getTower(0), hanoiPanel.getTower(1), hanoiPanel.getTower(2));
solver.solve();
toDo= solver.getActions();
} |
fdb0289d-afbf-4acf-8eb5-21e9031151d4 | private void forward() {
if (!toDo.empty()) {
hanoiPanel.moveDisk(toDo.peek().from(), toDo.peek().to());
done.push(toDo.peek());
toDo.pop();
repaint();
}
} |
036a7fd2-7c86-4273-8b92-b5d463bb2a21 | private void backward() {
if (!done.empty()) {
hanoiPanel.moveDisk(done.peek().to(), done.peek().from());
toDo.push(done.peek());
done.pop();
repaint();
}
} |
a9a85b6f-e76a-47e6-9cba-534a1c433779 | public static void main( String args[] ) {
try {
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
} catch( Exception e ) {
// Problem changing UI occured. Ignore and show in default mode instead.
}
java.awt.EventQueue.invokeLater( new Runnable() {
@Override
public void run() {
new TowersOfBerlin().setVisible( true );
}
} );
} |
0b4688f1-77a1-4124-96c6-3ca5c0bcf722 | @Override
public void run() {
new TowersOfBerlin().setVisible( true );
} |
6997af82-d61f-4f4e-84ea-db63da5f9d9b | @Override
public void mouseReleased( MouseEvent event ) {
JSlider source = (JSlider)event.getSource();
/* gets and sets the number of disks */
if( source.getName().equals( "disks" ) ) {
timer.stop();
toDo.clear();
done.clear();
hanoiPanel.setDiskCount( source.getValue() );
}
} |
ed34ec00-fcd1-4b7e-85f3-0e7902631b27 | @Override
public void actionPerformed( ActionEvent e ) {
JButton source = (JButton)e.getSource();
String name = source.getName();
timer.stop();
if( "forward".equals( name ) )
forward();
else if( "backward".equals( name ) )
backward();
repaint();
} |
bb7a654f-ea0a-4dcc-ac58-ea2094d199c6 | public Disk( int size, Color diskColor ) {
diskSize = size;
this.diskColor = diskColor;
isSelected = false;
} |
ff1dc3a1-7cd1-429e-ac35-d82f82bc0cbc | public boolean isSelected() {
return isSelected;
} |
b1374177-795c-4a28-8e57-c992fb6a2a96 | public void setSelected( boolean isSelected ) {
this.isSelected = isSelected;
} |
3f128a74-b59c-439a-bb75-49643b078d76 | public int getDiskSize() {
return this.diskSize;
} |
c7fca4b2-d364-49d4-b951-640247c34f30 | int getDiskWidth() {
return diskSize * TowerUtil.DISK_WIDTH_STEP;
} |
a1ec14cc-6247-42d6-90df-f444bdc03098 | void draw( Graphics g1, int x, int y ) {
Graphics2D g = (Graphics2D)g1;
int width = getDiskWidth();
int xpos = x - width / 2;
g.setColor( diskColor );
g.fillRoundRect( xpos, y, width, TowerUtil.DISK_HEIGHT, TowerUtil.ARC_WIDTH, TowerUtil.ARC_HEIGHT );
g.setStroke( new BasicStroke( 2 ) );
if( isSelected ) {
g.setColor( Color.red );
g.setStroke( new BasicStroke( 4 ) );
} else
g.setColor( Color.black );
g.drawRoundRect( xpos, y, width, TowerUtil.DISK_HEIGHT, TowerUtil.ARC_WIDTH, TowerUtil.ARC_HEIGHT );
} |
25bfde0c-bf29-49f0-813f-86c421784109 | public TowersOfBerlinSolver( Tower left, Tower middle, Tower right) {
this.left=left;
this.middle=middle;
this.right=right;
towerarray = new Tower[3];
towerarray[0]= left;
towerarray[1]= middle;
towerarray[2]= right;
} |
0bddd737-61a8-4de5-a9b9-4f4def8a62ae | public void merge(int tower1, int tower2, int index, int empty) {
if (index==1) {
//merge a tower with the height 1
moveDisk(tower1, tower2);
} else if (index==2) {
//merge a tower with the height 2
moveDisk(tower1, empty);
moveDisk(tower2, empty);
moveDisk(tower1, tower2);
moveDisk(empty, tower2);
moveDisk(empty, tower2);
}
if (index>2){
merge(tower1, tower2, index-1, empty);
moveTower(tower2, tower1, (index*2)-2, empty);
moveDisk (tower1, tower2);
moveTower(empty, tower1, (index*2)-2, tower2);
}
} |
b09f7a9b-6690-4812-b083-c8914f1ef25c | public void moveTower(int tower1, int tower2, int index, int empty) {
if(index>0) {
moveTower(tower1, empty, index-1, tower2);
moveDisk(tower1, empty);
moveTower(tower2, tower1, index-1, empty);
}
} |
7eb4ea30-96bc-479a-871e-177151f66bd8 | private void moveDisk( int from, int to ) {
towerarray[to].addDisk(towerarray[from].peek());
towerarray[from].removeDisk();
DiskAction action = new DiskAction(from, to);
actions.add(action);
} |
de5be7cd-6652-40c9-8977-105ad02e32ae | public Stack<DiskAction> getActions() {
while(!actions.empty()) {
actions2.push(actions.peek());
actions.pop();
}
return actions2;
} |
f4df7bed-d8d2-41c6-bb9e-b629344dc94c | public void solve() {
int disk=middle.countDisk();
int diff=0;
merge(0, 1, disk-1, 2);
moveDisk(0, 2);
moveTower(1, 2, middle.countDisk(), 0);
moveDisk(2,1);
while(middle.countDisk()!=disk) {
diff=Math.abs(left.countDisk()-middle.countDisk()-1);
moveTower(0, 2, diff, 1);
moveTower(1, 2, diff-1, 0);
}
} |
ffa04473-5dbb-4f63-9e1b-eb084fe59a42 | public DiskAction( int from, int to ) {
this.from = from;
this.to = to;
} |
d86c6edc-26e7-4bcd-a24a-fb2d3dc91fe9 | public int from() {
return from;
} |
dd29f8df-7ac7-4b59-9eee-4b90cc26e915 | public int to() {
return to;
} |
c52b2842-a4e5-4386-9343-66bc6b49ae71 | public Tower( int maxHeight ) {
disks = new Stack<Disk>();
this.maxHeight = maxHeight;
} |
eb4882f5-851f-4806-a515-b143e56e5b9e | public Tower( Tower t ) {
this.disks = new Stack<Disk>();
for( Disk disk : t.disks )
this.disks.add( disk );
this.maxHeight = t.maxHeight;
} |
51dbdae4-3e45-4e20-bb02-c13af679608b | public int getMaxHeight() {
return this.maxHeight;
} |
e40e41c6-f486-4433-9427-93f99d6edbf9 | public boolean isEmpty() {
return disks.empty();
} |
3f43c676-617e-4189-8ee6-aa39fd0c744f | void addDisk( Disk disk ) {
if( !disks.isEmpty() && disk.getDiskSize() > disks.peek().getDiskSize() )
throw new IllegalArgumentException( "Disk size do not fit!" );
disks.push( disk );
} |
945123ed-b008-4847-89ad-4e26790b0bfa | public Disk peek() {
if( disks.empty() )
return null;
else
return disks.peek();
} |
df6d54e3-4577-46e3-82c5-0e44258502b0 | public Disk removeDisk() {
if( disks.empty() ){
return null;
}
else
return disks.pop();
} |
e52c5fc0-d67f-42f0-842e-4222997db502 | public int countDisk() {
Stack<Disk> diskcount;
diskcount = (Stack)disks.clone();
int i=0;
while (!diskcount.empty()) {
diskcount.pop();
i++;
}
return i;
} |
ca0d075f-4fe8-46be-a893-b65fcd59edf9 | public void draw( Graphics g, int x, int y ) {
int height = TowerUtil.DISK_HEIGHT * this.maxHeight * TowerUtil.MAX_TOWERS;
g.setColor( Color.gray );
g.fillRect( x, y - height - 2, TowerUtil.TOWER_WIDTH, height + 2 );
// draw disks
if( !disks.empty() ) {
// create a local stack of disks in reverse order
Stack<Disk> localstack = new Stack<Disk>();
while( !disks.empty() )
localstack.push( disks.pop() );
// draw the disks
int curheight = 1;
int diskX = x + TowerUtil.TOWER_WIDTH / 2;
while( !localstack.empty() ) {
Disk disk = localstack.pop();
int diskY = y - TowerUtil.DISK_HEIGHT * curheight;
disk.draw( g, diskX, diskY );
// put disk back on global stack
disks.push( disk );
curheight++;
}
}
} |
2fd6cd8b-69f4-4bf3-924d-54e87be8528f | @SuppressWarnings("unchecked")
public static void main(String[] args) {
CommandLineParser parser = new PosixParser();
CommandLine cmd;
try {
cmd = parser.parse(options, args);
} catch (MissingOptionException e) {
for(Object obj : options.getOptions()){
Option opt = (Option)obj;
out(opt.toString() + (opt.isRequired() ? " - REQUIRED" : " - OPTIONAL"));
}
return;
}catch (ParseException e) {
out("Error parsing arguments");
e.printStackTrace();
return;
}
String basedir = cmd.getOptionValue('b');
String[] filenames = cmd.getOptionValue('f').split(",");
Map<String, Object> model = new HashMap<>();
if(cmd.hasOption("m")){
Gson gson = new Gson();
model = gson.fromJson(cmd.getOptionValue('m'), HashMap.class);
}
mergeAndPrint(basedir,filenames, model, !cmd.hasOption('u'));
} |
ebfd00d3-cc5a-481e-8eed-3d1e09fa4e02 | private static void mergeAndPrint(String basedir, String[] filenames, Map<String, Object> model, boolean pretty) {
TemplateEngine engine;
try {
engine = EngineFactory.build(basedir, null, filenames);
engine.setPretty(pretty);
} catch (IOException e) {
out("error creating the template engine");
e.printStackTrace();
return;
}
for(String template:filenames){
try {
out(engine.merge(template, model));
} catch (IOException e) {
out("Error processing " + template);
e.printStackTrace();
}
}
} |
0325fe57-e193-4022-ae67-a77e4fbd3d13 | private static void out(String text){
System.out.println(text);
} |
78467873-b684-4379-bd82-d83fefc78056 | String merge(String textTemplate, Map<String, Object> model) throws IOException; |
5dbbbc9d-e381-469d-a327-f2dd15e62600 | String getEncoding(); |
56f9c099-2f17-49f9-8849-b4c53feb341b | String getBasedir(); |
8c43abee-a68a-47ce-a343-924703281ebf | void setPretty(boolean pretty); |
17d78958-1813-466b-be5a-16cfd2af2eeb | public static TemplateEngine build(String basedir, String encoding, String... filenames) throws IOException {
if (filenames == null) {
throw new UnsupportedOperationException("just supported .jade files");
} else {
for (String file : filenames) {
if (!file.endsWith(".jade"))
throw new UnsupportedOperationException("just supported .jade files");
}
}
return new JadeEngine(basedir, encoding);
} |
d185d642-f189-4e99-ab57-8fd71580e4da | public JadeEngine(String basedir, String encoding) throws IOException {
super();
setBasedir(basedir);
setEncoding(encoding);
config = new JadeConfiguration();
config.setTemplateLoader(new FileTemplateLoader(getBasedir(), getEncoding()));
config.setPrettyPrint(true);//pretty out default
} |
f934bdff-0cf3-49c0-9974-c48f12a97710 | public JadeEngine() throws IOException {
this(null, null);
} |
10f0d322-e3c0-4fb4-9918-3c0b04d4a1b9 | @Override
public String merge(String templateName, Map<String, Object> model) throws IOException {
JadeTemplate template = config.getTemplate(templateName);
return config.renderTemplate(template, model);
} |
90139661-92e6-4265-be9e-9fe257a23575 | @Override
public String getBasedir() {
return basedir;
} |
1d65e520-909b-4ea9-b736-d6b1eb30dce1 | public void setBasedir(String basedir) throws IOException {
if (basedir != null && new File(basedir).exists())
this.basedir = basedir;
else {
Path base = Files.createTempDirectory("tlmerge");
this.basedir = base.toString() + File.pathSeparator;
}
} |
6de7e5b2-235a-449c-a2ff-ad326c0edd08 | @Override
public String getEncoding() {
return encoding;
} |
6fe612f0-8675-4711-97c6-6a4fa538218f | public void setEncoding(String encoding) {
if (encoding != null)
this.encoding = encoding;
} |
0540baf1-5653-4390-9c1b-8570596b642b | @Override
public void setPretty(boolean pretty) {
config.setPrettyPrint(pretty);
} |
eecd76f5-010a-48c2-bfca-a80682a532d3 | @Test(expected=UnsupportedOperationException.class)
public void shouldThrowException() throws IOException{
EngineFactory.build(null, null, null);
} |
a43959cd-1e9d-4153-9327-18bfc8628eb2 | @Test(expected=UnsupportedOperationException.class)
public void shouldThorwExceptionNotSupport() throws IOException {
EngineFactory.build(null, null, "tl1.jade, tl2.vm");
} |
8ea9cf02-abc7-4581-b924-2f81298f1029 | @Test
public void testBuildJadeEngine() throws IOException {
TemplateEngine eng = EngineFactory.build(null, null, "tl1.jade");
assertTrue(eng instanceof JadeEngine);
} |
b3f8a946-10a5-424e-b325-de62812d72a0 | @Before
public void setup() throws IOException{
engine = new JadeEngine();
} |
aa7f3f44-be00-47ce-8595-45db4f98d0a2 | @After
public void down(){
File baseDir = new File(engine.getBasedir());
baseDir.delete();
} |
2270601c-e581-4c1f-8816-92f51aee091f | @Test
public void test() throws Exception {
Map<String, Object> model = new HashMap<>();
model.put("varname", "just a name");
String file = engine.getBasedir() + "tl1.jade";
FileWriter writer = new FileWriter(file);
writer.write("| hello test, value: #{model.varname}");
writer.flush();
writer.close();
String result = engine.merge("tl1.jade", model);
assertNotNull(result);
assertEquals("hello test, value: just a name", result);
} |
0724a105-78af-432a-bff2-ae8883fb0389 | public Right() {
// TODO Auto-generated constructor stub
System.out.println(">> right");
} |
b88b06df-1951-48ea-9dc1-7a7b559238b4 | public Left() {
// TODO Auto-generated constructor stub
System.out.println(">>");
System.out.println("LEFT");
System.out.println(">>>>>");
} |
a545403e-5484-49be-9322-5bbdc58375bb | public LLeft() {
// TODO Auto-generated constructor stub
} |
da9647bc-f77e-424e-a42f-7a6c35c45f4d | public RRight() {
// TODO Auto-generated constructor stub
} |
8d3bc0f6-898e-4227-86f5-8411aba0586a | public Proo() {
// TODO Auto-generated constructor stub
} |
7269d5d2-4eb7-4deb-944f-b4e9dd00c314 | public static void main(String[] args) {
System.out.println(">> HELLO WORLD");
} |
30971688-1ba7-48c6-be7a-ac76e4cd7dc0 | public String getNick(); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.