file_id
int64 1
250k
| content
stringlengths 0
562k
| repo
stringlengths 6
115
| path
stringlengths 1
147
|
---|---|---|---|
910 | class Solution {
public void setZeroes(int[][] matrix) {
//a dumb approach is to turn this matrix into char and convert changed 0 to x and then convert back BUT cannot do it in place
//using two sets to store the row and column will be converted
// HashSet<Integer> row = new HashSet<>();
// HashSet<Integer> col = new HashSet<>();
// int m = matrix.length, n = matrix[0].length;
// for (int i = 0; i < m; i++){
// for (int j = 0; j < n; j++){
// if (matrix[i][j] == 0){
// row.add(i);
// col.add(j);
// }
// }
// }
// Iterator<Integer> itRow = row.iterator();
// while (itRow.hasNext()){
// int temp = itRow.next();
// for (int i = 0; i < n; i++)
// matrix[temp][i] = 0;
// }
// Iterator<Integer> itCol = col.iterator();
// while (itCol.hasNext()){
// int temp = itCol.next();
// for (int j = 0; j < m; j++)
// matrix[j][temp] = 0;
// }
// }
//FBIP 2R
//implement in-place approach
//store zero states in every first row and first column
//and get states in top-down way and set matrix in buttom-up way
int m = matrix.length, n = matrix[0].length;
int col0 = 1; //since row0 and col0 has the same cell so need a variable to store zero info for column 0
for (int i = 0; i < m; i++){
if (matrix[i][0] == 0) col0 = 0;
for (int j = 1; j < n; j++){ //skip the 0 col since that info store in col0
if (matrix[i][j] == 0){
matrix[i][0] = 0;
matrix[0][j] = 0;
}
}
}
for (int i = m - 1; i >= 0; i--){
for (int j = n - 1; j > 0; j--) //skip the 0 col since that info store in col0
if (matrix[i][0] == 0 || matrix[0][j] == 0)
matrix[i][j] = 0;
if (col0 == 0) matrix[i][0] = 0;
}
}
} | EdwardHXu/FBIP-LC | 73.java |
911 | public class Cat {
/**
* Indicates whether or not the cat is rented.
*/
boolean _rented = false;
/**
* ID of the cat
* By default, -1
*/
int _id = -1;
/**
* Name of the cat
*/
String _name;
/**
* Constructor - creates a new Cat object
* Note there are no checks that this ID is not taken by another
* cat! This is probably something that we would fix in a production
* system.
* @param int id - the id number of this cat
* @param String name - the name of this Cat
*/
public Cat(int id, String name) {
_rented = false;
_id = id;
_name = name;
}
/**
* Rent cat. Simply sets the _rented flag to true.
*/
public void rentCat() {
_rented = true;
}
/**
* Return cat. Simply sets the _rented flag to false.
*/
public void returnCat() {
_rented = false;
}
/**
* Accessor for _name variable. Returns the name of this cat.
* @return String name of cat
*/
public String getName() {
return _name;
}
/**
* Accessor for _id variable. Returns the ID of this cat.
* @return int ID of this cat
*/
public int getId() {
return _id;
}
/**
* Accessor for _rented variable. Returns if cat is rented.
* @return boolean - true if rented, false otherwise
*/
public boolean getRented() {
return _rented;
}
/**
* Returns string version of this cat, in form: "ID *id_num*. *name*"
* Example for cat of ID 1, name Jennyanydots: "ID 1. Jennyanydots"
* @return String string version of cat
*/
public String toString() {
return "ID " + _id + ". " + _name;
}
}
| laboon/CS1632_Fall2017 | exercises/3/Cat.java |
912 | // KicadModuleToGEDA - a utility for turning kicad modules to gEDA PCB footprints
// BXLDecoder.java - a utility for converting Huffman encoded files
// Pad.java v1.1
// Copyright (C) 2015 Erich S. Heinzle, [email protected]
// see LICENSE-gpl-v2.txt for software license
// see README.txt
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// KicadModuleToGEDA Copyright (C) 2015 Erich S. Heinzle [email protected]
/**
*
* This class is used to store and process a pad/pin definition string from a Kicad footprint
* allowing it then generate a gEDA PCB compatible footprint
* Oblong hole definitions are processed sensibly, to produce a pair of joined pins, but
* slots implemented this way as a pair of pins with joining pads on both sides of the board
* require gerbers to be post-processed with a G85 directive to join the pins to make a slot
*
*/
import java.util.Scanner;
public class Pad extends FootprintElementArchetype
{
String kicadShapePadName = "not defined";
String kicadShapeNetName = "not defined yet";
long kicadShapeXsizeNm = 0;
long kicadShapeYsizeNm = 0;
long kicadShapeXdeltaNm = 0; // this is used to define trapezoidal pads
// -ve xDelta = decrease in left edge length vs right
// +ve xDelta = increase in right edge length vs left
long kicadShapeYdeltaNm = 0; // this is used to define trapezoidal pads
// -ve yDelta = decrease in top edge length vs bottom
// +ve yDelta = increase in bottom edge length vs top
// Note: one or both of xDelta, yDelta, must be zero
long kicadShapeOrientation = 0; // this is specified in decidegrees by kicad
char kicadDrillShape = '0';
long kicadDrillOneSizeNm = 0;
long kicadDrillOneXoffsetNm = 0;
long kicadDrillOneYoffsetNm = 0;
char kicadDrillShapeTwo = '0' ;
long kicadDrillSlotWidthNm = 0;
long kicadDrillSlotHeightNm = 0;
long kicadPadPositionXNm = 0;
long kicadPadPositionYNm = 0;
String kicadPadAttributeType = "null";
long gEDAdefaultMetalClearance = 20; // NB defined here in thousandths of an inch = mils
// (clearance/2) = minimum distance from pad/pin metal
// to nearest copper
// this gets multiplied by 100 for 0.01 mil units in output
long gEDAdefaultSolderMaskRelief = 8; // NB defined here in thousandths of an inch = mils
// solder mask relief
// = ((thickness of mask aperture) - (pad or pin thickness))
// this gets multiplied by 100 for 0.01 mil units in output
long gEDAdefaultMinimumDrillSizeNm = 0; // 300000 is big enough to be vaguely sane for vias
// this can be imposed when creating the module by passing
// a minimum drill/via size to the setter/constructor
String topLayerPad = ""; // we use these temporary variables when building slots
String bottomLayerPad = ""; // and obroid pads
Boolean equilateralPad = true; // also used when processing obroid, round and circular pads
// Pins and SMD pads have been converted from Kicad foot prints which do not have solder
// mask relief or clearances specified. Default values used for solder mask relief and
// clearance are as specified above.
//
// Users of the foot print must ensure that the solder mask reliefs and clearances are
// compatible with the PCB manufacturer's process tolerances
String gEDAflag = "blah"; // hex values now deprecated i.e. "0x0000"
public Pad() // the default constructor simply creates a simple default pad for testing
{
kicadShapePadName = "1";
kicadShapeNetName = "GND";
kicadShapeXsizeNm = 800*2540;
kicadShapeYsizeNm = 800*2540;
kicadShapeXdeltaNm = 0;
kicadShapeYdeltaNm = 0;
kicadShapeOrientation = 0;
kicadDrillShape = 'C';
kicadDrillOneSizeNm = 600;
kicadDrillOneXoffsetNm = 0;
kicadDrillOneYoffsetNm = 0;
kicadDrillShapeTwo = 'C';
kicadDrillSlotWidthNm = 0;
kicadDrillSlotHeightNm = 0;
kicadPadPositionXNm = 1000*2540;
kicadPadPositionYNm = 1000*2540;
kicadPadAttributeType = "STD";
}
public void populateElement(String arg, boolean metric, long minimumViaAndDrillSizeNM)
{
gEDAdefaultMinimumDrillSizeNm = minimumViaAndDrillSizeNM;
String parseString = "";
String[] tokens;
// System.out.println("Constructor has been passed:" + arg);
float parsedValue = 0;
Scanner padDefinition = new Scanner(arg);
// the while statement takes care of legacy pad definitions
// will need to fork here with an if, either legacy or s-file
// since s-file fits almost all of it on one line
while (padDefinition.hasNextLine())
{
// System.out.println("Now in while loop, processing: " + parseString);
parseString = padDefinition.nextLine();
tokens = parseString.split(" ");
if (tokens[0].startsWith("Sh"))
{
kicadShapePadName = tokens[1];
// we get rid of odd characters that may interfere with pad naming:
kicadShapePadName =
kicadShapePadName.replaceAll("[^a-zA-Z0-9.-]", "_");
kicadDrillShape = tokens[2].charAt(0);
// System.out.println("Drillshape: " + drillShape);
parsedValue = Float.parseFloat(tokens[3]);
kicadShapeXsizeNm =
convertToNanometres(parsedValue, metric);
parsedValue = Float.parseFloat(tokens[4]);
kicadShapeYsizeNm =
convertToNanometres(parsedValue, metric);
// System.out.println(shapeXsize + " " + shapeYsize);
parsedValue = Float.parseFloat(tokens[5]);
kicadShapeXdeltaNm =
convertToNanometres(parsedValue, metric);
parsedValue = Float.parseFloat(tokens[6]);
kicadShapeYdeltaNm =
convertToNanometres(parsedValue, metric);
kicadShapeOrientation = Integer.parseInt(tokens[7]);
// this is the rotation of the pad in decidegrees
// we need orientation to process obround pads
}
if (tokens[0].startsWith("Po"))
{
parsedValue = Float.parseFloat(tokens[1]);
kicadPadPositionXNm =
convertToNanometres(parsedValue, metric);
// System.out.println(padPositionX);
parsedValue = Float.parseFloat(tokens[2]);
kicadPadPositionYNm =
convertToNanometres(parsedValue, metric);
// System.out.println(padPositionY);
}
if (tokens[0].startsWith("Ne"))
{
kicadShapeNetName = tokens[1];
// we now need to cleanse the NetName of nasties like '$' which sometimes occur
kicadShapeNetName =
kicadShapeNetName.replaceAll("[^a-zA-Z0-9.-]", "_");
// System.out.println("Shape's Net name: " + shapeNetName);
}
if (tokens[0].startsWith("At"))
{
kicadPadAttributeType = tokens[1];
// System.out.println("Pad attribute type: " + padAttributeType);
}
if (tokens[0].startsWith("Dr"))
{
parsedValue = Float.parseFloat(tokens[1]);
kicadDrillOneSizeNm =
convertToNanometres(parsedValue, metric);
// System.out.println("Drill size: " + drillOneSize);
// we can capture drill x and y offset, but it may not be useful
parsedValue = Float.parseFloat(tokens[2]);
kicadDrillOneXoffsetNm =
convertToNanometres(parsedValue, metric);
parsedValue = Float.parseFloat(tokens[3]);
kicadDrillOneYoffsetNm =
convertToNanometres(parsedValue, metric);
// System.out.println("First hole X and Y offsets: " +
// drillOneXoffset + " " + drillOneYoffset);
// and now we figure out if there is a second hole defined, i.e. slot
if (tokens.length > 5)
{
// System.out.print("hey, there's a second hole");
// System.out.print(" and it is defined as ");
kicadDrillShapeTwo = tokens[4].charAt(0);
// System.out.println(drillShapeTwo);
parsedValue = Float.parseFloat(tokens[5]);
kicadDrillSlotWidthNm =
convertToNanometres(parsedValue, metric);
parsedValue = Float.parseFloat(tokens[6]);
kicadDrillSlotHeightNm =
convertToNanometres(parsedValue, metric);
// System.out.println("DrillTwoX and DrillTwoY are: " + drillTwoX + " " + drillTwoY);
}
else // this captures scenarios where the pad is repopulated
{ // with a pin rather than a slot
kicadDrillShapeTwo = '0';
}
}
if (parseString.startsWith("pad")) // we move onto dedicated s-file parsing
{
metric = true;
// System.out.println("Parsing s-file pad description");
// while (padDefinition.hasNextLine())
// {
// parseString = parseString + " " + padDefinition.nextLine();
// }
tokens = parseString.split(" ");
// for (int counter = 0; counter < tokens.length; counter++)
// {
// System.out.println("Pad token #: " + counter + " : " + tokens[counter]);
// }
// we first grab the pad name
kicadShapePadName =
tokens[1].replaceAll("[^a-zA-Z0-9.-]", "_");
// and rid the Pad Name of nasties like '$' which sometimes occur
// next we glean the type of pad
if (tokens[2].startsWith("thru_hole"))
{
kicadPadAttributeType = "STD";
}
else if (tokens[2].startsWith("smd"))
{
kicadPadAttributeType = "SMD";
}
else if (tokens[2].startsWith("connect"))
{
kicadPadAttributeType = "CONN";
}
else if (tokens[2].startsWith("np_thru"))
{
kicadPadAttributeType = "HOLE";
}
// next comes the shape of the pad or hole
if (tokens[3].startsWith("circle"))
{
kicadDrillShape = 'C';
}
else if (tokens[3].startsWith("rect"))
{
kicadDrillShape = 'R';
}
else if (tokens[3].startsWith("oval"))
{
kicadDrillShape = 'O';
}
else if (tokens[3].startsWith("trapezoid"))
{
kicadDrillShape = 'T';
}
// now we parse the less predictable remaining attributes
for (int parseIndex = 4; parseIndex < tokens.length; parseIndex++)
{
if (tokens[parseIndex].startsWith("at"))
{
parseIndex++;
parsedValue = Float.parseFloat(tokens[parseIndex]);
kicadPadPositionXNm =
convertToNanometres(parsedValue, metric);
// System.out.println(padPositionX);
parseIndex++;
parsedValue = Float.parseFloat(tokens[parseIndex]);
kicadPadPositionYNm =
convertToNanometres(parsedValue, metric);
// System.out.println(padPositionY);
kicadShapeOrientation = 0; // set a default value
// we now look to see if orientation is specified
if (!tokens[parseIndex + 1].startsWith("size"))
{
// them tricksy kicadians went and changed
// from decidegrees to degrees in the s-file
// format without telling anyone....
// hence the multiplication by 10......
kicadShapeOrientation =
10*Integer.parseInt(tokens[parseIndex+1]);
parseIndex++;
}
}
else if (tokens[parseIndex].startsWith("size"))
{
parseIndex++;
parsedValue = Float.parseFloat(tokens[parseIndex]);
kicadShapeXsizeNm =
convertToNanometres(parsedValue, metric);
parseIndex++;
parsedValue = Float.parseFloat(tokens[parseIndex]);
kicadShapeYsizeNm =
convertToNanometres(parsedValue, metric);
}
else if (tokens[parseIndex].startsWith("rect_delta"))
{
parseIndex++;
parsedValue = Float.parseFloat(tokens[parseIndex]);
kicadShapeXdeltaNm =
convertToNanometres(parsedValue, metric);
parseIndex++;
parsedValue = Float.parseFloat(tokens[parseIndex]);
kicadShapeYdeltaNm =
convertToNanometres(parsedValue, metric);
}
else if (tokens[parseIndex].startsWith("drill"))
{
parseIndex++;
// we look to see if it is an oval hole
if (tokens[parseIndex].startsWith("o"))
{
kicadDrillShapeTwo = 'O';
parseIndex++;
parsedValue =
Float.parseFloat(tokens[parseIndex]);
kicadDrillSlotWidthNm =
convertToNanometres(parsedValue, metric);
parseIndex++;
parsedValue =
Float.parseFloat(tokens[parseIndex]);
kicadDrillSlotHeightNm =
convertToNanometres(parsedValue, metric);
}
else // it isn't an oval hole
{
parsedValue =
Float.parseFloat(tokens[parseIndex]);
kicadDrillOneSizeNm =
convertToNanometres(parsedValue, metric);
kicadDrillShapeTwo = '0';// flag lack of hole 2
}
// we now look for x,y offset of hole, if specified
if ((parseIndex < (tokens.length - 2)) &&
tokens[parseIndex + 1].startsWith("offset"))
{
parseIndex++; // we step past "offset"
parseIndex++; // and get to offsetX
parsedValue =
Float.parseFloat(tokens[parseIndex]);
kicadDrillOneXoffsetNm =
convertToNanometres(parsedValue, metric);
parseIndex++; // and then onto offsetY
parsedValue =
Float.parseFloat(tokens[parseIndex]);
kicadDrillOneYoffsetNm =
convertToNanometres(parsedValue, metric);
}
}
else if (tokens[parseIndex].startsWith("net"))
{
parseIndex++;
// we will skip the net number
parseIndex++;
kicadShapeNetName = tokens[parseIndex];
// we now need to cleanse the NetName of
// nasties like '$' which sometimes occur
kicadShapeNetName = kicadShapeNetName.replaceAll("[^a-zA-Z0-9.-]", "_");
}
}
}
}
// System.out.println("finished populating pad object");
}
// here, we populate the pad object with data
// extracted from a BXL file
// noting that y-coords are inverted relative
// to gEDA and kicad
// may need to think about effect on rotation
public void populateBXLElement(long w,
long h,
long x,
long y,
char shape,
long rot,
long holeDiam,
String attr,
String pinNum,
String pinName) {
kicadShapeXsizeNm = w;
kicadShapeYsizeNm = h;
kicadPadPositionXNm = x;
kicadPadPositionYNm = -y;
kicadDrillShape = shape;
kicadShapeOrientation = rot;
kicadDrillOneSizeNm = holeDiam;
kicadPadAttributeType = attr;
kicadShapePadName = pinNum;
kicadShapeNetName = pinName;
// for now, we do not worry ourselves with slots, so...
kicadDrillShapeTwo = '0';
}
public String generateGEDAelement(long xOffsetNm, long yOffsetNm, float magnificationRatio)
// offsets supplied in Nm, magnificationRatio supplied as float, not used as of yet
{
// System.out.println("about to generate a gEDA pad element");
String output = "For some reason, the pad object was not populated by the constructor";
/**
* the first task is to establish if the pad is a pin, pad, hole or square
* octogons are not supported in kicad
*/
String oblongSlotFlag = ""; // the default setting of rounded ends for a slot = ""
// we now check to see if we have had a minimum drill and via size imposed
// by the Footprint that constructed this pad
// Note: could have a distinct method to change this, would be useful
if (kicadDrillOneSizeNm != 0)
{
if (kicadDrillOneSizeNm < gEDAdefaultMinimumDrillSizeNm)
{
kicadDrillOneSizeNm = gEDAdefaultMinimumDrillSizeNm;
}
}
// one of the first things to do is to establish if
// the pad is a boring round or square pad, as this will
// affect our processing of rectangular and obroid pads
// but before we even do this, we have to catch an annoying deviation
// from the file format, namely, when the pad shape is given as 'R'
// and a kicadShapeX size is given but the given kicadShapeY is zero
// presumably kicad automagically assumes it is square
// this is an unusual problem, and is probably the result of an
// eagle-kicad conversion tool quirk
if (kicadShapeYsizeNm == 0)
{
kicadShapeYsizeNm = kicadShapeXsizeNm;
} // with that out of the way, we can now decide if the pad is "equilateral"
if (kicadShapeXsizeNm != kicadShapeYsizeNm)
{
equilateralPad = false;
}
else
{
equilateralPad = true;
}
switch (kicadDrillShape)
{
case 'O': // an obround pad shape can be done as a circle for now
// probably will need to implement as a pin + a pad on
// top layer plus, on the bottom "onsolder" layer
// plus take care of the orientation stuff too
// when determining stop, start of pad direction
// which might make the centre pin round or square, too
// .......but obround pins are a little rare, though
case 'C': if (kicadPadAttributeType.startsWith("STD")) // = plate through
{
gEDAflag = ""; // WAS "pin"; // "0x0001" now deprecated
}
else if (kicadPadAttributeType.startsWith("HOLE")) // = NPTH, round
{
gEDAflag = "hole"; // "0x0008" now deprecated
}
break;
case 'R': if (kicadPadAttributeType.startsWith("STD")) // = plate through
{
if (equilateralPad) // it is square, let it be square
{
gEDAflag = "square"; // "0x0100" now deprecated
}
else
{
gEDAflag = ""; // make obroid pad pins rounded
}
// i.e. we don't want "square" set for square ended obroid pads
oblongSlotFlag = "square";
}
else if (kicadPadAttributeType.startsWith("HOLE"))
{
gEDAflag = "hole"; // "0x0008" now deprecated
}
else if (kicadPadAttributeType.startsWith("SMD") ||
kicadPadAttributeType.startsWith("CONN"))
{
gEDAflag = "square"; // "0x0000" now deprecated
}
break;
/**
*
* additional pad "shape" options in, for example, 'Sh "2" C 1500 1500 0 0 2700' definition
* include 'O' = oblong, 'T' = trapeze
*
* this is to be distinguished from from "drillshape" options, such as 'Dr 600 0 0 O 600 650
* which can be used to specify an oblong 'O' hole which seems to be a slot
*
*/
default: gEDAflag = "blah";
break;
}
// further refinements would include the addition of a track to make more complicated
// non square or non round pads, with onsolder and top layer elements
// here we implement rudimentary support for pad orientation
// we do this by noting that orientations of 900 or 2700 can be achieved
// by exchanging the value of kicadShapeXsizeNm and kicadShapeYsizeNm
// which will work for simple pads with only one, centred hole
// for this to work for pads with more than one hole, slot widths and heights
// will need to be translated as well
while (kicadShapeOrientation < 0) // we aim to produce 0 =< orientation values =< 3599
{
kicadShapeOrientation = 3600 + kicadShapeOrientation;
}
if (((kicadShapeOrientation >= 450) &&
(kicadShapeOrientation <= 1350)) ||
((kicadShapeOrientation >= 2250) &&
(kicadShapeOrientation <= 3150)))
{
long tempVal = kicadShapeXsizeNm;
kicadShapeXsizeNm = kicadShapeYsizeNm;
kicadShapeYsizeNm = tempVal;
}
// simple support for rotation has been effected with a range of orientation values,
// quantised into either horizontal of vertical
// To support it more rigorously again, a rotation matrix would be needed
// This rudimentary effort could break obround slots which rely on x and y offsets for the slot
// in the form of slot height and width values, so we can test for those.
// also, drill offsets in x and y would need translation
/**
*
* the simplest scenario of all is an SMD pad or edge connector and we deal with this first
* // ? have reworked the dimensions in the copied and pasted code for pins, ok so far
*
* also, the problem of pins defined with zero hole size are caught here and treated as a pad
*/
if ((kicadPadAttributeType.startsWith("SMD") ||
kicadPadAttributeType.startsWith("CONN")) ||
(kicadPadAttributeType.startsWith("STD") &&
(kicadDrillOneSizeNm == 0)))
{
// scenario with wider SMD pad than tall, which determines which dimension is used for thickness
// i.e. shapeYsize is equivalent to gEDA's "thickness" attribute for a pad
if (kicadShapeXsizeNm >= kicadShapeYsizeNm)
{
output = "Pad[" +
((xOffsetNm + kicadPadPositionXNm -
kicadShapeXsizeNm/2 + kicadShapeYsizeNm/2)/254)
+ " " +
((yOffsetNm + kicadPadPositionYNm)/254)
+ " " +
((xOffsetNm + kicadPadPositionXNm +
kicadShapeXsizeNm/2 - kicadShapeYsizeNm/2)/254)
+ " " +
((yOffsetNm + kicadPadPositionYNm)/254)
+ " " +
(kicadShapeYsizeNm/254) + " " +
(100*gEDAdefaultMetalClearance) + " " +
(100*gEDAdefaultSolderMaskRelief +
(kicadShapeYsizeNm/254)) + " " +
'"' + kicadShapeNetName + "\" " +
'"' + kicadShapePadName + "\" " +
'"' +
gEDAflag + // flag useful, square vs rounded ends of SMD pad
'"' + "]\n";
}
// scenario with taller SMD pad than wide, which determines which dimension is used for thickness
// i.e. shapeXsize is equivalent to gEDA's "thickness" attribute for a pad
else
{
output = "Pad[" +
((xOffsetNm + kicadPadPositionXNm)/254) + " " +
((yOffsetNm + kicadPadPositionYNm - kicadShapeYsizeNm/2 + kicadShapeXsizeNm/2)/254) + " " +
((xOffsetNm + kicadPadPositionXNm)/254) + " " +
((yOffsetNm + kicadPadPositionYNm + kicadShapeYsizeNm/2 - kicadShapeXsizeNm/2)/254) + " " +
(kicadShapeXsizeNm/254) + " " +
(100*gEDAdefaultMetalClearance) + " " +
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
'"' + kicadShapeNetName + "\" " +
'"' + kicadShapePadName + "\" " +
'"' +
gEDAflag + // sets rounded or square pad
'"' + "]\n";
}
}
/**
*
* the next simplest scenario captures a pin = "HOLE", with no additional hole, so, not an unplated
* slot, and not a plated hole pin = "STD"
*
*/
else if (kicadPadAttributeType.startsWith("HOLE") && (kicadDrillShapeTwo == '0'))
{
output = "Pin[" + // square bracket indicates 1/100 mil resolution
((kicadPadPositionXNm + xOffsetNm)/254) + " " +
((kicadPadPositionYNm + yOffsetNm)/254) + " " +
(kicadShapeXsizeNm/254) + " " + // pin outer diam., if round = shapeXsize = shapeYsize
(100*gEDAdefaultMetalClearance) + " " + // gEDA: clearance is specified per pad/pin
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
(kicadDrillOneSizeNm/254) + " " + // drill hole size in 0.01mil units
'"' + kicadShapeNetName + "\" " + // arbitrary label for pin
'"' + kicadShapePadName + "\" " + // pin number for attaching nets
'"' + gEDAflag + '"' + "]\n"; // gEDAflag has already been set to "hole"
}
/**
*
* the next simplest scenario captures a standard pin = "STD" with no additional hole, so, not a slot
* and also is an equilateralPad = true, so not oblong,
* and it is a plated hole rather than a mechanical "HOLE"
* This also captures kicadDrillShape = 'T' for trapezoidal pad shapes, which could be dealt with
* in another bit of code if support is desirable
*
*/
else if (kicadPadAttributeType.startsWith("STD") && (kicadDrillShapeTwo == '0') && (equilateralPad)) // was: && kicadDrillShape != 'O'))
{
output = "Pin[" + // square bracket indicates 1/100 mil resolution
((kicadPadPositionXNm + xOffsetNm)/254) + " " +
((kicadPadPositionYNm + yOffsetNm)/254) + " " +
(kicadShapeXsizeNm/254) + " " + // pin outer diam., if round = shapeXsize = shapeYsize
(100*gEDAdefaultMetalClearance) + " " + // gEDA: clearance is specified per pad/pin
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
(kicadDrillOneSizeNm/254) + " " + // drill hole size in 0.01mil units
'"' + kicadShapeNetName + "\" " + // arbitrary label for pin
'"' + kicadShapePadName + "\" " + // pin number for attaching nets
'"' + gEDAflag + '"' + "]\n"; // square bracket indicates 1/100 mil resolution
}
/**
*
* the next simplest scenario captures a standard pin = "STD" with no additional hole, so, not a slot,
* but kicadDrillShape = 'O', 'T' or 'R' and not an equilateral pad, making it an obroid pad,
* and it is a plated hole rather than a mechanical "HOLE"
*
* - we also need to consider orientation of the pad in due course with rotational
* translation of the pad
* - in the first instance, rotation of 900 or 2700 decigrees can be supported by applying
* horizontal pad processing for vertical pads, and vice versa
*
* we need to process kicadDrillShape = 'R' or 'O' or 'T' and at the same time !equilateralPad"
*
* The code produces a standard "STD" plate through hole, round, pin, with the addition
* of a suitable pad on the top and on the bottom (="onsolder") layers of necessary dimensions
*
*
* There is also the problem of some modules specifiying shape 'R' pads with arbitrary X size
* but zero Y size, presumably KiCad defaults to a sqaure pad in these cases - We tested for this
* prior and let y size = x size if y size = 0
*
*/
else if (kicadPadAttributeType.startsWith("STD") && (kicadDrillShapeTwo == '0') && (!equilateralPad) )
{
// if (kicadShapeYsizeNm == 0)
// {
// kicadShapeYsizeNm = kicadShapeXsizeNm;
// }// this could perhaps be done during parsing in case other scenarios exist
if (kicadShapeXsizeNm >= kicadShapeYsizeNm) // we have a horizontal obroid pad
{
output = "Pin[" + // square bracket indicates 1/100 mil resolution
((kicadPadPositionXNm + xOffsetNm)/254) + " " +
((kicadPadPositionYNm + yOffsetNm)/254) + " " +
(kicadShapeYsizeNm/254) + " " +
// pin outer diam., if horizontal obroad pad = shapeYsize
(100*gEDAdefaultMetalClearance) + " " +
// gEDA: clearance is specified per pad/pin
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
(kicadDrillOneSizeNm/254) + " " + // drill hole size in 0.01mil units
'"' + kicadShapeNetName + "\" " + // arbitrary label for pin
'"' + kicadShapePadName + "\" " + // pin number for attaching nets
'"' + gEDAflag + '"' + "]\n";
// square bracket indicates 1/100 mil resolution
// rotational transformation could maybe be applied here for
// kicadPadPositionXNm and kicadPadPositionYNm
topLayerPad = "Pad[" +
((xOffsetNm + kicadPadPositionXNm - kicadShapeXsizeNm/2 + (kicadShapeYsizeNm)/2)/254) + " " + // drillTwoY is the slot height
((yOffsetNm + kicadPadPositionYNm)/254) + " " +
((xOffsetNm + kicadPadPositionXNm + kicadShapeXsizeNm/2 - (kicadShapeYsizeNm)/2)/254) + // drillTwoY is the slot height
// it seems that oblong slot's drillTwoX and drillTwoY are absolute slot dimensions
// not delta x,y vs first hole
" " +
((yOffsetNm + kicadPadPositionYNm)/254) + " " +
(kicadShapeYsizeNm/254) + " " +
(100*gEDAdefaultMetalClearance) + " " +
(100*gEDAdefaultSolderMaskRelief + (kicadShapeYsizeNm/254)) + " " +
'"' + kicadShapeNetName + "\" " +
'"' + kicadShapePadName + "\" " +
'"' +
oblongSlotFlag;
bottomLayerPad = topLayerPad + ",onsolder";
output = output + topLayerPad + "\"]\n" + bottomLayerPad + "\"]\n";
}
else if (kicadShapeXsizeNm < kicadShapeYsizeNm) // a vertical obroid pad
{
output = "Pin[" + // square bracket indicates 1/100 mil resolution
((kicadPadPositionXNm + xOffsetNm)/254) + " " +
((kicadPadPositionYNm + yOffsetNm)/254) + " " +
(kicadShapeXsizeNm/254) + " " +
// pin outer diam., if vertical obroid pad = shapeXsize
(100*gEDAdefaultMetalClearance) + " " +
// gEDA: clearance is specified per pad/pin
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
(kicadDrillOneSizeNm/254) + " " + // drill hole size in 0.01mil units
'"' + kicadShapeNetName + "\" " + // arbitrary label for pin
'"' + kicadShapePadName + "\" " + // pin number for attaching nets
'"' + gEDAflag + '"' + "]\n";
// square bracket indicates 1/100 mil resolution
// rotational transformation could maybe be applied here for
// kicadPadPositionXNm and kicadPadPositionYNm
topLayerPad = "Pad[" +
((xOffsetNm + kicadPadPositionXNm)/254) + " " +
((yOffsetNm + kicadPadPositionYNm - kicadShapeYsizeNm/2 + (kicadShapeXsizeNm)/2)/254) + " " +
((xOffsetNm + kicadPadPositionXNm)/254) + " " +
((yOffsetNm + kicadPadPositionYNm + kicadShapeYsizeNm/2 - (kicadShapeXsizeNm)/2)/254) +
" " +
(kicadShapeXsizeNm/254) + " " +
(100*gEDAdefaultMetalClearance) + " " +
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
'"' + kicadShapeNetName + "\" " +
'"' + kicadShapePadName + "\" " +
'"' +
oblongSlotFlag;
bottomLayerPad = topLayerPad + ",onsolder";
output = output + topLayerPad + "\"]\n" + bottomLayerPad + "\"]\n";
}
}
/**
*
* the next section deals with oblong pins which are "STD" and drillShapeTwo = oblong "O"
* by generating two pins the appropriate distance apart
*
* we really want the pins to be rounded, not square, if the drill offsets are
* on a diagonal, and we first test to see if the oblong hole is on a diagonal
*
* we then join the two pins with a pad of the right length and with rounded ends
*
*/
else if (kicadPadAttributeType.startsWith("STD") && (kicadDrillShapeTwo == 'O')) // not zero, but "O" for "Obround" or oval, and a slot
{
if (((kicadDrillSlotWidthNm - kicadDrillOneXoffsetNm) != 0) && ((kicadDrillSlotHeightNm - kicadDrillOneYoffsetNm) != 0)) // we capture (hmm, not diagonal, if slot not rotated) slots here
{
oblongSlotFlag = ""; // and make the slot ends rounded != "square"
// i'm starting to think this only rounds off the ends for all slots
}
// next, we require an if statement to fork for the vertical or horizontal slot cases
if (kicadShapeXsizeNm >= kicadShapeYsizeNm) // horizontal slot
{
output = "Pin[" + // square bracket indicates 1/100 mil resolution
((kicadPadPositionXNm + kicadDrillOneXoffsetNm - kicadDrillSlotWidthNm/2 + xOffsetNm + kicadDrillOneYoffsetNm/2)/254) + " " +
((kicadPadPositionYNm + kicadDrillOneYoffsetNm - yOffsetNm)/254) +
" " +
(kicadShapeYsizeNm/254) + " " + // pin outer diam., slot pad height = shapeYsize
(100*gEDAdefaultMetalClearance) + " " + // gEDA: clearance specified per pad/pin
(100*gEDAdefaultSolderMaskRelief + (kicadShapeYsizeNm/254)) + " " +
(kicadDrillSlotHeightNm/254) + " " + // drill two Y size = slot height
'"' + kicadShapeNetName + "\" " + // arbitrary label for pin
'"' + kicadShapePadName + "\" " + // pin number for attaching nets
'"' +
oblongSlotFlag + // gEDAflag +
'"' + "]\n" + // square bracket indicates 1/100 ml resolution
"Pin[" +
((kicadPadPositionXNm + kicadDrillOneXoffsetNm + xOffsetNm + kicadDrillSlotWidthNm/2 - kicadDrillOneXoffsetNm/2)/254) + " " +
((kicadPadPositionYNm + kicadDrillOneYoffsetNm + yOffsetNm)/254) +
" " +
(kicadShapeYsizeNm/254) + " " + // pin outer diameter
(100*gEDAdefaultMetalClearance) + " " +
(100*gEDAdefaultSolderMaskRelief + (kicadShapeYsizeNm/254)) + " " +
(kicadDrillSlotHeightNm/254) + " " + // drill two Y equals slot height
'"' + kicadShapeNetName + "\" " +
'"' + kicadShapePadName + "\" " +
'"' +
oblongSlotFlag + // gEDAflag +
'"' + "]\n";
}
else if (kicadShapeYsizeNm > kicadShapeXsizeNm) // vertical slot
{
output = "Pin[" + // square bracket indicates 1/100 mil resolution
((kicadPadPositionXNm + kicadDrillOneXoffsetNm + xOffsetNm)/254) + " " +
((kicadPadPositionYNm + kicadDrillOneYoffsetNm - kicadDrillSlotHeightNm/2 + yOffsetNm + kicadDrillOneXoffsetNm/2)/254) + " " +
(kicadShapeXsizeNm/254) + " " + // pin outer diam., if round = shapeXsize = slot pad width
(100*gEDAdefaultMetalClearance) + " " + // gEDA: clearance specified per pad/pin
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
(kicadDrillSlotWidthNm/254) + " " + // drill one hole size
'"' + kicadShapeNetName + "\" " + // arbitrary label for pin
'"' + kicadShapePadName + "\" " + // pin number for attaching nets
'"' +
oblongSlotFlag + // gEDAflag +
'"' + "]\n" + // square bracket indicates 1/100 ml resolution
"Pin[" +
((kicadPadPositionXNm + kicadDrillOneXoffsetNm + xOffsetNm)/254) + " " +
((kicadPadPositionYNm + kicadDrillOneYoffsetNm + yOffsetNm + kicadDrillSlotHeightNm/2- kicadDrillOneXoffsetNm/2)/254) + " " +
(kicadShapeXsizeNm/254) + " " + // pin outer diameter
(100*gEDAdefaultMetalClearance) + " " +
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
(kicadDrillSlotWidthNm/254) + " " +
'"' + kicadShapeNetName + "\" " +
'"' + kicadShapePadName + "\" " +
'"' +
oblongSlotFlag + // gEDAflag +
'"' + "]\n";
}
/**
*
* If we are to join two holes with a pad, the pad will need rounded ends, and a thickness
* that increases in proportion to the sine of the angle/2, so for now we will simply
* skip the gEDAflag that would probably be "square", and use the oblongSlotFlag instead
* to keep the ends round - it is simpler this way.
*
*/
/**
*
* the first case addresses the scenario of a horizontally aligned, rectangular pad
* or square with two holes making a slot
*
*/
if (kicadShapeXsizeNm >= kicadShapeYsizeNm) // i.e. horizontal slot
{
topLayerPad = "Pad[" +
((xOffsetNm + kicadDrillOneXoffsetNm + kicadPadPositionXNm - kicadShapeXsizeNm/2 + (kicadShapeYsizeNm - kicadDrillSlotHeightNm)/2)/254) + " " + // drillTwoY is the slot height
((yOffsetNm + kicadDrillOneYoffsetNm + kicadPadPositionYNm)/254) + " " +
((xOffsetNm + kicadDrillOneXoffsetNm + kicadPadPositionXNm + kicadShapeXsizeNm/2 - (kicadShapeYsizeNm - kicadDrillSlotHeightNm)/2)/254) + // drillTwoY is the slot height
// it seems that oblong slot's drillTwoX and drillTwoY are absolute slot dimensions
// not delta x,y vs first hole
" " +
((yOffsetNm + kicadDrillOneYoffsetNm + kicadPadPositionYNm)/254) + " " +
(kicadShapeYsizeNm/254) + " " +
(100*gEDAdefaultMetalClearance) + " " +
(100*gEDAdefaultSolderMaskRelief + (kicadShapeYsizeNm/254)) + " " +
'"' + kicadShapeNetName + "\" " +
'"' + kicadShapePadName + "\" " +
'"' +
oblongSlotFlag;
bottomLayerPad = topLayerPad + ",onsolder";
output = output + topLayerPad + "\"]\n" + bottomLayerPad + "\"]\n";
}
/**
*
* versus the remaining alternative of a vertically aligned rectangular pad with a hole
* at each end to make a slot - as of yet nothing done for non orthogonal rectangular or
* square slot pads, it has been implemented with round pads for diagonal slots
*
*/
else // vertical slot
{
topLayerPad = "Pad[" +
((xOffsetNm + kicadPadPositionXNm + kicadDrillOneXoffsetNm)/254) + " " +
((yOffsetNm + kicadPadPositionYNm + kicadDrillOneYoffsetNm - kicadShapeYsizeNm/2 + (kicadShapeXsizeNm - kicadDrillSlotWidthNm)/2)/254) + " " +
((xOffsetNm + kicadPadPositionXNm + kicadDrillOneXoffsetNm)/254) + " " +
((yOffsetNm + kicadPadPositionYNm + kicadDrillOneYoffsetNm + kicadShapeYsizeNm/2 - (kicadShapeXsizeNm - kicadDrillSlotWidthNm)/2)/254) +
" " +
(kicadShapeXsizeNm/254) + " " +
(100*gEDAdefaultMetalClearance) + " " +
(100*gEDAdefaultSolderMaskRelief + (kicadShapeXsizeNm/254)) + " " +
'"' + kicadShapeNetName + "\" " +
'"' + kicadShapePadName + "\" " +
'"' +
oblongSlotFlag;
bottomLayerPad = topLayerPad + ",onsolder";
output = output + topLayerPad + "\"]\n" + bottomLayerPad + "\"]\n";
}
/**
*
* having assembled a slotted oblong pair of pins with a pad between them
* we return the string containing the gEDA compatible definition
*
*/
}
return output;
}
private long convertToNanometres(float rawValue, Boolean metricSystem)
{
if (metricSystem)
{
return (long)(rawValue * 1000000); // 1,000,000 nm per mm
}
else
{
return (long)(rawValue * 2540); // 2540 nm per 0.1 mil
}
}
}
| erichVK5/BXL2text | src/Pad.java |
913 | //David Nguyen - The class Bid represents a bid that a contractor makes for a contract//
public class Bid{
//The contract field represents the contract name for the bid
Contract contract;
//The contractor field represents the contractor's name
Contractor contractor;
//The value field represents the value of the bid
Double value;
//A constructor that creates a bid//
public Bid (Contract contract, Contractor contractor, double value) {
this.contract = contract;
this.contractor = contractor;
this.value = value;
}
//A method that returns the contract for the bid
public Contract contract() {
return contract;
}
//A method that returns the contractor for the bid
public Contractor contractor() {
return this.contractor;
}
//A method that returns the value of the bid//
public double value() {
return this.value;
}
} | hoangsonww/Inheritance-in-Java | Bid.java |
915 |
class nk {
// Function to find all elements in array that appear more than n/k times.
public static int countOccurence(int[] arr, int n, int k) {
int x = n / k;
HashMap<Integer, Integer> y = new HashMap<>();
// Count the frequency of each element.
for (int i = 0; i < n; i++) {
if (!y.containsKey(arr[i])) {
y.put(arr[i], 1);
} else {
int count = y.get(arr[i]);
y.put(arr[i], count + 1);
}
}
int count = 0; // Variable to keep track of the count of elements appearing more than n/k times.
for (Map.Entry<Integer, Integer> entry : y.entrySet()) {
if (entry.getValue() > x) {
count++;
}
}
return count;
}
// Main function to test the countOccurence method.
public static void main(String[] args) {
int[] arr = {1, 1, 2, 2, 3, 5, 4, 2, 2, 3, 1, 1, 1};
int n = arr.length;
int k = 4;
int result = countOccurence(arr, n, k);
System.out.println("Count of elements appearing more than n/k times: " + result);
}
}
| kritika-das/LOVE_BABBAR_DSA_SHEET | nk.java |
916 |
/**
* Author: Leandro L. Minku ([email protected])
* Implementation of Oversampling Online Bagging as in
* WANG, S.; MINKU, L.L.; YAO, X. "Dealing with Multiple Classes in Online Class Imbalance Learning",
* Proceedings of the 25th International Joint Conference on Artificial Intelligence (IJCAI'16), July 2016
*
* Please note that this was not the implementation used in the experiments done in the paper above.
* It has been implemented after that paper was published.
* However, it implements the algorithm proposed in that paper. So, it should reflect those results.
*
*/
package moa.classifiers.meta;
import com.github.javacliparser.FloatOption;
import com.yahoo.labs.samoa.instances.Instance;
import moa.core.Measurement;
import moa.core.MiscUtils;
public class OOB extends OzaBag {
private static final long serialVersionUID = 1L;
public FloatOption theta = new FloatOption("theta", 't',
"The time decay factor for class size.", 0.9, 0, 1);
protected double classSize[]; // time-decayed size of each class
@Override
public String getPurposeString() {
return "Oversampling on-line bagging of Wang et al IJCAI 2016.";
}
public OOB() {
super();
classSize = null;
}
@Override
public void trainOnInstanceImpl(Instance inst) {
updateClassSize(inst);
double lambda = calculatePoissonLambda(inst);
for (int i = 0; i < this.ensemble.length; i++) {
int k = MiscUtils.poisson(lambda, this.classifierRandom);
if (k > 0) {
Instance weightedInst = (Instance) inst.copy();
weightedInst.setWeight(inst.weight() * k);
this.ensemble[i].trainOnInstance(weightedInst);
}
}
}
protected void updateClassSize(Instance inst) {
if (this.classSize == null) {
classSize = new double[inst.numClasses()];
// <---start class size as equal for all classes
for (int i=0; i<classSize.length; ++i) {
classSize[i] = 1d/classSize.length;
}
}
for (int i=0; i<classSize.length; ++i) {
classSize[i] = theta.getValue() * classSize[i] + (1d - theta.getValue()) * ((int) inst.classValue() == i ? 1d:0d);
}
}
// classInstance is the class corresponding to the instance for which we want to calculate lambda
// will result in an error if classSize is not initialised yet
public double calculatePoissonLambda(Instance inst) {
double lambda = 1d;
int majClass = getMajorityClass();
lambda = classSize[majClass] / classSize[(int) inst.classValue()];
return lambda;
}
// will result in an error if classSize is not initialised yet
public int getMajorityClass() {
int indexMaj = 0;
for (int i=1; i<classSize.length; ++i) {
if (classSize[i] > classSize[indexMaj]) {
indexMaj = i;
}
}
return indexMaj;
}
// will result in an error if classSize is not initialised yet
public int getMinorityClass() {
int indexMin = 0;
for (int i=1; i<classSize.length; ++i) {
if (classSize[i] <= classSize[indexMin]) {
indexMin = i;
}
}
return indexMin;
}
// will result in an error if classSize is not initialised yet
@Override
protected Measurement[] getModelMeasurementsImpl() {
Measurement [] measure = super.getModelMeasurementsImpl();
Measurement [] measurePlus = null;
if (classSize != null) {
measurePlus = new Measurement[measure.length + classSize.length];
for (int i=0; i<measure.length; ++i) {
measurePlus[i] = measure[i];
}
for (int i=0; i<classSize.length; ++i) {
String str = "size of class " + i;
measurePlus[measure.length+i] = new Measurement(str,classSize[i]);
}
} else
measurePlus = measure;
return measurePlus;
}
}
| minkull/UOB-OOB-MultiClass | OOB.java |
917 | package act4_sm159.client.model.task;
import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.Arrays;
import provided.remoteCompute.client.model.taskUtils.ITaskFactory;
import provided.remoteCompute.compute.ILocalTaskViewAdapter;
import provided.remoteCompute.compute.ITask;
import provided.remoteCompute.compute.ITaskResultFormatter;
/**
* Task to list files
*/
public class Ls implements ITask<String[]> {
/**
* SerialversionUID for well-defined serialization.
*/
private static final long serialVersionUID = 227L;
/**
* Adapter to the local view. Marked "transient" so that it is not serialized
* and instead is re-attached at the destination (the server).
*/
private transient ILocalTaskViewAdapter taskView = ILocalTaskViewAdapter.DEFAULT_ADAPTER;
/**
* Construct a task to list files
*/
public Ls() {
taskView.append("Ls constructing...");
}
/**
* List hw files
* @return hw files
*/
@Override
public String[] execute() {
File currentDirectory = new File("..");
return Arrays.asList(currentDirectory.listFiles())
.stream()
.map(file -> file.getName())
.toArray(size -> new String[size]);
}
/**
* Reinitializes transient fields upon deserialization. See the
* <a href="http://download.oracle.com/javase/6/docs/api/java/io/Serializable.html">
* Serializable</a> marker interface docs.
* taskView is set to a default value for now (ILocalTaskViewAdapter.DEFAULT_ADAPTER).
* @param stream The object stream with the serialized data
* @throws IOException if the input stream cannot be read correctly
* @throws ClassNotFoundException if the class file associated with the input stream cannot be located.
*/
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject(); // Deserialize the non-transient data
taskView = ILocalTaskViewAdapter.DEFAULT_ADAPTER; // re-initialize the transient field
}
/**
* Sets the task view adapter to a new value. Used by the server to attach
* the task to its view.
*/
@Override
public void setTaskViewAdapter(ILocalTaskViewAdapter viewAdapter) {
taskView = viewAdapter;
taskView.append("Ls task ready to run.");
}
/**
* An ITaskFactory for this task
*/
public static final ITaskFactory<String[]> FACTORY = new ITaskFactory<String[]>() {
public ITask<String[]> make(String param) {
return new Ls();
}
@Override
public String toString() {
return Ls.class.getName();
}
};
/**
* Return a a formatter that returns the output as-is.
*/
@Override
public ITaskResultFormatter<String[]> getFormatter() {
return new ITaskResultFormatter<String[]>() {
public String format(String[] result) {
return String.join("\n", result);
}
};
}
} | shreyasminocha/evil-rmi | Ls.java |
920 | // javac DH.java && java DH
// "Just use libsodium if you can," also applies for every other language below
import java.math.*;
import java.util.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.*;
import java.net.*;
public class DH {
int bitLength=512;
int certainty=20;// probabilistic prime generator 1-2^-certainty => practically 'almost sure'
private static final SecureRandom rnd = new SecureRandom();
// byte[] randomBytes = new byte[32];
// csprng.nextBytes(randombytes);
// Important: Despite its name, don't use SecureRandom.getInstanceStrong()!
// On Linux, this is the equivalent to reading /dev/random which is a pointless performance killer. The default for new SecureRandom() in Java 8 is to read from /dev/urandom, which is what you want
public static void main(String [] args) throws Exception
{
new DH();
}
public DH() throws Exception{
Random randomGenerator = new Random();
BigInteger generatorValue,primeValue,publicA,publicB,secretA,secretB,sharedKeyA,sharedKeyB;
primeValue = findPrime();// BigInteger.valueOf((long)g);
System.out.println("the prime is "+primeValue);
generatorValue = findPrimeRoot(primeValue);//BigInteger.valueOf((long)p);
System.out.println("the generator of the prime is "+generatorValue);
// on machine 1
secretA = new BigInteger(bitLength-2,randomGenerator);
// on machine 2
secretB = new BigInteger(bitLength-2,randomGenerator);
// to be published:
publicA=generatorValue.modPow(secretA, primeValue);
publicB=generatorValue.modPow(secretB, primeValue);
sharedKeyA = publicB.modPow(secretA,primeValue);// should always be same as:
sharedKeyB = publicA.modPow(secretB,primeValue);
System.out.println("the public key of A is "+publicA);
System.out.println("the public key of B is "+publicB);
System.out.println("the shared key for A is "+sharedKeyA);
System.out.println("the shared key for B is "+sharedKeyB);
System.out.println("The secret key for A is "+secretA);
System.out.println("The secret key for B is "+secretB);
String getAValue=sharedKeyA.toString();
String getBValue=sharedKeyB.toString();
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(getAValue.getBytes());
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for(int i=0;i<byteData.length;i++)
{
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));// ??
}
String getHexValue = sb.toString();
System.out.println("hex format in SHA-256 is "+getHexValue);
byte [] key = getAValue.getBytes("UTF-8");
MessageDigest sha = MessageDigest.getInstance("SHA-256");
key = sha.digest(key);
key = Arrays.copyOf(key, 16);
SecretKeySpec secretKeySpec = new SecretKeySpec(key,"AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
CipherInputStream cipt = new CipherInputStream(new FileInputStream(new File("test.jpg")),cipher); // enter your filename here
FileOutputStream fop=new FileOutputStream(new File("testEncrypt.jpg"));
int i;
while((i=cipt.read())!= -1)
fop.write(i);
cipher.init(Cipher.DECRYPT_MODE,secretKeySpec);
CipherInputStream cipt2 = new CipherInputStream(new FileInputStream(new File("testEncrypt.jpg")),cipher); // encryption of image
FileOutputStream fop2 = new FileOutputStream(new File("testDecrypt.jpg"));//decryption of images
int j;
while((j=cipt2.read())!=-1)
fop2.write(j);
}
// {
// System.load("/opt/local/lib/libcrypto.1.0.0.dylib");
// }
// private native BigInteger BN_generate_prime(BigInteger r,int bits);
// private native int BN_is_prime_fasttest_ex(BigInteger r,int nchecks);
private static boolean miller_rabin_pass(BigInteger a, BigInteger n) {
BigInteger n_minus_one = n.subtract(BigInteger.ONE);
BigInteger d = n_minus_one;
int s = d.getLowestSetBit();
d = d.shiftRight(s);
BigInteger a_to_power = a.modPow(d, n);
if (a_to_power.equals(BigInteger.ONE)) return true;
for (int i = 0; i < s-1; i++) {
if (a_to_power.equals(n_minus_one)) return true;
a_to_power = a_to_power.multiply(a_to_power).mod(n);
}
if (a_to_power.equals(n_minus_one)) return true;
return false;
}
public static boolean miller_rabin(BigInteger n) {
for (int repeat = 0; repeat < 20; repeat++) {
BigInteger a;
do {
a = new BigInteger(n.bitLength(), rnd);
} while (a.equals(BigInteger.ZERO));
if (!miller_rabin_pass(a, n)) {
return false;
}
}
return true;
}
boolean isPrime(BigInteger r){
return miller_rabin(r);
// return BN_is_prime_fasttest_ex(r,bitLength)==1;
}
public List<BigInteger> primeFactors(BigInteger number) {
BigInteger n = number;
BigInteger i=BigInteger.valueOf(2);
BigInteger limit=BigInteger.valueOf(10000);// speed hack! -> consequences ???
List<BigInteger> factors = new ArrayList<BigInteger>();
while (!n.equals(BigInteger.ONE)){
while (n.mod(i).equals(BigInteger.ZERO)){
factors.add(i);
n=n.divide(i);
// System.out.println(i);
// System.out.println(n);
if(isPrime(n)){
factors.add(n);// yes?
return factors;
}
}
i=i.add(BigInteger.ONE);
if(i.equals(limit))return factors;// hack! -> consequences ???
// System.out.print(i+" \r");
}
System.out.println(factors);
return factors;
}
boolean isPrimeRoot(BigInteger g, BigInteger p)
{
BigInteger totient = p.subtract(BigInteger.ONE); //p-1 for primes;// factor.phi(p);
List<BigInteger> factors = primeFactors(totient);
int i = 0;
int j = factors.size();
for(;i < j; i++)
{
BigInteger factor = factors.get(i);//elementAt
BigInteger t = totient.divide( factor);
if(g.modPow(t, p).equals(BigInteger.ONE))return false;
}
return true;
}
String download(String address){
String txt="";
URLConnection conn = null;
InputStream in = null;
try {
URL url = new URL(address);
conn = url.openConnection();
conn.setReadTimeout(10000);//10 secs
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
String encoding = "UTF-8";
while ((numRead = in.read(buffer)) != -1) {
txt+=new String(buffer, 0, numRead, encoding);
}
} catch (Exception exception) {
exception.printStackTrace();
}
return txt;
}
void compareWolfram(BigInteger p){
// String g= download("http://www.wolframalpha.com/input/?i=primitive+root+"+p);
String url="http://api.wolframalpha.com/v2/query?appid=&input=primitive+root+"+p;
System.out.println(url);
String g= download(url);;
String[] vals=g.split(".plaintext>");
if(vals.length<3) System.out.println(g);
else System.out.println("wolframalpha generatorValue "+vals[3]);
}
BigInteger findPrimeRoot(BigInteger p){
int start= 2001;// first best probably precalculated by NSA?
// preferably 3, 17 and 65537
if(start==2)compareWolfram(p);
for(int i=start;i<100000000;i++)
if(isPrimeRoot(BigInteger.valueOf(i),p))
return BigInteger.valueOf(i);
// if(isPrimeRoot(i,p))return BigInteger.valueOf(i);
return BigInteger.valueOf(0);
}
BigInteger findPrime(){
Random rnd=new Random();
BigInteger p=BigInteger.ZERO;
// while(!isPrime(p))
p= new BigInteger(bitLength, certainty, rnd);// sufficiently NSA SAFE?!!
return p;
// BigInteger r;
// BigInteger r2= BN_generate_prime(r,512);
// System.out.println("isPrime(i)? "+r+" "+r2);
// return r;
}
// Better for NSA:?
// Some of the largest primes not known to have any particular form (that is, no simple formula such as that of Mersenne primes) have been found by taking a piece of semi-random binary data, converting it to a number n, multiplying it by 256k for some positive integer k, and searching for possible primes within the interval [256kn + 1, 256k(n + 1) β 1].
// long findPrime(long from,long to){
// long findPrime2(){
// Random randomGenerator = new Random();
//
// // long n=randomGenerator.nextLong();
// int k=2;//randomGenerator.nextInt(2);
// long n=randomGenerator.nextInt();
// long from=(long)Math.pow(256,k)*n;
// long to=(long)Math.pow(256,k)*(n+1);
// // BigInteger
//
// System.out.println("from "+from);
// System.out.println("to "+to);
// for(long i=from;i<to;i++){
// System.out.println("isPrime(i)? "+i);
// if(isPrime(i))return i;
// }
// return 0;
// }
} | pannous/Diffie-Hellman | DH.java |
921 | /*
* $Id: cp.java,v 1.7 2001/10/07 23:48:55 rayo Exp $
*/
/*
* $Log: cp.java,v $
* Revision 1.7 2001/10/07 23:48:55 rayo
* added author javadoc tag
*
* Revision 1.6 2001/10/07 23:23:23 rayo
* added internal documentation, cleaned up javadoc
*
* Revision 1.5 2001/10/06 15:39:10 rayo
* added comments
*
* Revision 1.4 2001/09/27 21:52:56 rayo
* minor cleanups
*
* Revision 1.3 2001/09/26 16:15:29 rayo
* now throws Exception
*
* Revision 1.2 2001/09/17 01:43:49 rayo
* added error handling
*
* Revision 1.1 2001/09/16 12:58:40 rayo
* Initial revision
*
*/
/**
* A simple copy program for a simulated file system.
* <p>
* Usage:
* <pre>
* java cp <i>input-file</i> <i>output-file</i>
* </pre>
* @author Ray Ontko
*/
public class cp
{
/**
* The name of this program.
* This is the program name that is used
* when displaying error messages.
*/
public static final String PROGRAM_NAME = "cp" ;
/**
* The size of the buffer to be used when reading files.
*/
public static final int BUF_SIZE = 4096 ;
/**
* The file mode to use when creating the output file.
*/
// ??? perhaps this should be the same mode as the input file
public static final short OUTPUT_MODE = 0700 ;
/**
* Copies an input file to an output file.
* @exception java.lang.Exception if an exception is thrown by
* an underlying operation
*/
public static void main( String[] argv ) throws Exception
{
// initialize the file system simulator kernel
Kernel.initialize() ;
// make sure we got the correct number of parameters
if( argv.length != 2 )
{
System.err.println( PROGRAM_NAME + ": usage: java " +
PROGRAM_NAME + " input-file output-file" ) ;
Kernel.exit( 1 ) ;
}
// give the parameters more meaningful names
String in_name = argv[0] ;
String out_name = argv[1] ;
// open the input file
int in_fd = Kernel.open( in_name , Kernel.O_RDONLY ) ;
if( in_fd < 0 )
{
Kernel.perror( PROGRAM_NAME ) ;
System.err.println( PROGRAM_NAME + ": unable to open input file \"" +
in_name + "\"" ) ;
Kernel.exit( 2 ) ;
}
// open the output file
int out_fd = Kernel.creat( out_name , OUTPUT_MODE ) ;
if( out_fd < 0 )
{
Kernel.perror( PROGRAM_NAME ) ;
System.err.println( PROGRAM_NAME + ": unable to open output file \"" +
argv[1] + "\"" ) ;
Kernel.exit( 3 ) ;
}
// read and write buffers full of data while we can
int rd_count ;
byte[] buffer = new byte[BUF_SIZE] ;
while( true )
{
// read a buffer full from the input file
rd_count = Kernel.read( in_fd , buffer , BUF_SIZE ) ;
// if error or nothing read, quit the loop
if( rd_count <= 0 )
break ;
// write whatever we read to the output file
int wr_count = Kernel.write( out_fd , buffer , rd_count ) ;
// if error or nothing written, give message and exit
if( wr_count <= 0 )
{
Kernel.perror( PROGRAM_NAME ) ;
System.err.println( PROGRAM_NAME +
": error during write to output file" ) ;
Kernel.exit( 4 ) ;
}
}
// close the files
Kernel.close( in_fd ) ;
Kernel.close( out_fd ) ;
// check to see if the final read was successful; exit accordingly
if( rd_count == 0 )
Kernel.exit( 0 ) ;
else
{
Kernel.perror( PROGRAM_NAME ) ;
System.err.println( PROGRAM_NAME +
": error during read from input file" ) ;
Kernel.exit( 5 ) ;
}
}
}
| ttsugriy/File-System-Simulator | cp.java |
922 | import java.io.*;
/**
* A class that represents a cd command object that extends Filter class and
* that contains main functionality of cd command.
* @author michaelroytman
*/
public class Cd extends Filter {
private CurrentDir dir; //current directory object
private String destination; //destination of directory
public Cd(String destination, CurrentDir dir) {
super(null, null); //super constructor; no input or output queues
this.dir = dir;
this.destination = destination;
}
/**
* @override
* Transform method that sets the current directory object to new path.
*/
public Object transform(Object o) {
//moves current directory to parent
if (destination.equals("..")) {
File file = new File(dir.getDir()); //file representing path of current directory
String fileString;
fileString = file.getParent(); //parent of current directory
dir.setDir(fileString, false); //sets current directory to new directory
}
//does nothing
else if (destination.equals(".")) {
}
//if an actual destination directory is specified
else {
//appends current directory to include new directory
dir.setDir(System.getProperty("file.separator") + destination, true);
}
this.done = true; //loop done
return null; //no output queue; need to return something
}
}
| MichaelRoytman/UnixShell | Cd.java |
923 | import java.util.concurrent.BlockingQueue;
/**
* A class that represents a lc command object that extends Filter class and
* that contains main functionality of lc command.
* @author michaelroytman
*/
public class Lc extends Filter {
private int count; //line count
private boolean countReturned; //boolean flag representing whether the
//count has been returned
/**
* Constructor that accepts an input and output blocking queue.
* @param in input blocking queue
* @param out output blocking queue
*/
public Lc(BlockingQueue<Object> in, BlockingQueue<Object> out) {
super(in, out);
count = 0;
countReturned = false;
}
/**
* @override
* Override run method for lc command that adds the countReturned condition
* to the functionality of the method.
*/
public void run() {
Object o = null;
while(! this.done) {
//if there is an input queue and if count has not been returned
if (in != null && !countReturned) {
// read from input queue, may block
try {
o = in.take();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// allow filter to change message
o = transform(o);
//if there is an output queue and o is not null
if (out != null && o != null) {
// forward to output queue
try {
out.put(o);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
/**
* @override
* Transform method that keeps track of line count and returns it to the
* output queue at the end of input; once count is returned; an EndOfFileMarker
* is returned to signal end of output.
*/
public Object transform(Object o) {
//if o is a String, line is incremented
if (o instanceof String) {
count++;
return null;
}
// if o is an EndOfFileMarker, signal end of input
else if (o instanceof EndOfFileMarker) {
countReturned = true; //count is returned
return ((Integer)count).toString(); //returns count as an Integer
}
//if count has been returned, returns EndOfFileMarker to output queue
//to signal end of output
else if (countReturned) {
this.done = true;
return new EndOfFileMarker();
}
return null;
}
} | MichaelRoytman/UnixShell | Lc.java |
924 | import java.util.Scanner;
public class os{
public static void main(String[] args){
String Question1 = "Explain any 4 Commands of Linux?";
System.out.println(Question1);
//Command-1: ls - list directory contents
//Command-2: cd β change working directory
//Command-3: mkdir β make a new directory or folder in the current location
//Command-4: rm β remove files and directories
int answer=0;
while (answer!=5) {
try (Scanner scanner = new Scanner(System.in)) {
System.out.print("Enter your choice:");
try {
answer = Integer.parseInt(scanner.nextLine());
} catch (NumberFormatException e) {
continue;}
}
switch (answer) {
case 1 :
System.out.println("\nThe command 'ls' is used to display all the file names, including hidden ones.");
break;
case 2 :
System.out.println("\nThe command 'cd' stands for Change Directory");
System.out.println("- It allows you to move from one directory to another within the same filesystem hierarchy.\n" + "- You can use it with either absolute paths like /home/user\n"+ "(which starts at root level), \nor relative paths which start from wherever "+ "you currently are,\ne.g.,../Documents/. ");
break;
case 3 :
System.out.println("\nThe'mkdir' command creates a new directory inside an existing parent directory using its name as argument:\nmkdir <directory_name>");
break;
case 4 :
System.out.println("\nThe 'rm' command removes specified files or folders:"+ "\nrmdir [options]... DIRECTORY...\nremove [-f | --force] [--interactive | --no-preserve-root]\n[-r -R,--recursive][--help]");
break;
default:
System.out.println("Invalid input! Please enter valid number between 1 & 4 inclusive!");
break;
}}
public static void main() throws Exception{
Menu menu=new Menu();
Scanner scanner= new Scanner(System.in);
while(!menu.isExit){
try{
int choice = Integer.parseInt((scanner.nextLine()));
if (!menu.isValidChoice(choice))
throw new IllegalArgumentException("Invalid input, please enter a valid number.");
throw new IllegalArgumentException("Invalid input!");
switch (choice) {
//case statements go here
case -1://exit
menu.setExitStatus(true);//setting exit status to true
return;//returning from the method, which will terminate it's execution
return;//returning from the method, terminating program execution
case 0://option A
//code for optionA goes here
break;
case 1://option B
// code for optionB goes here
break;
/* add more cases as needed */
}
}catch(NumberFormatException e){
continue;} catch (IllegalArgumentException ex) {//handling invalid inputs
System.out.println("\nPlease enter a valid integer value.");
} catch (IllegalArgumentException ex) {//handling invalid inputs
} catch (IllegalArgumentException ex) {
System.err.println(ex.getMessage());
}}
public boolean getExitStatus(){
return this._isExited;}
private void setExitStatus(boolean flag){
_isExited =flag ;}
/**
**/
class MenuOption{
String name;
int number;
Runnable action;
MenuOption(String n,int num,Runnable act){
public MenuOption(String n,int num,Runnable act){
public MenuOption(String n,int num,Runnable act){
public MenuOption(String n,int num,Runnable act){
MenuOption(String n,int num,Runnable act){
//constructor for menu option object
//constructor for menu option object
}
}
// what is deadlock in Operating System?
// A deadlock is a situation in which two or more processes are waiting for each other to release a resource that they are holding. This can happen when two processes are both trying to access the same resource, and neither one is willing to give it up.
// Deadlocks can occur in any operating system, but they are more common in multi-threaded programs. This is because threads can share resources, and if two threads are both trying to access the same resource, they can deadlock each other.
// There are several ways to prevent deadlocks. One way is to use a deadlock avoidance algorithm. This algorithm ensures that no two processes can ever be waiting for each other to release a resource. Another way to prevent deadlocks is to use a deadlock detection algorithm. This algorithm detects deadlocks when they occur, and then it takes steps to break the deadlock.
// In Java, there are several ways to prevent deadlocks. One way is to use the synchronized keyword. This keyword ensures that only one thread can access a shared resource at a time. Another way to prevent deadlocks is to use the wait() and notify() methods. These methods allow threads to wait for each other to release a resource.
// If you are writing a multi-threaded program in Java, it is important to be aware of the possibility of deadlocks. There are several tools available to help you prevent deadlocks, such as deadlock avoidance algorithms and deadlock detection algorithms.A deadlock is a situation in which two or more processes are waiting for each other to release a resource that they are holding. This can happen when two processes are both trying to access the same resource, and neither one is willing to give it up.
// Deadlocks can occur in any operating system, but they are more common in multi-threaded programs. This is because threads can share resources, and if two threads are both trying to access the same resource, they can deadlock each other.
// There are several ways to prevent deadlocks. One way is to use a deadlock avoidance algorithm. This algorithm ensures that no two processes can ever be waiting for each other to release a resource. Another way to prevent deadlocks is to use a deadlock detection algorithm. This algorithm detects deadlocks when they occur, and then it takes steps to break the deadlock.
// In Java, there are several ways to prevent deadlocks. One way is to use the synchronized keyword. This keyword ensures that only one thread can access a shared resource at a time. Another way to prevent deadlocks is to use the wait() and notify() methods. These methods allow threads to wait for each other to release a resource.
// If you are writing a multi-threaded program in Java, it is important to be aware of the possibility of deadlocks. There are several tools available to help you prevent deadlocks, such as deadlock avoidance algorithms and deadlock detection algorithms. | Saikishor164/javapractical | os.java |
925 | //import classes and packages
import java.util.Scanner;
// create Node class to design the structure of the AVL Tree Node
class Node
{
int element;
int h; //for height
Node leftChild;
Node rightChild;
//default constructor to create null node
public Node()
{
leftChild = null;
rightChild = null;
element = 0;
h = 0;
}
// parameterized constructor
public Node(int element)
{
leftChild = null;
rightChild = null;
this.element = element;
h = 0;
}
}
// create class ConstructAVLTree for constructing AVL Tree
class ConstructAVLTree
{
private Node rootNode;
//Constructor to set null value to the rootNode
public ConstructAVLTree()
{
rootNode = null;
}
//create removeAll() method to make AVL Tree empty
public void removeAll()
{
rootNode = null;
}
// create checkEmpty() method to check whether the AVL Tree is empty or not
public boolean checkEmpty()
{
if(rootNode == null)
return true;
else
return false;
}
// create insertElement() to insert element to to the AVL Tree
public void insertElement(int element)
{
rootNode = insertElement(element, rootNode);
}
//create getHeight() method to get the height of the AVL Tree
private int getHeight(Node node )
{
return node == null ? -1 : node.h;
}
//create maxNode() method to get the maximum height from left and right node
private int getMaxHeight(int leftNodeHeight, int rightNodeHeight)
{
return leftNodeHeight > rightNodeHeight ? leftNodeHeight : rightNodeHeight;
}
//create insertElement() method to insert data in the AVL Tree recursively
private Node insertElement(int element, Node node)
{
//check whether the node is null or not
if (node == null)
node = new Node(element);
//insert a node in case when the given element is lesser than the element of the root node
else if (element < node.element)
{
node.leftChild = insertElement( element, node.leftChild );
if( getHeight( node.leftChild ) - getHeight( node.rightChild ) == 2 )
if( element < node.leftChild.element )
node = rotateWithLeftChild( node );
else
node = doubleWithLeftChild( node );
}
else if( element > node.element )
{
node.rightChild = insertElement( element, node.rightChild );
if( getHeight( node.rightChild ) - getHeight( node.leftChild ) == 2 )
if( element > node.rightChild.element)
node = rotateWithRightChild( node );
else
node = doubleWithRightChild( node );
}
else
; // if the element is already present in the tree, we will do nothing
node.h = getMaxHeight( getHeight( node.leftChild ), getHeight( node.rightChild ) ) + 1;
return node;
}
// creating rotateWithLeftChild() method to perform rotation of binary tree node with left child
private Node rotateWithLeftChild(Node node2)
{
Node node1 = node2.leftChild;
node2.leftChild = node1.rightChild;
node1.rightChild = node2;
node2.h = getMaxHeight( getHeight( node2.leftChild ), getHeight( node2.rightChild ) ) + 1;
node1.h = getMaxHeight( getHeight( node1.leftChild ), node2.h ) + 1;
return node1;
}
// creating rotateWithRightChild() method to perform rotation of binary tree node with right child
private Node rotateWithRightChild(Node node1)
{
Node node2 = node1.rightChild;
node1.rightChild = node2.leftChild;
node2.leftChild = node1;
node1.h = getMaxHeight( getHeight( node1.leftChild ), getHeight( node1.rightChild ) ) + 1;
node2.h = getMaxHeight( getHeight( node2.rightChild ), node1.h ) + 1;
return node2;
}
//create doubleWithLeftChild() method to perform double rotation of binary tree node. This method first rotate the left child with its right child, and after that, node3 with the new left child
private Node doubleWithLeftChild(Node node3)
{
node3.leftChild = rotateWithRightChild( node3.leftChild );
return rotateWithLeftChild( node3 );
}
//create doubleWithRightChild() method to perform double rotation of binary tree node. This method first rotate the right child with its left child and after that node1 with the new right child
private Node doubleWithRightChild(Node node1)
{
node1.rightChild = rotateWithLeftChild( node1.rightChild );
return rotateWithRightChild( node1 );
}
//create getTotalNumberOfNodes() method to get total number of nodes in the AVL Tree
public int getTotalNumberOfNodes()
{
return getTotalNumberOfNodes(rootNode);
}
private int getTotalNumberOfNodes(Node head)
{
if (head == null)
return 0;
else
{
int length = 1;
length = length + getTotalNumberOfNodes(head.leftChild);
length = length + getTotalNumberOfNodes(head.rightChild);
return length;
}
}
//create searchElement() method to find an element in the AVL Tree
public boolean searchElement(int element)
{
return searchElement(rootNode, element);
}
private boolean searchElement(Node head, int element)
{
boolean check = false;
while ((head != null) && !check)
{
int headElement = head.element;
if (element < headElement)
head = head.leftChild;
else if (element > headElement)
head = head.rightChild;
else
{
check = true;
break;
}
check = searchElement(head, element);
}
return check;
}
// create inorderTraversal() method for traversing AVL Tree in in-order form
public void inorderTraversal()
{
inorderTraversal(rootNode);
}
private void inorderTraversal(Node head)
{
if (head != null)
{
inorderTraversal(head.leftChild);
System.out.print(head.element+" ");
inorderTraversal(head.rightChild);
}
}
// create preorderTraversal() method for traversing AVL Tree in pre-order form
public void preorderTraversal()
{
preorderTraversal(rootNode);
}
private void preorderTraversal(Node head)
{
if (head != null)
{
System.out.print(head.element+" ");
preorderTraversal(head.leftChild);
preorderTraversal(head.rightChild);
}
}
// create postorderTraversal() method for traversing AVL Tree in post-order form
public void postorderTraversal()
{
postorderTraversal(rootNode);
}
private void postorderTraversal(Node head)
{
if (head != null)
{
postorderTraversal(head.leftChild);
postorderTraversal(head.rightChild);
System.out.print(head.element+" ");
}
}
}
// create AVLTree class to construct AVL Tree
public class AVLTreeExample
{
//main() method starts
public static void main(String[] args)
{
//creating Scanner class object to get input from user
Scanner sc = new Scanner(System.in);
// create object of ConstructAVLTree class object for costructing AVL Tree
ConstructAVLTree obj = new ConstructAVLTree();
char choice; //initialize a character type variable to choice
// perform operation of AVL Tree using switch
do
{
System.out.println("\nSelect an operation:\n");
System.out.println("1. Insert a node");
System.out.println("2. Search a node");
System.out.println("3. Get total number of nodes in AVL Tree");
System.out.println("4. Is AVL Tree empty?");
System.out.println("5. Remove all nodes from AVL Tree");
System.out.println("6. Display AVL Tree in Post order");
System.out.println("7. Display AVL Tree in Pre order");
System.out.println("8. Display AVL Tree in In order");
//get choice from user
int ch = sc.nextInt();
switch (ch)
{
case 1 :
System.out.println("Please enter an element to insert in AVL Tree");
obj.insertElement( sc.nextInt() );
break;
case 2 :
System.out.println("Enter integer element to search");
System.out.println(obj.searchElement( sc.nextInt() ));
break;
case 3 :
System.out.println(obj.getTotalNumberOfNodes());
break;
case 4 :
System.out.println(obj.checkEmpty());
break;
case 5 :
obj.removeAll();
System.out.println("\nTree Cleared successfully");
break;
case 6 :
System.out.println("\nDisplay AVL Tree in Post order");
obj.postorderTraversal();
break;
case 7 :
System.out.println("\nDisplay AVL Tree in Pre order");
obj.preorderTraversal();
break;
case 8 :
System.out.println("\nDisplay AVL Tree in In order");
obj.inorderTraversal();
break;
default :
System.out.println("\n ");
break;
}
System.out.println("\nPress 'y' or 'Y' to continue \n");
choice = sc.next().charAt(0);
} while (choice == 'Y'|| choice == 'y');
}
}
| kishanrajput23/Coding-Buddies-Community-Contributions | avl.java |
926 | package ee6895ta;
import static ee6895ta.OCRObject.*;
import java.io.Serializable;
import java.util.ArrayList;
import org.apache.commons.math3.distribution.BinomialDistribution;
import org.apache.commons.math3.stat.interval.ConfidenceInterval;
import org.apache.commons.math3.stat.interval.NormalApproximationInterval;
import scala.Tuple2;
public class TF implements Comparable<TF>, Serializable {
/**
*
*/
private static final long serialVersionUID = -7738084869738437121L;
public enum Rloc {
IN("IN"), ABOVE("ABOVE"), BELOW("BELOW"), PATHED("PATH-DEPENDENT");
private String name;
private Rloc(String s) {
name = s;
}
public String toString() {
return name;
}
};
public static NormalApproximationInterval nai = new NormalApproximationInterval();
public final String token;
public final int freq;
public TF(String t, int f) {
this.token = t;
this.freq = f;
}
/*
* Returns whether the given token could be variant of this token given Ergo by being less than
* the max predicted frequency range.
* NOTE: an upgrade would scale the stdDev according to the number of edits,
* so that errors don't accumulate during repeated application of a given Conf Interval
*/
public boolean hasLeftVariant(TF v, Ergo ergo, double predictionZ) throws Exception {
if (this.token.equals(v.token)) return true;
if (v.freq >= this.freq) return false;
return !location(v, ergo, predictionZ, false).equals(Rloc.ABOVE);
}
/*
* Joint log probability mass
*/
public double jlpm(TF v, Ergo ergo) throws Exception {
verbose(v.token, "Examining " + "\n" + this.toString() + " -> " + v.toString() + "...");
if (this.token.equals(v.token)) return 0;
Edit[] edits = this.edits(v).toArray(new Edit[] {});
double probs[] = new double[edits.length];
for (int i = 0; i < edits.length; i++) {
Edit edit = edits[i];
probs[i] = ergo.postProb(edit.from(), edit.to(), (edits.length == 1 ? v.freq : 0));
}
double jp = 0;
for (int i = 0; i < edits.length; i++) {
jp += Math.log(probs[i]);
}
return jp;
}
/*
* Location of the given variant, NOTE: more than two edits only traverses one path and
* therefore is not recommended
*/
public Rloc location(TF v, Ergo ergo, double predictionZ, boolean emit) throws Exception {
if (this.token.equals(v.token)) return Rloc.IN;
if (v.freq >= this.freq) return Rloc.ABOVE;
int totalTrials = this.freq + v.freq;
Range predictRange = new Range(totalTrials, totalTrials);
verbose(v.token, "\n" + this.toString() + " -> " + v.toString() + " tt=" + totalTrials);
Edit[] edits = this.edits(v).toArray(new Edit[] {});
double probs[] = new double[edits.length];
for (int i = 0; i < edits.length; i++) {
Edit edit = edits[i];
probs[i] = ergo.postProb(edit.from(), edit.to(), (edits.length == 1 ? v.freq : 0));
}
// 3-edits will create a problem - don't search them.
if (edits.length == 2 && (probs[0] < probs[1])) {
Edit he = edits[0];
edits[0] = edits[1];
edits[1] = he;
double hp = probs[0];
probs[0] = probs[1];
probs[1] = hp;
}
for (int i = 0; i < edits.length; i++) {
predictRange.setMin(predictOccurrences(predictRange.getMin(), probs[i], predictionZ).getMin());
predictRange.setMax(predictOccurrences(predictRange.getMax(), probs[i], predictionZ).getMax());
verbose(emit, "Edit " + edits[i].toString() + " predicts range " + predictRange + " using prob = " + probs[i]);
}
Rloc rloc = (v.freq < predictRange.getMin() ? Rloc.BELOW : (v.freq > predictRange.getMax() ? Rloc.ABOVE : Rloc.IN));
verbose(emit, " is " + rloc);
return rloc;
}
/*
* Return the predicted frequency range of occurences of the given edit for the given number of
* tokens
*/
public Range predictOccurrences(int trials, double prob, double z) {
if (trials < 2) return new Range(0, 2);
if (prob <= 0) return new Range(0, 0);
BinomialDistribution dist = new BinomialDistribution(trials, prob);
double stdDev = Math.sqrt(dist.getNumericalVariance());
return new Range(dist.getNumericalMean() - z * stdDev, dist.getNumericalMean() + z * stdDev);
}
/*
* Probability of the given number of occurrences
*/
public double probOcc(int trials, double prob, int occ) {
BinomialDistribution dist = new BinomialDistribution(trials, prob);
return Math.log(dist.probability(occ));
}
/*
* Confidence interval for a universal error rate misread
*/
public ConfidenceInterval probMisreadAs(TF v) {
if (this.token.equals(v.token)) return null;
if (v.freq >= this.freq) return new ConfidenceInterval(DEFACTO_ONE - EPSILON, DEFACTO_ONE + EPSILON, DEFACTO_ONE);
int edits = this.edits(v).size();
int trials = this.freq * edits + v.freq * edits;
int succs = v.freq * edits;
return nai.createInterval(trials, succs, CONFIDENCE_LEVEL);
}
/*
* Edits
*/
public ArrayList<Edit> edits(TF v) {
assert (this.token.length() == v.token.length());
ArrayList<Edit> edits = new ArrayList<Edit>();
char[] tcs = this.token.toCharArray();
char[] vcs = v.token.toCharArray();
for (int i = 0; i < tcs.length; i++) {
if (tcs[i] != vcs[i]) {
edits.add(new Edit(tcs[i], vcs[i]));
}
}
return edits;
}
/*
* The 1-* DVF that separates this TF from the given TF
*/
public ArrayList<DVF> dvf(TF v) {
ArrayList<DVF> dvfs = new ArrayList<DVF>();
ArrayList<Edit> edits = this.edits(v);
if (edits.size() == 1) {
dvfs.add(new DVF(edits.get(0).from() + edits.get(0).to(), v.freq));
}
return dvfs;
}
@Override
/*
* Always sorted in DESC by default
*/
public int compareTo(TF o) {
if (o == null) return 1;
return o.freq > this.freq ? 1 : (this.freq != o.freq ? -1 : 0);
}
public Tuple2<String, Integer> t2() {
return new Tuple2<String, Integer>(token, freq);
}
public String literal() {
return token + COMMA + freq;
}
@Override
public String toString() {
return this.token + " (" + this.freq + ")";
}
}
| Sapphirine/Enhanced-Error-Correction-in-Large-Volume-OCR-Datasets | TF.java |
927 | package org.usfirst.frc.team6489.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.InternalButton;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
public class OI {
public static Joystick left;
public static JoystickButton leftControls;
public static Joystick right;
public static JoystickButton rightControls;
public static XboxController xbox;
// TODO: Test if these works as static!
public static Button forkliftUp;
public static Button forkliftDown;
/**
* Initializes all the buttons and their actions.
**/
public void initControls() {
xbox = new XboxController(0);
left = new Joystick(1);
right = new Joystick(2);
InternalButton none = new InternalButton(); // Effectively a button that is eternally not-pressed
leftControls = new JoystickButton(left, 11);
rightControls = new JoystickButton(right, 12);
}
public OI() {
initControls();
}
} | ZacharyRobotics/2018 | OI.java |
928 | /**
* Automated Teller Machine.
*
* @author PP-Namias
*
* Licensed under the MIT
*/
// import a library we need for this code project
import java.util.*;
public class ATM {
public static void main(String[] args){
try (Scanner input = new Scanner(System.in)) {
// Initializing Variable of Password and Balance
int password = 123456;
int balance = 50_000;
// Welcome message
System.out.println("\t\tWelcome to the ATM Machine".toUpperCase());
System.out.println("------------------------------------------");
// Get the password of the user
System.out.print ("Enter your PIN Password: ");
int pass = input.nextInt();
System.out.println("------------------------------------------");
// MAIN-ELSE STATEMENT STARTS HERE
// The "IF" of "MAIN IF-ELSE STATEMENT"
if(pass == password){
// Main Page
System.out.println("Good Day Mr. Jhon Keneth Namias");
System.out.println("[1] Check Balance");
System.out.println("[2] Withdraw");
System.out.println("[3] Deposit");
System.out.println("------------------------------------------");
// Get the function of the user to be process
System.out.print("Enter a function: ");
int choice = input.nextInt();
// Switch Case for the function of the user chose above
switch (choice) {
// Case 1 for Check Balance
case 1: {
System.out.print("\nYour Balance is " + balance + " Pesos");
/*
* The program will ask the user if he/she wants to withdraw after
* checking the balance *
*/
System.out.print("\n\n\t\tDo you want to withdraw: ");
String x = input.next();
// If-Else for the user if he/she wants to withdraw
if (x.startsWith("y") || x.startsWith("Y")) {
// get the amount that you want to withdraw in your back account
System.out.print("\nEnter amount: ");
int amount = input.nextInt();
/*
* create a new varible na kung ilan na lang ang
* matitira kapag nagwithdraw
*/
int newBalance = balance - amount;
// Message to show after withdraw
System.out.print("\n\t\tWithdraw Succesfully!");
System.out.println("\n\nYour new balance is " + newBalance);
System.out.println("------------------------------------------");
// use "break" to stop the program after withdraw
break;
} else {
/*
* else if the user don't want to withdraw after
* checking the balance
*/
System.out.print("\n\t\tThank you for checking!");
System.out.print("\n------------------------------------------");
// use "break" to stop the program after withdraw
break;
}
}
case 2: {
// get the amount that you want to withdraw in your back account
System.out.print("\nEnter amount: ");
int amount = input.nextInt();
/*
* create a new varible na kung ilan na lang ang
* matitira after withdraw
*/
int newBalance = balance - amount;
// Message to show after withdraw
System.out.print("\n\t\tWithdraw Succesfully!");
// print the new balance of your account
System.out.println("\n\nYour new balance is " + newBalance);
System.out.println("------------------------------------------");
// use "break" to stop the program after withdraw
break;
}
case 3: {
/*
* Ask the user if how much he/she wants to
* add money in his/her account
*/
System.out.print("\nEnter amount to be added in your account: ");
int deposit = input.nextInt();
/*
* create a new variable na kung ilan na ang balance
* kapag naidagdag na ang "deposit" sa "balance"
*/
int newAm = balance + deposit;
// Message to show after deposit
System.out.println("\n\t\tDeposit Succesfully!");
System.out.println("\nYour new balance is " + newAm);
System.out.println("------------------------------------------");
// use "break" to stop the program after deposit
break;
}
}
// The "ELSE" from "MAIN IF-ELSE STATEMENT"
}
else{
// If the password is wrong, the program will stop
System.out.print("You entered a wrong password, try again");
}
}
}
} | PP-Namias/Java-Program | ATM.java |
929 | /*
* $Id: ls.java,v 1.6 2001/10/12 02:14:31 rayo Exp $
*/
/*
* $Log: ls.java,v $
* Revision 1.6 2001/10/12 02:14:31 rayo
* better formatting
*
* Revision 1.5 2001/10/07 23:48:55 rayo
* added author javadoc tag
*
*/
/**
* A simple directory listing program for a simulated file system.
* <p>
* Usage:
* <pre>
* java ls <i>path-name</i> ...
* </pre>
* @author Ray Ontko
*/
public class ls
{
/**
* The name of this program.
* This is the program name that is used
* when displaying error messages.
*/
public static String PROGRAM_NAME = "ls" ;
/**
* Lists information about named files or directories.
* @exception java.lang.Exception if an exception is thrown
* by an underlying operation
*/
public static void main( String[] args ) throws Exception
{
// initialize the file system simulator kernel
Kernel.initialize() ;
// for each path-name given
for( int i = 0 ; i < args.length ; i ++ )
{
String name = args[i] ;
int status = 0 ;
// stat the name to get information about the file or directory
Stat stat = new Stat() ;
status = Kernel.stat( name , stat ) ;
if( status < 0 )
{
Kernel.perror( PROGRAM_NAME ) ;
Kernel.exit( 1 ) ;
}
// mask the file type from the mode
short type = (short)( stat.getMode() & Kernel.S_IFMT ) ;
// if name is a regular file, print the info
if( type == Kernel.S_IFREG )
{
print( name , stat ) ;
}
// if name is a directory open it and read the contents
else if( type == Kernel.S_IFDIR )
{
// open the directory
int fd = Kernel.open( name , Kernel.O_RDONLY ) ;
if( fd < 0 )
{
Kernel.perror( PROGRAM_NAME ) ;
System.err.println( PROGRAM_NAME +
": unable to open \"" + name + "\" for reading" ) ;
Kernel.exit(1) ;
}
// print a heading for this directory
System.out.println() ;
System.out.println( name + ":" ) ;
// create a directory entry structure to hold data as we read
DirectoryEntry directoryEntry = new DirectoryEntry() ;
int count = 0 ;
// while we can read, print the information on each entry
while( true )
{
// read an entry; quit loop if error or nothing read
status = Kernel.readdir( fd , directoryEntry ) ;
if( status <= 0 )
break ;
// get the name from the entry
String entryName = directoryEntry.getName() ;
// call stat() to get info about the file
status = Kernel.stat( name + "/" + entryName , stat ) ;
if( status < 0 )
{
Kernel.perror( PROGRAM_NAME ) ;
Kernel.exit( 1 ) ;
}
// print the entry information
print( entryName , stat ) ;
count ++ ;
}
// check to see if our last read failed
if( status < 0 )
{
Kernel.perror( "main" ) ;
System.err.println( "main: unable to read directory entry from /" ) ;
Kernel.exit(2) ;
}
// close the directory
Kernel.close( fd ) ;
// print a footing for this directory
System.out.println( "total files: " + count ) ;
}
}
// exit with success if we process all the arguments
Kernel.exit( 0 ) ;
}
/**
* Print a listing for a particular file.
* This is a convenience method.
* @param name the name to print
* @param stat the stat containing the file's information
*/
private static void print( String name , Stat stat )
{
// a buffer to fill with a line of output
StringBuffer s = new StringBuffer() ;
// a temporary string
String t = null ;
short ts = 0;
// append mode information
ts = (short) stat.getMode();
s.append( ' ' );
s.append( (ts & Kernel.S_IRWXU) >> 6 );
s.append( (ts & Kernel.S_IRWXG) >> 3 );
s.append( ts & Kernel.S_IRWXO );
s.append( ' ' );
// append uid info
ts = stat.getUid();
s.append( ' ' );
s.append( ts );
s.append( ' ' );
// append uid info
ts = stat.getGid();
s.append( ' ' );
s.append( ts );
s.append( ' ' );
// append the inode number in a field of 5
t = Integer.toString( stat.getIno() ) ;
for( int i = 0 ; i < 5 - t.length() ; i ++ )
s.append( ' ' ) ;
s.append( t ) ;
s.append( ' ' ) ;
// append the size in a field of 10
t = Integer.toString( stat.getSize() ) ;
for( int i = 0 ; i < 10 - t.length() ; i ++ )
s.append( ' ' ) ;
s.append( t ) ;
s.append( ' ' ) ;
// append the name
s.append( name ) ;
// print the buffer
System.out.println( s.toString() ) ;
}
}
| ttsugriy/File-System-Simulator | ls.java |
930 | import java.util.ArrayList;
import java.util.HashMap;
public class WP {
private ColEdge[] edge;
private HashMap <Integer, Integer> numEdges = new HashMap<>();
private ArrayList<Integer> sortedNodes = new ArrayList<Integer>();
private int numNodes;
private int upperBound;
private ArrayList<Integer> colourSet = new ArrayList<Integer>();
private HashMap <Integer, Integer> colours = new HashMap<>();
private int nextColour;
private final boolean DEBUG = true;
//constructor
public WP(ColEdge[] edge, int numNodes) {
this.edge = edge;
this.numNodes = numNodes;
initiateColours(colourSet, numNodes);
sortedNodes = sortNodes(edge, numEdges);
compute(edge, colourSet, sortedNodes, colours);
upperBound = count(colours);
//debug infos:
if(DEBUG) {
System.out.println(colours);
System.out.println();
System.out.println(upperBound);
}
}
//.....methods.....................................//
//method that computes the upperBound
public void compute(ColEdge[] edge, ArrayList<Integer> colourSet, ArrayList<Integer> sortedNodes, HashMap <Integer, Integer> colours) {
while(colours.size()!=numNodes) {//run until every node is coloured
colourNextNode(colourSet, sortedNodes,colours);
colourOtherNodes(colourSet, sortedNodes,colours);
}
}
//method that colour the first node of a new colour
public void colourNextNode(ArrayList<Integer> colourSet, ArrayList<Integer> sortedNodes, HashMap <Integer, Integer> colours) {
int node = sortedNodes.get(0);
nextColour = colourSet.get(0);
colours.put(node, nextColour);
sortedNodes.remove(0);
}
//method that colours the rest of the nodes with the same colour of the first node
public void colourOtherNodes(ArrayList<Integer> colourSet, ArrayList<Integer> sortedNodes, HashMap <Integer, Integer> colours) {
for(int i=1; i<= numNodes; i++) {
if(!colours.containsKey(i) && isColourable(i, edge, colours)) {
colours.put(i, nextColour);
}
}
colourSet.remove(0);
}
//method that loops throught the nodes and decides which node is cololourable with the same colour
public boolean isColourable(int node, ColEdge[] edge, HashMap <Integer, Integer> colours ) {
boolean colourable = true;
for(int i=0; i<edge.length; i++) {
int newNode1 = edge[i].u;
int newNode2 = edge[i].v;
if(newNode1==node) {
if(colours.containsKey(newNode2) && colours.get(newNode2)==nextColour) {
colourable = false;
}
}
else if(newNode2==node) {
if(colours.containsKey(newNode1) && colours.get(newNode1)==nextColour) {
colourable = false;
}
}
}
return colourable;
}
//method for creating a set of colours
public void initiateColours(ArrayList<Integer> colours, int numNodes) {
for(int i=0; i<numNodes; i++)
colours.add(i);
}
//method that sorts nodes from highest degree to lowest
public ArrayList<Integer> sortNodes(ColEdge[] edge, HashMap <Integer, Integer> numEdges){
ArrayList<Integer> sortedNodes = new ArrayList<Integer>();
assignNumEdges(numEdges, edge);
int max = 0;
int counter = 0;
for(int j=0; j<numEdges.size(); j++) {
for(int i=1; i<=numEdges.size(); i++) {
int val = numEdges.get(i);
if(max == 0 || val > numEdges.get(max)) {
if(!sortedNodes.contains(i))
max = i;
}
}
sortedNodes.add(max);
max = 0;
}
return sortedNodes;
}
//method that counts how many colours have been used at the end of the algorithm (returns upperBound)
public int count(HashMap <Integer, Integer> colours) {
int max = 0;
for(int i=1; i<=numNodes; i++) {
int num = colours.get(i);
if(num > max)
max = num;
}
return ++max;
}
//method for assigning to each node it's number of edges
public void assignNumEdges(HashMap <Integer, Integer> numEdges, ColEdge[] edge) {
for(int i=1; i<=numNodes; i++) {
numEdges.put(i, 0);
}
for(int i=0; i<edge.length; i++) {
int node1 = edge[i].u;
int node2 = edge[i].v;
int newNum1 = numEdges.get(node1)+1;
int newNum2 = numEdges.get(node2)+1;
numEdges.replace(node1, newNum1);
numEdges.replace(node2, newNum2);
}
}
//method for retrieving the upperBound
public int getUpperBound() {
return upperBound;
}
//return a feasible solution for colouring the graph
public HashMap<Integer, Integer> getPossibleSolution(){
return colours;
}
}
| TijnLogtens/SaveSkelksCat | WP.java |
931 | package org.usfirst.frc.team6400.robot;
import org.usfirst.frc.team6400.robot.commands.BallPickupForward;
import org.usfirst.frc.team6400.robot.commands.BallPickupReverse;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import edu.wpi.first.wpilibj.buttons.Trigger;
import org.usfirst.frc.team6400.robot.commands.OpenGear;
import org.usfirst.frc.team6400.robot.commands.CloseGear;
import org.usfirst.frc.team6400.robot.commands.WinchOn;
import org.usfirst.frc.team6400.robot.commands.WinchOff;
//import org.usfirst.frc.team6400.robot.commands.LowerIntake;
//import org.usfirst.frc.team6400.robot.commands.PosCatForLaunch;
//import org.usfirst.frc.team6400.robot.commands.PosCatForLoad;
//import org.usfirst.frc.team6400.robot.commands.RaiseIntake;
import org.usfirst.frc.team6400.robot.commands.SwitchDirection;
import libraries.XboxController;
/**
* This class is the glue that binds the controls on the physical operator
* interface to the commands and command groups that allow control of the robot.
*/
public class OI {
public XboxController leftController = new XboxController(0);
//UPDATE LIST
//RightTrigger - opengeargobbler
//LeftTrigger - closegeargobbler
//Y - start winch
//B - stop winch
//A - do something
//X - do something
//LeftBumper - do something
//RightBumper - do something
//Start - do something
//Back - do something
public OI() {
leftController.setDeadband(0.2);
//Winch
Button startWinch = new JoystickButton(leftController, XboxController.Y);
//Button autoAim = new JoystickButton(driveController, XboxController.Start);
Button stopWinch = new JoystickButton(leftController, XboxController.X);
startWinch.whenPressed(new startWinch());
stopLatch.whenPressed(new stopWinch());
//Gear
// Button gearOpen = new JoystickButton(leftController, XboxController.RightTrigger);
// Button gearClose = new JoystickButton(leftController, XboxController.LeftTrigger);
// launch.whenPressed(new Launch());
// lockLatch.whenPressed(new LockLatch());
// LaunchGroup.whenPressed(new LaunchGroup());
// //Driving
// Button switchDirection = new JoystickButton(driveController, XboxController.Start);
// switchDirection.whenPressed(new SwitchDirection());
}
}
| erinboyd/manhattanfirstrobotics | IO.java |
932 | /*----------------------------------------------------------------------------*/
/* Copyright (c) 2019 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
/*----------------------------------------------------------------------------*/
package frc.robot;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
import frc.robot.commands.DriverCamera;
import frc.robot.commands.MoveToHeading;
import frc.robot.commands.ShiftFirst;
import frc.robot.commands.ShiftSecond;
import frc.robot.commands.ToggleWinch;
/**
* This class is the glue that binds the controls on the physical operator
* interface to the commands and command groups that allow control of the robot.
*/
public class OI {
//// CREATING BUTTONS
// One type of button is a joystick button which is any button on a
//// joystick.
// You create one by telling it which joystick it's on and which button
// number it is.
// Joystick stick = new Joystick(port);
// Button button = new JoystickButton(stick, buttonNumber);
// There are a few additional built in buttons you can use. Additionally,
// by subclassing Button you can create custom triggers and bind those to
// commands the same as any other Button.
//// TRIGGERING COMMANDS WITH BUTTONS
// Once you have a button, it's trivial to bind it to a button in one of
// three ways:
// Start the command when the button is pressed and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenPressed(new ExampleCommand());
public OI() {
}
// Run the command while the button is being held down and interrupt it once
// the button is released.
// button.whileHeld(new ExampleCommand());
// Start the command when the button is released and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenReleased(new ExampleCommand());
private Joystick driverJoystick = new Joystick(0);
private Joystick operatorJoystick = new Joystick(1);
// public static int camera1Selected = 0;
public void init() {
Button toggleWinchButton = new JoystickButton(operatorJoystick, 4);
toggleWinchButton.whenPressed(new ToggleWinch(Robot.winch));
Button followTargetButton = new JoystickButton(driverJoystick, 3);
followTargetButton.toggleWhenPressed(new MoveToHeading(Robot.drive, RobotMap.ultrasonicSensor, Robot.winch));
Button driverCam = new JoystickButton(driverJoystick, 1);
driverCam.whenReleased(new DriverCamera());
Button shift1 = new JoystickButton(driverJoystick, 5);
shift1.whenPressed(new ShiftFirst(Robot.drive));
Button shift2 = new JoystickButton(driverJoystick, 6);
shift2.whenPressed(new ShiftSecond(Robot.drive));
}
public double getDriverLeftY() {
return driverJoystick.getRawAxis(1);
}
public double getDriverLeftX() {
return driverJoystick.getRawAxis(0);
}
public double getDriverRightY() {
return driverJoystick.getRawAxis(5);
}
public double getDriverRightX() {
return driverJoystick.getRawAxis(4);
}
public double getOperatorRightY() {
return operatorJoystick.getRawAxis(5);
}
public double getOperatorLeftY() {
return operatorJoystick.getRawAxis(1);
}
public boolean getDriverDriveMode() {
return driverJoystick.getRawButton(7);
}
}
| FRCTeam1719/2020Robot | OI.java |
933 | import cs1.Keyboard;
public class Woo
{
// ~~~ INSTANCE VARIABLES ~~~
private static User u;
private static Farm f;
private static int weeksElapsed;
private static String name;
// ~~~~~~~~ METHODS ~~~~~~~~~
public static void startGame()
{
String s;
s = "~~~ Welcome to Cucumber Farm! ~~~\n";
s += "\nWhat is your name, dearest Farmer?";
System.out.println(s);
name = Keyboard.readString(); // user input for username
System.out.println("\nHello, " + name + ".\n");
s = "\n\n~~~ HOW TO PLAY ~~~";
s += "\nYou are the owner of a Cucumber Farm.";
s += "\nTo begin, you will be given $50, and a 2x2 farm";
s += "\nThe game ends when you have no money, or 15 weeks have elapsed.";
s += "\nThe goal of the game is to make as much money as possible in 15 weeks.";
s += "\n\nYou can buy seeds to plant on your own farm.";
s += "\nUnplanted land that you own is marked with \"O.\"";
s += "\nLand you do not own is marked with \"X.\" Plant here = $50 penalty!";
s += "\nThe first row has row number 1; the second, 2; and so on. Same for columns.";
s += "\n\nMore info on types of cucumbers by selecting See more.";
s += "\nCucumbers increase by an increment designated as \"nutrition\".";
s += "\nThey reach their maximum value after their \"ripe duration\", in weeks,";
s += "\n and begin rotting at the same rate afterward.";
s += "\n\nYou may also choose to harvest (sell) your cucumber,";
s += "\n buy a plot of land for $100,";
s += "\n or advance to the next week to watch your cucumbers grow.";
s += "\n\nGood luck.";
System.out.println(s); // print tutorial
} // end startGame method
public static void playGame()
{
String s;
int selection;
System.out.println("\nPress SPACE then ENTER to continue...");
String nextStep = Keyboard.readString();
System.out.println("\n\n===================================\n\n");
printStats(); // print farm & how much money you have
s = "\n" + name + ", what is your next step? Choose wisely.\n";
s += "\t1: Buy a seed and plant it!\n";
s += "\t2: Harvest a cucumber!\n";
s += "\t3: See more about Cucumbers!\n";
s += "\t4: Buy a plot of land for $100!\n";
s += "\t5: Start next week!\n";
System.out.println(s); // print options
selection = Keyboard.readInt(); // user input for options
if (selection == 1) // if user selected 1 ...
plant();
else if (selection == 2)
harvest();
else if (selection == 3)
printCucumberInfo();
else if (selection == 4)
buyLand();
else if (selection == 5) // user chose to start next week
{
weeksElapsed++;
for ( int r = 1; r < f.size()+1; r++) // Matrix.java converts from matrix index --> array index
{
for ( int c = 1; c < f.size()+1; c++)
{
if ( !( f.getCucumber(r,c).equals("X") ) && // only grow Cucumbers
!( f.getCucumber(r,c).equals("O") ) )
((Cucumber) f.getCucumber(r,c)).grow();
} // end inner for-loop
} // end outer for-loop
}
// increment weeksElapsed, back to main menu
else
System.out.println("\nFollow directions!");
// back to main menu, without incrementing weeksElapsed
} // end playGame method
public static void printCucumberInfo()
{
String cucumberInfo;
cucumberInfo = "\nArmenian cucumber:\n";
cucumberInfo += "\tNutrition: 20\n";
cucumberInfo += "\tRipe duration: 5 weeks\n";
cucumberInfo += "\tCost to buy: $30\n";
cucumberInfo += "\nEnglish cucumber:\n";
cucumberInfo += "\tNutrition: 5\n";
cucumberInfo += "\tRipe duration: 2 weeks\n";
cucumberInfo += "\tCost to buy: $3\n";
cucumberInfo += "\nJapanese cucumber:\n";
cucumberInfo += "\tNutrition: 25\n";
cucumberInfo += "\tRipe duration: 6 weeks\n";
cucumberInfo += "\tCost to buy: $50\n";
cucumberInfo += "\nKirby cucumber:\n";
cucumberInfo += "\tNutrition: 10\n";
cucumberInfo += "\tRipe duration: 3 weeks\n";
cucumberInfo += "\tCost to buy: $10\n";
cucumberInfo += "\nPersian cucumber:\n";
cucumberInfo += "\tNutrition: 15\n";
cucumberInfo += "\tRipe duration: 4 weeks\n";
cucumberInfo += "\tCost to buy: $20\n";
System.out.println( cucumberInfo);
} // end printCucumberInfo method
public static void plant()
{
String s, cucumberInfo;
int selection, xcor, ycor;
s = "\n" + name + ", what type of cucumber would you like to plant?\n";
s += "\t1: Armenian (for $30)\n";
s += "\t2: English (for $ 3)\n";
s += "\t3: Japanese (for $50)\n";
s += "\t4: Kirby (for $10)\n";
s += "\t5: Persian (for $20)\n";
s += "\t6: See more info about Cucumbers!\n";
System.out.println(s);
selection = Keyboard.readInt(); // user input for plant selection
if (selection == 1 || selection == 2 || selection == 3 ||
selection == 4 || selection == 5)
{
if ( (selection == 1 && u.getMoney() < 30) || // does user have enough money
(selection == 2 && u.getMoney() < 3 ) || // to plant selected plant?
(selection == 3 && u.getMoney() < 50) ||
(selection == 4 && u.getMoney() < 10) ||
(selection == 5 && u.getMoney() < 20) )
{
System.out.println("You don't have enough money!");
return; // back to main menu, without incrementing weeksElapsed
}
s = "\nIn which row would you like to plant?";
System.out.println(s);
xcor = Keyboard.readInt(); // converting from matrix index to array index handled by Matrix.java
s = "In which column would you like to plant?";
System.out.println(s);
ycor = Keyboard.readInt(); // converting from matrix index to array index handled by Matrix.java
if ( xcor > f.size() || ycor > f.size() ||
xcor <= 0 || ycor <= 0 ) // if selected plot of land out of bounds
{
System.out.println( "\nThis plot of land does not exist in the world!");
return; // back to main menu, without incrementing weeksElapsed
}
else if ( f.getCucumber(xcor, ycor).equals("X") ) // xcor, ycor in bounds of world
{
System.out.println("\nYou don't own land here! $50 penalty!");
u.setMoney( u.getMoney() - 50);
System.out.println("\nYou now have $" + u.getMoney() );
return; // back to main menu, without incrementing weeksElapsed
}
// if you arrive here, xcor and ycor in bounds of world,
// and f.getCucumber(xcor, ycor) is not "X"
// ... if not "O", means cucumber is planted in selected plot
else if ( !( f.getCucumber(xcor, ycor).equals("O") ) )
{
System.out.println("\nYou already planted here!");
return; // back to main menu, without incrementing weeksElapsed
}
if (selection == 1) // selected to plant an Armenian Cucumber ...
{
Cucumber c = new Armenian();
f.plant(xcor, ycor, c);
u.setMoney( u.getMoney() - 30);
System.out.println("\nThat cost you $30. You now have $" + u.getMoney() + ".");
}
else if (selection == 2)
{
Cucumber c = new English();
f.plant(xcor, ycor, c);
u.setMoney( u.getMoney() - 3);
System.out.println("\nThat cost you $3. You now have $" + u.getMoney() + ".");
}
else if (selection == 3)
{
Cucumber c = new Japanese();
f.plant(xcor, ycor, c);
u.setMoney( u.getMoney() - 50);
System.out.println("\nThat cost you $50. You now have $" + u.getMoney() + ".");
}
else if (selection == 4)
{
Cucumber c = new Kirby();
f.plant(xcor, ycor, c);
u.setMoney( u.getMoney() - 10);
System.out.println("\nThat cost you $10. You now have $" + u.getMoney() + ".");
}
else if (selection == 5)
{
Cucumber c = new Persian();
f.plant(xcor, ycor, c);
u.setMoney( u.getMoney() - 20);
System.out.println("\nThat cost you $20. You now have $" + u.getMoney() + ".");
}
} // end selections 1-5 / selections needing xcor and ycor
else if (selection == 6) // see Cucumber info
{
printCucumberInfo();
// back to main menu, without incrementing weeksElapsed
}
else // selection not in [1,6]
{
System.out.println("\nFollow directions!");
// back to main menu, without incrementing weeksElapsed
}
} // end plant method
public static void harvest()
{
int xcor, ycor;
System.out.println( "\nThe plant you would like to harvest...");
System.out.println( "\tis in which row?");
xcor = Keyboard.readInt(); // converting from matrix index to array index handled by Matrix.java
System.out.println( "\tis in which column?");
ycor = Keyboard.readInt(); // converting from matrix index to array index handled by Matrix.java
if ( xcor > f.size() || ycor > f.size() ||
xcor <= 0 || ycor <= 0 ) // chosen plot in bounds?
System.out.println( "\nThis plot of land does not exist in the world!");
// back to main menu, without incrementing weeksElapsed
else if ( f.getCucumber(xcor, ycor).equals("X") || f.getCucumber(xcor, ycor).equals("O") )
System.out.println("\nYou don't have anything planted here!");
// back to main menu, w/o incrementing weeksElapsed
else
{
int oldMoney = u.getMoney();
u.setMoney( u.getMoney() + f.harvest(xcor, ycor) );
// harvest() in Farm.java returns the value of plant being harvested
// resets plot to "O" and adds money to user's bank
System.out.println("\nYou earned $" + ( u.getMoney() - oldMoney ) + "!");
}
} // end harvest method
public static void buyLand()
{
int xcor, ycor;
if (u.getMoney() >= 100) // has enough money to buy land?
{
System.out.println( "\nThe plot of land you would like to buy...");
System.out.println( "\tis in which row?");
xcor = Keyboard.readInt(); // converting from matrix index to array index handled in Matrix.java
System.out.println( "\tis in which column?");
ycor = Keyboard.readInt(); // converting from matrix index to array index handled in Matrix.java
if ( xcor > f.size() || ycor > f.size() ||
xcor <= 0 || xcor <= 0 )
System.out.println( "\nThis plot of land does not exist in the world!");
// back to main menu, without incrementing weeksElapsed
else if ( !(f.getCucumber(xcor, ycor).equals("X")) ) // xcor, ycor within bounds of array
System.out.println( "\nYou already own this plot of land!");
// back to main menu, without incrementing weeksElapsed
else
{
u.setMoney( u.getMoney() - 100 );
System.out.println("\nPurchase successful! $100 has been deducted.");
f.plant(xcor, ycor, "O");
}
}
else
System.out.println("\nYou don't have enough money!");
// back to main menu, w/o incrementing weeksElapsed
} // end buyLand method
public static void endGame()
{
System.out.println("\n\n===================================\n\n");
if ( !(weeksElapsed < 15) ) // if game ended b/c 15 weeks elapsed, print following msg
System.out.println("\nTime's up! Your time as a Farmer is over.");
if ( !( u.getMoney() > 0) ) // if game ended b/c no money left, print following msg
System.out.println("\nYou ran out of money! Probably better to run a farm in a Communist country instead.");
System.out.println("\nHere is the final resting state of your farm:\n");
System.out.println(f);
System.out.println("\n\n" + "You had $" + u.getMoney() + " when you died.");
} // end endGame method
public static void printStats()
{
System.out.println(f);
System.out.println( "You have $" + u.getMoney() + ".");
System.out.println( "\nThere are " + (15 - weeksElapsed) + " weeks left in the game.\n");
} // end showStats method
public static void main(String[] args)
{
u = new User();
f = new Farm(5);
startGame();
while ( weeksElapsed < 15 &&
u.getMoney() > 0 ) // keep game running
playGame();
// does not update weeksElapsed here b/c will be updated when chosen by user
// reach here when while-loop conditions not met
endGame();
} // end main method
} // end Woo class
| wu-rymd/LosPepinos | Woo.java |
934 | /******************************************************************************
Copyright (c) 2016, Cormac Flanagan (University of California, Santa Cruz)
and Stephen Freund (Williams College)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the names of the University of California, Santa Cruz
and Williams College nor the names of its contributors may be
used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
******************************************************************************/
package tools.fasttrack_long;
import acme.util.Util;
import rr.state.ShadowVolatile;
import tools.util.LongVectorClock;
public class FTVolatileState extends LongVectorClock {
// inherited values field: protected by peer.
// RR ensures that peer is held when volatile access handler
// is called.
private final ShadowVolatile peer;
public FTVolatileState(ShadowVolatile peer, int size) {
super(size);
this.peer = peer;
}
public ShadowVolatile getPeer() {
return peer;
}
@Override
public synchronized String toString() {
return String.format("[peer %s: %s]", Util.objectToIdentityString(peer), super.toString());
}
}
| PLaSSticity/SmartTrack-pldi20 | tmp.java |
936 | /*
* Class Name and Description:
* Pet.java is the class which represents a pet at the vet
* hospital.
*
* Ideally, this class should be used in conjunction with
* a user interface (e.g. Hospital.java). However, it can also
* be used in your own program as long as you also include
* the 'Doctor' class (as pets can be assigned doctors).
*
* Please note that bad inputs will simply be rejected if they
* are invalid. It is the responsibility of the primary class
* (e.g. Hospital) to ask for new inputs if invalid.
*/
public class Pet {
private String name, size, type;
private int age;
private double weight;
private Doctor doctor; // Define as class rather than simply a name so that doctor
// name changes will not dissassociate pets from their assigned
// doctors. Everything will point to a central memory location.
/**
* Default constructor
*
* No inputs/preconditions
* All instance variables will be initialised as null
*/
public Pet() {} // Initialise as null rather than blank, as
// that is more semantically correct
/**
* Detailed constructor
*
* @param name pet name to be assigned
* @param size pet size to be assigned
* @param type pet type to be assigned
* @param age age of the pet
* @param weight weight of the pet
* @param doctor doctor to be assigned as the pet's doctor
* All instance variables will be initialised to the specified values
*/
public Pet(String name, String size, String type, int age, double weight, Doctor doctor) {
setName(name); // Use setters rather than direct assignment
setSize(size); // so that inputs are checked
setType(type);
setAge(age);
setWeight(weight);
setDoctor(doctor);
}
/**
* Prints all of the pet's properties (name, size, type, age, weight, doctor)
*
* No inputs/preconditions, returns nothing
*/
public void printDetails() {
System.out.println(" Name: " + getName());
System.out.println(" Size: " + getSize());
System.out.println(" Type: " + getType());
System.out.println(" Age: " + getAge());
System.out.println("Weight: " + getWeight() + "kg");
if (doctor != null) {
System.out.println("Doctor: " + doctor.getName());
}
else {
System.out.println("Doctor: none assigned");
}
System.out.println();
}
/**
* Gets the pet's type
*
* No inputs/preconditions
* @return pet type (dog or cat)
*/
public String getType() {
return type;
}
/**
* Sets the pet's type to the value specified
*
* @param type pet type to be assigned - should be either 'dog' or 'cat'
* Returns nothing; 'type' attribute will be set to input
*/
public void setType(String type) {
if (type.equalsIgnoreCase("dog") ||
type.equalsIgnoreCase("cat")) {
this.type = type;
}
}
/**
* Gets the pet's size
*
* No inputs/preconditions
* @return pet size (small, medium or large)
*/
public String getSize() {
return size;
}
/**
* Sets the pet's size to the value specified
*
* @param size size value to be assigned - should be either 'small', 'medium' or 'large'
* Returns nothing; 'size' attribute will be set to input
*/
public void setSize(String size) {
if (size.equalsIgnoreCase("small") ||
size.equalsIgnoreCase("medium") ||
size.equalsIgnoreCase("large")) {
this.size = size;
}
}
/**
* Gets the pet's name
*
* No inputs/preconditions
* @return pet name (exactly as it was inputted into the system)
*/
public String getName() {
return name;
}
/**
* Sets the pet's name to the value specified
*
* @param name pet name to be assigned - any format will be accepted - must not be empty
* Returns nothing; 'name' attribute will be set to input
*/
public void setName(String name) {
if (name.trim().length() > 0) {
this.name = name;
}
}
/**
* Gets the pet's weight in kilograms
*
* No inputs/preconditions
* @return pet weight (will be a positive double)
*/
public double getWeight() {
return weight;
}
/**
* Sets the pet's weight to the value specified
*
* @param weight weight value to be assigned - should be positive
* Returns nothing; 'weight' attribute will be set to input
*/
public void setWeight(double weight) {
if (weight > 0) {
this.weight = weight;
}
}
/**
* Gets the pet's age in years
*
* No inputs/preconditions
* @return pet age (will be a positive integer)
*/
public int getAge() {
return age;
}
/**
* Sets the pet's age to the value specified
*
* @param age age value to be assigned - should be positive
* Returns nothing; 'age' attribute will be set to input
*/
public void setAge(int age) {
if (age >= 0) {
this.age = age;
}
}
/**
* Gets the pet's doctor object
*
* No inputs/preconditions
* @return doctor object, or 'none' if no doctor is assigned
*/
public Doctor getDoctor() {
return doctor;
}
/**
* Assigns the specified doctor as the pet's doctor
*
* @param doctor doctor object to be assigned, or null to reset
* Returns nothing; 'doctor' attribute will be set to input
*/
public void setDoctor(Doctor doctor) {
this.doctor = doctor;
}
/* ******** Helper Methods ******** */
/**
* Determines whether the pet has a doctor assigned.
* Returns 'true' if a doctor is assigned, 'false' otherwise.
*
* No inputs/preconditions
* @return whether a doctor has been assigned (boolean value)
*/
public boolean hasDoctor() {
return getDoctor() != null;
}
/**
* Determines whether the pet is overweight, based on size and weight
*
* No inputs/preconditions
* @return whether this pet is overweight (boolean value)
*/
public boolean isOverweight() {
if (getType().equals("cat")) {
return ((getSize().equals("small") && getWeight() > 4) ||
(getSize().equals("medium") && getWeight() > 6) ||
(getSize().equals("large") && getWeight() > 8));
}
else { // Dog
return ((getSize().equals("small") && getWeight() > 6) ||
(getSize().equals("medium") && getWeight() > 9) ||
(getSize().equals("large") && getWeight() > 12));
}
}
/**
* Returns a string representation of the pet
* This format is developed to be compatiable with
* the specification 'HospitalManagement.txt'
*
* No inputs/preconditions
* @return a string representing the object
*/
public String toString() {
return "type " + getType() + "\n" +
"size " + getSize() + "\n" +
"name " + getName() + "\n" +
"weight " + getWeight() + "\n" +
"age " + getAge() + "\n" +
"doctor " + (hasDoctor() ? getDoctor().getName() : "no doctor assigned");
}
/**
* Determines whether this pet is equal to the other pet
* Returns 'true' if all attributes match (ignoring case)
*
* @param otherPet other pet object to be compared
* @return whether this pet is equal to otherPet (boolean value)
*/
public boolean equals(Pet otherPet) {
return (getType().equalsIgnoreCase(otherPet.getType()) &&
getSize().equalsIgnoreCase(otherPet.getSize()) &&
getName().equalsIgnoreCase(otherPet.getName()) &&
getWeight() == otherPet.getWeight() &&
getAge() == otherPet.getAge() &&
getDoctor() == otherPet.getDoctor());
}
}
| angussidney/vet-hospital-management | Pet.java |
937 | /* *****************************************************************************
* Name: Dumitru Hanciu
* Date: 14.01.2019
* Description: SAP
**************************************************************************** */
import edu.princeton.cs.algs4.Digraph;
import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.Queue;
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;
import java.util.ArrayList;
import java.util.Arrays;
public class SAP {
private Digraph D;
private int V, ancestor, next, length;
// constructor takes a digraph (not necessarily a DAG)
public SAP(Digraph G) {
if (G == null) throw new IllegalArgumentException();
V = G.V();
D = new Digraph(G);
this.ancestor = -1;
this.length = -1;
this.next = -1;
}
// a common ancestor of v and w that participates
// in a shortest ancestral path; -1 if no such path
public int ancestor(int v, int w) {
length(v, w);
return ancestor;
}
// a common ancestor that participates in shortest ancestral path; -1 if no such path
public int ancestor(Iterable<Integer> v, Iterable<Integer> w) {
if (v == null || w == null) throw new IllegalArgumentException();
length(v, w);
return ancestor;
}
// length of shortest ancestral path between v and w; -1 if no such path
public int length(int v, int w) {
ArrayList<Integer> vArray = new ArrayList<Integer>(Arrays.asList(v));
ArrayList<Integer> wArray = new ArrayList<Integer>(Arrays.asList(w));
return length(vArray, wArray);
}
// length of shortest ancestral path between any vertex in v and any vertex in w; -1 if no such path
public int length(Iterable<Integer> v, Iterable<Integer> w) {
if (v == null || w == null) throw new IllegalArgumentException();
validate(v);
validate(w);
for (int x : v)
for (int y : w)
if (x == y) {
ancestor = x;
return 0;
}
ancestor = -1;
length = -1;
Queue<Integer> queueV = new Queue<Integer>();
boolean[] markedV = new boolean[V];
int[] distToV = new int[V];
Queue<Integer> queueW = new Queue<Integer>();
boolean[] markedW = new boolean[V];
int[] distToW = new int[V];
for (int x : v) {
markedV[x] = true;
queueV.enqueue(x);
}
for (int y : w) {
markedW[y] = true;
queueW.enqueue(y);
}
while (!queueV.isEmpty() || !queueW.isEmpty()) {
if (!queueV.isEmpty()) {
int adjV = queueV.dequeue();
for (int nextV : D.adj(adjV)) {
int distV = distToV[adjV] + 1;
if (!markedV[nextV] && (length >= distToV[adjV] || length == -1)) {
distToV[nextV] = distV;
markedV[nextV] = true;
queueV.enqueue(nextV);
}
if (markedW[nextV] && (length >= distV + distToW[nextV] || length == -1)) {
ancestor = nextV;
this.next = adjV;
length = distV + distToW[nextV];
}
}
}
if (!queueW.isEmpty()) {
int adjW = queueW.dequeue();
for (int nextW : D.adj(adjW)) {
int distW = distToW[adjW] + 1;
if (!markedW[nextW] && (length >= distToW[adjW] || length == -1)) {
distToW[nextW] = distW;
markedW[nextW] = true;
queueW.enqueue(nextW);
}
if (markedV[nextW] && (length >= distW + distToV[nextW] || length == -1)) {
ancestor = nextW;
this.next = adjW;
length = distW + distToV[nextW];
}
}
}
}
return length;
}
private void validate(Iterable<Integer> i) {
for (Integer v : i)
if (v == null) throw new IllegalArgumentException();
else validate(v);
}
private void validate(int v) {
if (v < 0 || v >= V) throw new IllegalArgumentException();
}
public static void main(String[] args) {
In in = new In(args[0]);
Digraph G = new Digraph(in);
SAP sap = new SAP(G);
while (!StdIn.isEmpty()) {
int v = StdIn.readInt();
int w = StdIn.readInt();
int length = sap.length(v, w);
int ancestor = sap.ancestor(v, w);
StdOut.printf("length = %d, ancestor = %d\n", length, ancestor);
}
}
}
| prog-ai/SemanticAI | SAP.java |
938 | /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tappas;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
/**
*
* @author Hector del Risco - [email protected] & Pedro Salguero - [email protected]
*/
public class GO extends AppObject {
static public enum GOCat {
BP, MF, CC
}
static public String GOSLIM_GENERIC = "goslim_generic";
static String BP = "GO:0008150";
static String MF = "GO:0003674";
static String CC = "GO:0005575";
// category flags
static public int FLG_BP = 0x0001;
static public int FLG_MF = 0x0002;
static public int FLG_CC = 0x0004;
// ancestor flags
static int FLG_GOSLIM = 0x0001;
static int FLG_PARTOF = 0x0002;
static int FLG_MASK = 0x00FF;
static int FLG_ROOT = 0x0100;
HashMap<String, String> goSubsets = new HashMap<>();
HashMap<String, NamespaceInfo> goNamespaces = new HashMap<>();
int idxBP = -1;
int idxMF = -1;
int idxCC = -1;
HashMap<String, GOTerm> goTerms = new HashMap<>();
ArrayList<HashMap<String, GOTerm>> goCategoryTerms = new ArrayList<>();
public GO() {
super(null, null);
}
//
// Public Interface
//
public String getCategoryNamespace(int catidx) {
String catns = "";
for(String namespace : goNamespaces.keySet()) {
if(goNamespaces.get(namespace).idx == catidx) {
catns = namespace;
break;
}
}
return catns;
}
/*
public HashMap<String, NamespaceInfo> getNamespaces() {
if(goTerms.isEmpty())
loadGOTerms(Paths.get(app.data.getAppGOTermsFilepath()));
return goNamespaces;
}*/
public GOTerm getGOTermInfo(String term) {
GOTerm gt = null;
if(goTerms.isEmpty())
loadGOTerms(Paths.get(app.data.getAppGOTermsFilepath()));
if(goTerms.containsKey(term))
gt = goTerms.get(term);
return gt;
}
// Even though the function is allowing multiple categories, the application will support displaying only one at a time
// this minimizes clutter and avoids top/bottom-edgeArrow issue with dagre-d3
public static enum Show { Id, Name, Both }
public GraphResult buildGraph(GOCat cat, int maxLevel, ArrayList<String> lstGOTerms, double width, double height, Show show) {
String goSlim = GOSLIM_GENERIC;
GraphResult result = new GraphResult(0, "", false, false, false);
String htmlNodes = "";
String htmlEdges = "";
if(goTerms.isEmpty())
loadGOTerms(Paths.get(app.data.getAppGOTermsFilepath()));
HashMap<String, HashMap<String, TermInfo>> hmGraph = new HashMap<>();
HashMap<String, Integer> hmNodes = new HashMap<>();
ArrayList<HashMap<String, Object>> lstGlobalLevelTerms = new ArrayList<>();
// there is an issue with the fact that multiple terms share the same ancestors so the distance is different for each
ArrayList<Integer> lstDistances = new ArrayList<>();
for(int i = 0; i < goNamespaces.size(); i++) //lstDistances(i)!!!
lstDistances.add(0);
int idx;
ArrayList<Integer> lstNewDistances = new ArrayList<>();
ArrayList<Integer> lstMaxDistances = new ArrayList<>();
for(Integer dist : lstDistances)
lstMaxDistances.add(dist);
for(String term : lstGOTerms) {
ArrayList<ArrayList<HashMap<String, Object>>> lstCatLevelTerms = new ArrayList<>();
for(int i = 0; i < goNamespaces.size(); i++)
lstCatLevelTerms.add(new ArrayList(0));
lstNewDistances.clear();
for(Integer dist : lstDistances)
lstNewDistances.add(dist);
getTermGraph(term, hmGraph, cat, goSlim, lstNewDistances, lstCatLevelTerms, false);
idx = 0;
for(Integer dist : lstNewDistances) {
if(dist > lstMaxDistances.get(idx))
lstMaxDistances.set(idx, dist);
idx++;
}
int catidx = 0;
for(ArrayList<HashMap<String, Object>> lstLevelTerms : lstCatLevelTerms) {
Collections.reverse(lstLevelTerms);
int level = 0;
for(HashMap<String, Object> hmLevel : lstLevelTerms) {
// must be incremental adding so only add one
if(lstGlobalLevelTerms.size() < (level +1))
lstGlobalLevelTerms.add(new HashMap<>());
HashMap<String, Object> hmOutLevel = lstGlobalLevelTerms.get(level);
//System.out.println("Level " + level + " for " + getCategoryNamespace(catidx) + ": " + hmLevel.toString());
for(String levelTerm : hmLevel.keySet())
hmOutLevel.put(levelTerm, null);
level++;
}
catidx++;
}
}
// if the user does not request bp then bp is false!!!
// to get a true answer need to traverse all terms for all categories - that's expensive!
//System.out.println("Final max distances: ");
for(String namespace : goNamespaces.keySet()) {
int md = lstMaxDistances.get(goNamespaces.get(namespace).idx);
if(md > 0) {
if(goNamespaces.get(namespace).term.equals(BP))
result.bp = true;
else if(goNamespaces.get(namespace).term.equals(MF))
result.mf = true;
else if(goNamespaces.get(namespace).term.equals(CC))
result.cc = true;
}
//System.out.println("Max distance for " + namespace + ": " + md);
}
//System.out.println("Global level terms: ");
int level = 0;
//for(HashMap<String, Object> hmLevel : lstGlobalLevelTerms) {
// System.out.println("Level " + level + ": " + hmLevel.toString());
// level++;
//}
ArrayList<HashMap<String, Object>> lstFinalLevelTerms = new ArrayList<>();
for(int i = 0; i < lstGlobalLevelTerms.size(); i++)
lstFinalLevelTerms.add(new HashMap<>());
level = 0;
// need to either update lstGlobalLevelTerms or xfer to new list - some issues with both approaches
for(HashMap<String, Object> hmLevel : lstGlobalLevelTerms) {
HashMap<String, Object> hmFinal = lstFinalLevelTerms.get(level);
for(String term : hmLevel.keySet()) {
hmFinal.put(term, null);
// the terms are moved to the next level in lstFinalLevelTerms but we are checkng lstFinalLevelTerms!
moveOtherTermChildrenUp(term, lstGlobalLevelTerms, lstFinalLevelTerms, level+1);
}
level++;
}
int len = lstFinalLevelTerms.size();
boolean rmvflg = true;
do {
if(len > 1) {
HashMap<String, Object> hmLast = lstFinalLevelTerms.get(len-1);
HashMap<String, Object> hmPrev = lstFinalLevelTerms.get(len-2);
for(String term : hmLast.keySet()) {
if(!hmPrev.containsKey(term)) {
rmvflg = false;
break;
}
}
if(rmvflg)
lstFinalLevelTerms.remove(len-1);
len = lstFinalLevelTerms.size();
}
else
rmvflg = false;
} while(rmvflg);
result.maxLevel = lstFinalLevelTerms.size() - 1;
int node = 0;
for(String term : hmGraph.keySet()) {
boolean skip = true;
int skipLevel = 0;
for(HashMap<String, Object> hmLevel : lstFinalLevelTerms) {
if(hmLevel.containsKey(term)) {
skip = false;
break;
}
if(++skipLevel > maxLevel)
break;
}
if(skip)
continue;
String name = getGOTermInfo(term).name;
String label = "";
if(name.length() > 20) {
ArrayList<String> lines = new ArrayList<>();
String fields[] = name.split(" ");
for(String word : fields) {
if((label.length() + word.length()) < 22)
label += label.isEmpty()? word : " " + word;
else {
if(word.length() > 25) {
String subFields[] = word.split(",");
for(String subWord : subFields) {
if((label.length() + subWord.length()) < 22)
label += label.isEmpty()? subWord : "," + subWord;
else {
if(!label.isEmpty())
lines.add(label);
label = subWord;
}
}
}
else {
if(!label.isEmpty())
lines.add(label);
label = word;
}
}
}
if(!lines.isEmpty()) {
String lastLine = label;
label = "";
// pad it with a couple of spaces, the text will overflow the rectangle some times while zooming (d3js)
for(String line : lines)
label += label.isEmpty()? line + " " : "\\n" + line + " ";
label += "\\n" + lastLine;
}
}
else
label = name;
String nodeClass = "";
String slim = "";
GOTerm gt = getGOTermInfo(term);
if(gt.isRoot())
nodeClass += nodeClass.isEmpty()? "type-RootNode" : " " + "type-RootNode";
if(gt.lstSubset.contains(goSlim)) {
slim = ", slim: \"" + goSlim + "\"";
nodeClass += nodeClass.isEmpty()? "type-SlimNode" : " " + "type-SlimNode";
}
if(lstGOTerms.contains(term))
nodeClass += nodeClass.isEmpty()? "type-EndNode" : " " + "type-EndNode";
if(!nodeClass.isEmpty())
nodeClass = ", class: \"" + nodeClass + "\"";
String tooltip = term + "\\n" + gt.namespace + (slim.isEmpty()? "" : " - " + goSlim);
tooltip += "\\n" + wrapLine(gt.def.replace("\"", ""), 60);
switch(show) {
case Id:
label = term + " ";
break;
case Name:
label += " ";
break;
case Both:
label = term + "\\n" + label + " ";
break;
}
htmlNodes += "{id: " + node + ", args: " + "{label: \"" + label + "\"" + nodeClass + slim + ", tooltip: \"" + tooltip + "\"}},\n";
hmNodes.put(term, node++);
}
for(String term : hmGraph.keySet()) {
if(hmNodes.containsKey(term)) {
int nodeidx = hmNodes.get(term);
HashMap<String, TermInfo> hmLinks = hmGraph.get(term);
GOTerm gt;
for(String subTerm : hmLinks.keySet()) {
if(hmNodes.get(subTerm) != null) {
gt = getGOTermInfo(term); //hmLinks.get(subTerm);
if(gt.hmPartOf.containsKey(subTerm))
htmlEdges += "{source: " + nodeidx + ", target: " + hmNodes.get(subTerm) + ", args: {class: 'edgePathPartOf', lineInterpolate: 'basis'}},\n";
else
htmlEdges += "{source: " + nodeidx + ", target: " + hmNodes.get(subTerm) + ", args: {lineInterpolate: 'basis'}},\n";
}
}
}
}
String htmlGraph = app.data.getFileContentFromResource("/tappas/scripts/GODAG.html");
// edge arrows are lost when using the base tag (internal library reference) - so don't use for now
String htmlRankSep = "60";
if(node > 200)
htmlRankSep = "100";
else if(node > 50)
htmlRankSep = "80";
htmlGraph = htmlGraph.replace("<<ranksep>>", htmlRankSep);
htmlGraph = htmlGraph.replace("<<d3nodes>>", htmlNodes);
htmlGraph = htmlGraph.replace("<<d3edges>>", htmlEdges);
htmlGraph = htmlGraph.replace("<<width>>", width + "");
htmlGraph = htmlGraph.replace("<<height>>", height + "");
result.html = htmlGraph;
return result;
}
public HashMap<String, TermInfo> getTermAncestors(String term) {
HashMap<String, TermInfo> hmTermAncestors = new HashMap<>();
if(goTerms.isEmpty())
loadGOTerms(Paths.get(app.data.getAppGOTermsFilepath()));
if(goTerms.containsKey(term))
getTermAncestors(term, hmTermAncestors, "", 0, true, true);
return hmTermAncestors;
}
public HashMap<String, HashMap<String, Object>> getSlims(ArrayList<String> terms, String slim) {
if(slim == null || slim.isEmpty())
slim = GOSLIM_GENERIC;
HashMap<String, HashMap<String, Object>> hmSlims = new HashMap<>();
if(goTerms.isEmpty())
loadGOTerms(Paths.get(app.data.getAppGOTermsFilepath()));
for(String term : terms) {
if(goTerms.containsKey(term))
getTermSlims(term, term, hmSlims, slim);
else {
System.out.println("Warning: GO term '" + term + "' not found.");
if(!hmSlims.containsKey("TERM_NOT_FOUND"))
hmSlims.put("TERM_NOT_FOUND", new HashMap<>());
hmSlims.get("TERM_NOT_FOUND").put(term, null);
}
}
return hmSlims;
}
public HashMap<String, HashMap<String, Object>> getPartsOf(ArrayList<String> terms) {
HashMap<String, HashMap<String, Object>> hmPartsOf = new HashMap<>();
if(goTerms.isEmpty())
loadGOTerms(Paths.get(app.data.getAppGOTermsFilepath()));
for(String term : terms) {
if(goTerms.containsKey(term))
getTermPartsOf(term, term, hmPartsOf);
else {
System.out.println("Warning: GO term '" + term + "' not found.");
if(!hmPartsOf.containsKey("TERM_NOT_FOUND"))
hmPartsOf.put("TERM_NOT_FOUND", new HashMap<>());
hmPartsOf.get("TERM_NOT_FOUND").put(term, null);
}
}
return hmPartsOf;
}
public HashMap<String, Object> getChildren(HashMap<String, Object> hmAncestors, int catidx, boolean allowAncestorChild) {
HashMap<String, Object> hmChildren = new HashMap<>();
HashMap<String, GOTerm> hmTerms = goCategoryTerms.get(catidx);
hmAncestors.keySet().stream().forEach((ancestor) -> {
hmTerms.keySet().stream().forEach((term) -> {
if(allowAncestorChild || !hmAncestors.containsKey(term)) {
GOTerm gt = hmTerms.get(term);
if (gt.hmIsA.containsKey(ancestor) || gt.hmPartOf.containsKey(ancestor)) {
hmChildren.put(term, null);
}
}
});
});
return hmChildren;
}
//
// Internal Functions
//
private void moveOtherTermChildrenUp(String term, ArrayList<HashMap<String, Object>> lstGlobalLevelTerms,
ArrayList<HashMap<String, Object>> lstFinalLevelTerms, int level) {
for(int chkLevel = level; chkLevel < lstGlobalLevelTerms.size(); chkLevel++) {
if(lstGlobalLevelTerms.get(chkLevel).containsKey(term)) {
int nxtLevel = chkLevel + 1;
if(nxtLevel < lstGlobalLevelTerms.size()) {
HashMap<String, Object> hmChildren = lstGlobalLevelTerms.get(nxtLevel);
for(String child : hmChildren.keySet()) {
GOTerm gt = getGOTermInfo(child);
if(gt.hmIsA.containsKey(term) || gt.hmPartOf.containsKey(term)) {
//System.out.println("Moved child " + child + " for term " + term + " to level " + level);
lstFinalLevelTerms.get(level).put(child, null);
lstGlobalLevelTerms.get(level).put(child, null); // need to update this for calling func to process
}
}
}
}
}
}
// builds a GOterm -> list of ancestors with distance from term and GOslim|PartOf flags
private void getTermAncestors(String term, HashMap<String, TermInfo> hmTermAncestors, String slim, int distance,
boolean isPartOf, boolean originalTerm) {
if(goTerms.isEmpty())
loadGOTerms(Paths.get(app.data.getAppGOTermsFilepath()));
if(goTerms.containsKey(term)) {
GOTerm gt = goTerms.get(term);
int flags = isPartOf? FLG_PARTOF : 0;
if(slim != null && !slim.isEmpty()) {
if(gt.lstSubset.contains(slim))
flags |= FLG_GOSLIM;
}
if(gt.lstIsA.isEmpty() && !gt.obsolete)
flags |= FLG_ROOT;
if(!originalTerm)
hmTermAncestors.put(term, new TermInfo(gt.name, distance, flags, gt.catidx));
for(String isa : gt.lstIsA)
getTermAncestors(isa, hmTermAncestors, slim, distance+1, false, false);
for(String pof : gt.lstPartOf)
getTermAncestors(pof, hmTermAncestors, slim, distance+1, true, false);
}
}
// builds a GOterm -> list of ancestors with distance from term and GOslim|PartOf flags
// term -> immediate ancestors
private boolean isCatIncluded(GOCat cat, int catidx) {
boolean result = false;
if(cat != null) {
if(cat.equals(GOCat.BP) && catidx == idxBP)
result = true;
else if(cat.equals(GOCat.MF) && catidx == idxMF)
result = true;
else if(cat.equals(GOCat.CC) && catidx == idxCC)
result = true;
}
return result;
}
// pass ArrayList<HashMap<String, Object>> -
// add HM to list at each level for each category
// once all terms done (at calling func), reverse all the lists
// consolidate all the diff cat terms into a new list for each level of the reversed lists
private void getTermGraph(String term, HashMap<String, HashMap<String, TermInfo>> hmGraph, GOCat cat, String slim,
ArrayList<Integer> lstDistances, ArrayList<ArrayList<HashMap<String, Object>>> lstCatLevelTerms, boolean isPartOf) {
if(goTerms.containsKey(term)) {
// get term info and check if category included
GOTerm gt = goTerms.get(term);
if(!isCatIncluded(cat, gt.catidx))
return;
int distance = lstDistances.get(gt.catidx);
ArrayList<HashMap<String, Object>> lstLevelTerms = lstCatLevelTerms.get(gt.catidx);
// must be incremental adding so only add one
if(lstLevelTerms.size() < (distance +1))
lstLevelTerms.add(new HashMap<>());
HashMap<String, Object> hmLevel = lstLevelTerms.get(distance);
hmLevel.put(term, null);
// set flags
int flags = isPartOf? FLG_PARTOF : 0;
if(slim != null && !slim.isEmpty()) {
if(gt.lstSubset.contains(slim))
flags |= FLG_GOSLIM;
}
if(gt.lstIsA.isEmpty() && !gt.obsolete)
flags |= FLG_ROOT;
// update distance to max value, could have been set at a lower level - maybe remove later!!!
int maxdist = distance;
HashMap<String, TermInfo> hmTerm;
if(!hmGraph.containsKey(term)) {
hmTerm = new HashMap<>();
hmGraph.put(term, hmTerm);
}
else {
hmTerm = hmGraph.get(term);
for(TermInfo ti : hmTerm.values()) {
if(ti.distance > maxdist)
maxdist = ti.distance;
break;
}
}
// Note: term info is for the 'term' and it's added to every child
TermInfo ti = new TermInfo(maxdist, flags, gt.catidx);
// save all direct ancestors
for(String isa : gt.lstIsA)
hmTerm.put(isa, ti);
for(String pof : gt.lstPartOf)
hmTerm.put(pof, ti);
// traverse ancestors
int idx = 0;
ArrayList<Integer> lstNewDistances = new ArrayList<>();
ArrayList<Integer> lstMaxDistances = new ArrayList<>();
for(Integer dist : lstDistances)
lstMaxDistances.add(dist);
for(String isa : gt.lstIsA) {
lstNewDistances.clear();
for(Integer dist : lstDistances)
lstNewDistances.add(dist);
lstNewDistances.set(gt.catidx, lstNewDistances.get(gt.catidx) + 1);
getTermGraph(isa, hmGraph, cat, slim, lstNewDistances, lstCatLevelTerms, false);
idx = 0;
for(Integer dist : lstNewDistances) {
if(dist > lstMaxDistances.get(idx))
lstMaxDistances.set(idx, dist);
idx++;
}
}
for(String pof : gt.lstPartOf) {
lstNewDistances.clear();
for(Integer dist : lstDistances)
lstNewDistances.add(dist);
lstNewDistances.set(gt.catidx, lstNewDistances.get(gt.catidx) + 1);
getTermGraph(pof, hmGraph, cat, slim, lstNewDistances, lstCatLevelTerms, true);
idx = 0;
for(Integer dist : lstNewDistances) {
if(dist > lstMaxDistances.get(idx))
lstMaxDistances.set(idx, dist);
idx++;
}
}
idx = 0;
for(Integer dist : lstMaxDistances) {
if(dist > lstDistances.get(idx))
lstDistances.set(idx, dist);
idx++;
}
}
}
// builds a GOslims -> terms having that GOslim
private void getTermSlims(String term, String ancestor, HashMap<String, HashMap<String, Object>> hmSlims, String slim) {
if(goTerms.containsKey(ancestor)) {
GOTerm gt = goTerms.get(ancestor);
if(gt.lstSubset.contains(slim))
{
if(!hmSlims.containsKey(ancestor))
hmSlims.put(ancestor, new HashMap<>());
hmSlims.get(ancestor).put(term, null);
}
for(String isa : gt.lstIsA)
getTermSlims(term, isa, hmSlims, slim);
}
}
// builds a Part -> terms being a part of it
private void getTermPartsOf(String term, String ancestor, HashMap<String, HashMap<String, Object>> hmPartsOf) {
if(goTerms.containsKey(ancestor)) {
GOTerm gt = goTerms.get(ancestor);
if(!gt.lstPartOf.isEmpty())
{
for(String part : gt.lstPartOf) {
if(!hmPartsOf.containsKey(ancestor))
hmPartsOf.put(ancestor, new HashMap<>());
// unlike with isA, we do not traverse the 'part of' term
// http://geneontology.org/page/ontology-relations#isa
hmPartsOf.get(ancestor).put(part, null);
}
}
for(String isa : gt.lstIsA)
getTermPartsOf(term, isa, hmPartsOf);
}
}
private void loadGOTerms(Path filepath) {
try {
idxBP = -1;
idxMF = -1;
idxCC = -1;
goSubsets.clear();
goNamespaces.clear();
goTerms.clear();
goCategoryTerms.clear();
if(Files.exists(filepath)) {
List<String> lines = Files.readAllLines(filepath, StandardCharsets.UTF_8);
int idx = 0;
int cnt = lines.size();
boolean terms = false;
for(String line : lines) {
if(line.trim().equals(GOTerm.GOTERMDEF)) {
terms = true;
GOTerm gt = GOTerm.getGOTerm(lines, cnt, idx);
if(gt != null)
goTerms.put(gt.id, gt);
}
if(!terms) {
GOSubset gs = GOSubset.getGOSubset(line);
if(gs != null)
goSubsets.put(gs.id, gs.name);
}
idx++;
}
// we have the GO terms loaded, now build specificity levels for each root
// start out by getting all the root terms
//ArrayList<String> lstRoot = new ArrayList<>();
for(String term : goTerms.keySet()) {
GOTerm gt = goTerms.get(term);
//Get ancestors by each term
//ArrayList<String> all = new ArrayList<>();
//all.addAll(gt.lstIsA);
//all.addAll(gt.lstPartOf);
//Key GO:XXXX - List: A lot of GO:YYYYY
//ances.put(gt.id,all);
if(!gt.namespace.isEmpty()) {
if(!goNamespaces.containsKey(gt.namespace)) {
goNamespaces.put(gt.namespace, new NamespaceInfo(goNamespaces.size()));
goCategoryTerms.add(new HashMap<>());
}
int catidx = goNamespaces.get(gt.namespace).idx;
gt.catidx = catidx;
goCategoryTerms.get(catidx).put(term, gt);
if(gt.lstIsA.isEmpty() && !gt.obsolete) {
//lstRoot.add(term);
HashMap<String, Object> hm = new HashMap<>();
hm.put(term, null);
goNamespaces.get(gt.namespace).term = term;
}
}
}
//SAVE HASHMAP ANCES INVALID CHARACTERS!!! SAVE IN PROJECT!!!!
String ascen_path = app.data.getAppGOTermsAncesFilepath();
//ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(ascen_path));
// we have to calculate ancestors for each go.obo update - detect when you run for first time the new version of the app
if(!Files.exists(Paths.get(ascen_path)) || !app.checkAppLastVersion()) {
PrintWriter writer = new PrintWriter(ascen_path, "UTF-8");
for(String term : goTerms.keySet()) {
GOTerm gt = goTerms.get(term);
//Get ancestors by each term
ArrayList<String> all = new ArrayList<>();
all.addAll(gt.lstIsA);
all.addAll(gt.lstPartOf);
writer.println(term + "\t" + all.toString());
}
writer.close();
}
System.out.println("Finish");
//System.out.println("GO Namespaces/Categories: ");
//for(String namespace : goNamespaces.keySet())
// System.out.println(" " + namespace + "(" + goNamespaces.get(namespace).idx + ") " + goNamespaces.get(namespace).term);
//int catidx = 0;
//for(String cat : goNamespaces.keySet())
// System.out.println("Total GO terms for " + cat + ": " + goCategoryTerms.get(catidx++).size());
//System.out.println("Total GO terms: " + goTerms.size());
}
}
catch (Exception e) {
app.logError("Unable to load GO terms definition file '" + filepath.toString() + "': " + e.getMessage());
goSubsets.clear();
goNamespaces.clear();
goTerms.clear();
goCategoryTerms.clear();
}
for(String namespace : goNamespaces.keySet()) {
NamespaceInfo ni = goNamespaces.get(namespace);
if(ni.term.equals(BP))
idxBP = ni.idx;
else if(ni.term.equals(MF))
idxMF = ni.idx;
else if(ni.term.equals(CC))
idxCC = ni.idx;
}
}
//
// Static Functions
//
static public String getShortName(String name, int maxlen) {
String label = "";
if(name.length() > maxlen) {
String subName = abbrevNameWords(name);
ArrayList<String> lines = new ArrayList<>();
String fields[] = subName.split(" ");
for(String word : fields) {
if((label.length() + word.length()) < maxlen)
label += label.isEmpty()? word : " " + word;
else {
// this assumes maxlen is in the 20s, change if needed
// it is done to minimize ending up with dup names being displayed
if(label.isEmpty() || label.length() < 20)
label += label.isEmpty()? word : " " + word;
label += "...";
break;
}
}
}
else
label = name;
return label;
}
static public String abbrevNameWords(String name) {
String subName = name.replaceAll("Negative regulation", "-reg");
subName = subName.replaceAll("negative regulation", "-reg");
subName = subName.replaceAll("Positive regulation", "+reg");
subName = subName.replaceAll("positive regulation", "+reg");
subName = subName.replaceAll("Negative", "Neg.");
subName = subName.replaceAll("negative", "neg.");
subName = subName.replaceAll("Positive", "Pos.");
subName = subName.replaceAll("positive", "pos.");
subName = subName.replaceAll("Regulation", "Reg.");
subName = subName.replaceAll("regulation", "reg.");
return subName;
}
static public String wrapLine(String line, int maxlen) {
String newLine = "";
if(line.length() > maxlen) {
String nline = "";
String fields[] = line.split(" ");
for(String word : fields) {
if((nline.length() + word.length()) < maxlen)
nline += nline.isEmpty()? word : " " + word;
else {
if(!nline.isEmpty()) {
newLine += newLine.isEmpty()? nline : "\\n" + nline;
nline = word;
}
else
newLine += newLine.isEmpty()? word : "\\n" + word;
}
}
if(!nline.isEmpty())
newLine += newLine.isEmpty()? nline : "\\n" + nline;
}
else
newLine = line;
// check for bracketed references at the end and remove them
if(!newLine.isEmpty()) {
if(newLine.charAt(newLine.length() - 1) == ']') {
int pos = newLine.lastIndexOf("[");
if(pos != -1)
newLine = newLine.substring(0, pos);
}
}
return newLine;
}
//
// Data Classes
//
public static class GOSubset {
private final static String SUBSETDEF = "subsetdef:";
public String id;
public String name;
GOSubset(String id, String name) {
this.id = id;
this.name = name;
}
public static GOSubset getGOSubset(String def) {
GOSubset gs = null;
if(isGOSubsetDef(def)) {
String[] fields = def.split(" ");
int pos = def.indexOf(" \"");
gs = new GOSubset(fields[1].trim(), def.substring(pos).replaceAll("[\"]", "").trim());
}
return gs;
}
public static boolean isGOSubsetDef(String def) {
boolean result = false;
String[] fields = def.split(" ");
int pos = def.indexOf(" \"");
if(fields.length >= 3 && fields[0].trim().equals(SUBSETDEF) && pos != -1)
result = true;
return result;
}
}
public static class GOTerm {
public final static String GOTERMDEF = "[Term]";
public String id;
public String name;
public String namespace;
public String def;
public boolean obsolete;
public int catidx;
public HashMap<String, Object> hmIsA;
public HashMap<String, Object> hmPartOf;
public ArrayList<String> lstIsA;
public ArrayList<String> lstPartOf;
public ArrayList<String> lstSubset;
GOTerm(String id) {
this.id = id;
this.obsolete = false;
this.catidx = -1;
this.hmIsA = new HashMap<>();
this.hmPartOf = new HashMap<>();
this.lstIsA = new ArrayList<>();
this.lstPartOf = new ArrayList<>();
this.lstSubset = new ArrayList<>();
}
public static GOTerm getGOTerm(List<String> lines, int cnt, int idx) {
GOTerm gt = null;
if(lines.get(idx).trim().equals(GOTERMDEF)) {
for(++idx; idx < cnt; idx++) {
String line = lines.get(idx).trim();
if(line.isEmpty() || line.equals(GOTERMDEF))
break;
KeyValuePair kvp = KeyValuePair.getKeyValuePair(line);
if(kvp != null) {
if(gt == null) {
if(kvp.key.equals("id"))
gt = new GOTerm(kvp.value);
else {
System.out.print("ERROR: NO ID for Go [Term]");
break;
}
}
else {
// other possible keys to capture: alt_id, consider, intersection_of, relationship
switch(kvp.key) {
case "name":
gt.name = kvp.value;
break;
case "namespace":
gt.namespace = kvp.value;
break;
case "def":
gt.def = kvp.value;
break;
case "is_obsolete":
gt.obsolete = Boolean.valueOf(kvp.value.toLowerCase());
break;
case "is_a":
int pos = kvp.value.indexOf(" ");
if(pos != -1) {
gt.lstIsA.add(kvp.value.substring(0, pos));
gt.hmIsA.put(kvp.value.substring(0, pos), null);
}
else {
gt.lstIsA.add(kvp.value);
gt.hmIsA.put(kvp.value, null);
}
break;
case "subset":
gt.lstSubset.add(kvp.value);
break;
case "relationship":
// get 'part of' relationships
if(PartOf.isPartOf(kvp.value)) {
gt.lstPartOf.add(PartOf.getPartOf(kvp.value));
gt.hmPartOf.put(PartOf.getPartOf(kvp.value), null);
}
break;
}
}
}
}
}
return gt;
}
public boolean isRoot() {
return(lstIsA.isEmpty() && !obsolete);
}
}
public static class KeyValuePair {
String key, value;
public KeyValuePair(String key, String value) {
this.key = key;
this.value = value;
}
private static KeyValuePair getKeyValuePair(String line) {
KeyValuePair kvp = null;
int pos = line.indexOf(": ");
if(pos != -1)
kvp = new KeyValuePair(line.substring(0, pos).trim(), line.substring(pos+2).trim());
return kvp;
}
}
public static class PartOf {
static String PART_OF = "part_of ";
static String PART_OF_SEPARATOR = " ! ";
String id;
public static String getPartOf(String relationship) {
String po = "";
if(isPartOf(relationship)) {
String[] fields = relationship.substring(PART_OF.length()).split(PART_OF_SEPARATOR);
po = fields[0].trim();
}
return po;
}
private static boolean isPartOf(String relationship) {
boolean result = false;
if(relationship.startsWith(PART_OF)) {
String[] fields = relationship.substring(PART_OF.length()).split(PART_OF_SEPARATOR);
if(fields.length == 2)
result = true;
}
return result;
}
}
public static class TermInfo {
int distance, flags, catidx;
String name;
public TermInfo(int distance, int flags, int catidx) {
this.name = "";
this.distance = distance;
this.flags = flags;
this.catidx = catidx;
}
public TermInfo(String name, int distance, int flags, int catidx) {
this.name = name;
this.distance = distance;
this.flags = flags;
this.catidx = catidx;
}
public boolean isRoot() {
return ((flags & FLG_ROOT) != 0);
}
public boolean isGOslim() {
return ((flags & FLG_GOSLIM) != 0);
}
public boolean isPartOf() {
return ((flags & FLG_PARTOF) != 0);
}
}
public static class TermGroupInfo {
int maxDistance;
ArrayList<String> levels;
public TermGroupInfo(int maxDistance) {
this.maxDistance = maxDistance;
this.levels = new ArrayList<>();
}
}
public static class NamespaceInfo {
int idx;
String term;
public NamespaceInfo(int idx) {
this.idx = idx;
this.term = "";
}
}
public static class GraphResult {
boolean bp, mf, cc;
int maxLevel;
String html;
public GraphResult(int maxLevels, String html, boolean bp, boolean mf, boolean cc) {
this.maxLevel = maxLevels;
this.html = html;
this.bp = bp;
this.mf = mf;
this.cc = cc;
}
}
}
| ConesaLab/tappAS | GO.java |
939 | /**
* class thart represent 1 bit of number
*/
public class Bit{
/**
* Value tha represented by a 1bit String
*/
protected String value;
/**
* Class constructor
* @param bilangan biner sebagai data
*/
public Bit(String value){
this.value=value;
}
/**
* Class constructor
* @param value decimal value as the data
* @param bitLength the length of the bit
*/
public Bit(int value,int bitLength){
this.value=this.toBinary(value,bitLength);
}
/**
* Getter for the value
* @return string berupa bilangan biner
*/
public String getValue(){
return this.value;
}
/**
* Setter for the value attributes
* @param value bilangan biner baru
*/
public void setValue(String value){
this.value=value;
}
/**
* Method to change the decimal number to binary number
* @return the decimal number of the given binary number
*/
public int toDecimal(){
int res=0;
for(int i=this.value.length()-1;i>=0;i--){
if(this.value.charAt(i)=='1'){
res+=Math.pow(2,this.value.length()-1-i);
}
}
return res;
}
/**
* Method to change the decimal number to binary number
* @param val decimal number that will be changed top binary number
* @param bitLength the length of binary number
* @return String value that represent the binary number of the decimal that has been provided by the user
*/
public String toBinary(int val,int bitLength){
String str="";
while(val>0&&str.length()<bitLength){
str=(val%2)+str;
val/=2;
}
while(str.length()<bitLength){
str='0'+str;
}
return str;
}
}
| kpratama24/SAP | Bit.java |
941 |
package seniorproject;
/**
*
* @author Richard
* TM is an item that teaches a Pokemon a move. TM inherits from Product.
*/
public class TM extends Product {
private final String mAbility;
/**
* Constructor for a TM
* @param name Name of TM
* @param ID ID
* @param description Description
* @param price Price
* @param stock Amount in stock
* @param ability name of the ability (not the TM!)
*/
public TM(String name, String ID, String description, int price, int stock, String ability) {
super(name, ID, description, price, stock);
mAbility = ability;
}
/**
* Getter for a TM's ability
* @return ability that TM teaches
*/
public String getAbility () {
return mAbility;
}
}
| jalesco/PokemonMarket | TM.java |
942 |
/*
In a binary tree, the root node is at depth 0, and children of each depth k node are at depth k+1.
Two nodes of a binary tree are cousins if they have the same depth, but have different parents.
We are given the root of a binary tree with unique values, and the values x and y of two different nodes in the tree.
Return true if and only if the nodes corresponding to the values x and y are cousins.
*/
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public boolean isCousins(TreeNode root, int x, int y) {
return find(root, x, y, 0) == -2;
}
// -1 means couldn't find that
// return the level of node x or y
// the lca is found, return level_x == level_y?
private int find(TreeNode root, int x, int y, int level) {
if (root == null) return -1;
if (root.val == x || root.val == y) return level;
int left = find(root.left, x, y, level+1);
int right = find(root.right, x, y, level+1);
if (left != -1 && right != -1) {
if (left == right && root.left.val != x && root.left.val != y) return -2;
return -3;
}
if (left != -1) return left;
else return right;
}
}
| wxping715/LeetCode | 993.java |
943 | class MyQueue {
Stack<Integer> input=new Stack<>();
Stack<Integer> output = new Stack<>();
/** Initialize your data structure here. */
public MyQueue() {
}
/** Push element x to the back of queue. */
public void push(int x) {
input.push(x);
}
/** Removes the element from in front of queue and returns that element. */
public int pop() {
peek();
return output.pop();
}
/** Get the front element. */
public int peek() {
if(output.empty())
while(!input.empty()) output.push(input.pop());
return output.peek();
}
/** Returns whether the queue is empty. */
public boolean empty() {
return input.empty()&&output.empty();
}
}
/**
* Your MyQueue object will be instantiated and called as such:
* MyQueue obj = new MyQueue();
* obj.push(x);
* int param_2 = obj.pop();
* int param_3 = obj.peek();
* boolean param_4 = obj.empty();
*/ | fztfztfztfzt/leetcode | 232.java |
944 | import java.util.*;
class Solution {
public boolean checkSubarraySum(int[] nums, int k) {
int prefixMod = 0;
HashMap<Integer, Integer> modSeen = new HashMap<>();
modSeen.put(0, -1);
for (int i = 0; i < nums.length; i++) {
prefixMod = (prefixMod + nums[i]) % k;
if (modSeen.containsKey(prefixMod)) {
// ensures that the size of subarray is at least 2
if (i - modSeen.get(prefixMod) > 1) {
return true;
}
} else {
// mark the value of prefixMod with the current index.
modSeen.put(prefixMod, i);
}
}
return false;
}
}
| kalongn/LeetCode_Solution | 523.java |
945 | /**
* Go extends Space
* Go doesn't do anything, its just a special space that has
* a chance card that points to it.
*/
public class Go extends Space
{
/**
* Constructs a Go space by calling the space constructor
* @param name the name of the space
* @param location the location of the space
*/
public Go(String name, int location)
{
super(name, location);
}
/**
* Overrides the performRole in space
* but Go doesn't do anything specific
* @param player the player to perform the role on
*/
@Override
public void performRole(Player player) {}
}
| bwalcott12/MonopolyJr | Go.java |
947 | 404: Not Found | pappukumar35/Leet_code | So.java |
948 | import java.math.*;
import java.io.*;
import java.security.*;
/*
ALGORITHM
==========
STEP 1 > pick 2 large prime numbers , say 'p' and 'q'
STEP 2 > Compute their product, say n = p * q
STEP 3 > Compute PHI(n) as PHI(n) = (p-1) * (q-1)
STEP 4 > pick a value 'e' such that GCD(e,PHI(n))=1 , here 'e' is the encrytion key
STEP 5 > calculate 'd' as d = e^(-1) mod PHI(n) , here 'd' is the decryption key
STEP 6 > now we have our PublicKey=(e,n) and PrivateKey=(d,n)
STEP 7 > Encryption : CipherText = (Message)^e mod n
STEP 8 > Decryption : PlainMsg = (CipherText)^d mod n
*/
class ED_helper
{
private int bitlen,r;
private BigInteger p,q,n,phi,e,d;
ED_helper(int bit)
{
bitlen=bit;//number of bits strong we want our encryption to be
SecureRandom r=new SecureRandom();//we use this because its a 128bit rand_generator,hence low chances of repeats.
//<================================< STEP 1 >======================================>
//SYNTAX
//BigInteger(int bitLength, int certainty, Random rnd)
//we want to generate encryption keys as a product of p and q hence each of p and q much contain half as many digits
//as bitlen.And the second value to the BigInt tells us we want to generate primes with 100% certainity using 'r'
p=new BigInteger(bitlen/2,100,r);
q=new BigInteger(bitlen/2,100,r);
System.out.println("P value :"+p+"\n\n\n "+"Q value="+q);
//<================================< STEP 2 >======================================>
n=p.multiply(q);//BigInteger Multiplication
//<================================< STEP 3 >======================================>
phi=p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE));
//<================================< STEP 4 >======================================>
e=new BigInteger(bitlen/2,100,r);//BigInteger will take care of GCD() <UNDERATED STEP>
//<================================< STEP 5 >======================================>
d=e.modInverse(phi);//e^-1 then % phi
//<================================< STEP 6 >======================================>
System.out.println("\n\n\nValue of D :"+d+"\n\n\nValue of E : "+e);//Displaying keys
}
//<================================< STEP 7 >======================================>
public BigInteger encrypt(BigInteger Msg)
{
//CipherText = (Msg)^e mod n
return(Msg.modPow(e,n));
}
//<================================< STEP 8 >======================================>
public BigInteger decrypt(BigInteger Msg)
{
//DecodedMsg = (Ciphext)^d mod n
return(Msg.modPow(d,n));
}
}
//Main Driver Class to demonstrate functionalities implemented by the above class
class ED
{
public static void main(String args[]) throws IOException
{
//Create object and pass the bit length
ED_helper rsa=new ED_helper(1200);
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String text1,text2;
BigInteger Pt,Ct;
//Input Message from user
System.out.println("\n\nEnter Plaintext :");
text1=br.readLine();
//pass the input message to the encrypt method to obtain cipher text
Pt=new BigInteger(text1.getBytes());
Ct=rsa.encrypt(Pt);
System.out.println("\n\nCiperText is : "+Ct);
//Pass the CipherText to the decrypt method to obtain original message
Pt=rsa.decrypt(Ct);
text2=new String(Pt.toByteArray());
System.out.println("\n\n\nData after decrypt :"+text2);
}
}
| Pythonista7/ComputerNetworksLab | ED.java |
949 | /*Problem-1
* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
* Find the sum of all the multiples of 3 or 5 below 1000.
*/
import java.util.Scanner;
class E1
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int x=0;x<t;x++)
{
long n=sc.nextLong();
n--;
long n3=n/3;
long n5=n/5;
long n15=n/15;
n3=3*n3*(n3+1)/2;
n5=5*n5*(n5+1)/2;
n15=15*n15*(n15+1)/2;
System.out.println(n3+n5-n15);
}
}
}
| Goku1999/Project-Euler | E1.java |
950 | /*What is the smallest positive number that is evenly divisible(divisible with no remainder) by all of the numbers from 1 to N?*/
import java.util.Scanner;
class E5
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
int r[]=new int[t];
for(int x=0;x<t;x++)
{
int n=sc.nextInt();
int ar[]=new int[n-1];
for(int y=0;y<n-1;y++)
{
ar[y]=y+2;
}
boolean once=false;
int i=2;
r[x]=1;
while(!isOne(ar))
{
for(int y=0;y<n-1;y++)
{
if(ar[y]%i==0)
{
ar[y]/=i;
once=true;
}
}
if(once)
{
once=false;
r[x]*=i;
}
else
{
i++;
}
}
}
for(int x=0;x<t;x++)
{
System.out.println(r[x]);
}
}
public static boolean isOne(int ar[])
{
for(int x=0;x<ar.length;x++)
{
if(ar[x]!=1)
{
return false;
}
}
return true;
}
}
| Goku1999/Project-Euler | E5.java |
951 | // Copyright (C) 2021 Jarmo Hurri, Diana Ginzburg, Gabriel Dearden,
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
public class CX extends Crossover
{
public char[] crossover (char[] parentA, char[] parentB)
{
char[] offspring = new char [parentA.length];
boolean[] assigned = new boolean [parentA.length];
offspring [0] = parentA [0];
assigned [0] = true;
char c = parentB [0];
int i;
while ((i = find (c, parentA)) != 0)
{
offspring [i] = c;
assigned [i] = true;
c = parentB [i];
}
// copy remaining from parentB
for (int j = 0; j < offspring.length; j++)
if (!assigned [j])
offspring [j] = parentB [j];
return offspring;
}
private int find (char c, char[] parent)
{
for (int i = 0; i < parent.length; i++)
if (parent [i] == c)
return i;
return (-1);
}
}
| hurrja/ib-cs-tsp-ga | CX.java |
952 | // Copyright (C) 2021 Jarmo Hurri, Diana Ginzburg, Gabriel Dearden,
// Askar Tuiushev
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
public class OX extends Crossover
{
char[] crossover (char[] parentA, char[] parentB)
{
// indices of subsequence copied directly from parent A
int[] ASubInds = new int [2];
RandomUtils.randomSortedIntegerPair (parentA.length, ASubInds);
int aStartInd = ASubInds [0], aEndInd = ASubInds [1];
char[] offspring = new char [parentA.length];
int numAssigned = 0;
int offspringInd;
// copy subsequence from parent A
for (offspringInd = aStartInd; offspringInd <= aEndInd; offspringInd++)
{
offspring [offspringInd] = parentA [offspringInd];
numAssigned++;
}
int bInd = aEndInd + 1; // index in parent B
while (numAssigned < parentA.length)
{
// if past end of offspring array, cycle to beginning
offspringInd %= parentA.length;
bInd %= parentA.length;
boolean bGeneUsed;
do
{
bGeneUsed = false;
for (int j = aStartInd; !bGeneUsed && j <= aEndInd; j++)
if (parentB [bInd] == parentA [j])
bGeneUsed = true;
if (bGeneUsed)
{
bInd++;
bInd %= parentA.length;
}
} while (bGeneUsed);
offspring [offspringInd] = parentB [bInd];
numAssigned++;
bInd++;
offspringInd++;
}
return offspring;
}
}
| hurrja/ib-cs-tsp-ga | OX.java |
953 | import java.io.*;
import java_cup.runtime.*;
/**
* Main program to test the parser.
*
* There should be 2 command-line arguments:
* 1. the file to be parsed
* 2. the output file into which the AST built by the parser should be
* unparsed
* The program opens the two files, creates a scanner and a parser, and
* calls the parser. If the parse is successful, the AST is unparsed.
*/
public class P5 {
FileReader inFile;
private PrintWriter outFile;
private static PrintStream outStream = System.err;
public static final int RESULT_CORRECT = 0;
public static final int RESULT_SYNTAX_ERROR = 1;
public static final int RESULT_TYPE_ERROR = 2;
public static final int RESULT_OTHER_ERROR = -1;
/**
* P5 constructor for client programs and testers. Note that
* users MUST invoke {@link setInfile} and {@link setOutfile}
*/
public P5(){
}
/**
* If we are directly invoking P5 from the command line, this
* is the command line to use. It shouldn't be invoked from
* outside the class (hence the private constructor) because
* it
* @param args command line args array for [<infile> <outfile>]
*/
private P5(String[] args){
//Parse arguments
if (args.length < 2) {
String msg = "please supply name of file to be parsed"
+ "and name of file for unparsed version.";
pukeAndDie(msg);
}
try{
setInfile(args[0]);
setOutfile(args[1]);
} catch(BadInfileException e){
pukeAndDie(e.getMessage());
} catch(BadOutfileException e){
pukeAndDie(e.getMessage());
}
}
/**
* Source code file path
* @param filename path to source file
*/
public void setInfile(String filename) throws BadInfileException{
try {
inFile = new FileReader(filename);
} catch (FileNotFoundException ex) {
throw new BadInfileException(ex, filename);
}
}
/**
* Text file output
* @param filename path to destination file
*/
public void setOutfile(String filename) throws BadOutfileException{
try {
outFile = new PrintWriter(filename);
} catch (FileNotFoundException ex) {
throw new BadOutfileException(ex, filename);
}
}
/**
* Perform cleanup at the end of parsing. This should be called
* after both good and bad input so that the files are all in a
* consistent state
*/
public void cleanup(){
if (inFile != null){
try {
inFile.close();
} catch (IOException e) {
//At this point, users already know they screwed
// up. No need to rub it in.
}
}
if (outFile != null){
//If there is any output that needs to be
// written to the stream, force it out.
outFile.flush();
outFile.close();
}
}
/**
* Private error handling method. Convenience method for
* @link pukeAndDie(String, int) with a default error code
* @param error message to print on exit
*/
private void pukeAndDie(String error){
pukeAndDie(error, -1);
}
/**
* Private error handling method. Prints an error message
* @link pukeAndDie(String, int) with a default error code
* @param error message to print on exit
*/
private void pukeAndDie(String error, int retCode){
outStream.println(error);
cleanup();
System.exit(-1);
}
/** the parser will return a Symbol whose value
* field is the translation of the root nonterminal
* (i.e., of the nonterminal "program")
* @return root of the CFG
*/
private Symbol parseCFG(){
try {
parser P = new parser(new Yylex(inFile));
return P.parse();
} catch (Exception e){
return null;
}
}
public int process(){
Symbol cfgRoot = parseCFG();
ProgramNode astRoot = (ProgramNode)cfgRoot.value;
if (ErrMsg.getErr()) {
return P5.RESULT_SYNTAX_ERROR;
}
astRoot.nameAnalysis(); // perform name analysis
if(ErrMsg.getErr()) {
return P5.RESULT_SYNTAX_ERROR;
}
astRoot.typeCheck();
if(ErrMsg.getErr()) {
return P5.RESULT_TYPE_ERROR;
}
astRoot.unparse(outFile, 0);
return P5.RESULT_CORRECT;
}
public void run(){
int resultCode = process();
if (resultCode == RESULT_CORRECT){
cleanup();
return;
}
switch(resultCode){
case RESULT_SYNTAX_ERROR:
pukeAndDie("Syntax error", resultCode);
case RESULT_TYPE_ERROR:
pukeAndDie("Type checking error", resultCode);
default:
pukeAndDie("Type checking error", RESULT_OTHER_ERROR);
}
}
private class BadInfileException extends Exception{
private static final long serialVersionUID = 1L;
private String message;
public BadInfileException(Exception cause, String filename) {
super(cause);
this.message = "Could not open " + filename + " for reading";
}
@Override
public String getMessage(){
return message;
}
}
private class BadOutfileException extends Exception{
private static final long serialVersionUID = 1L;
private String message;
public BadOutfileException(Exception cause, String filename) {
super(cause);
this.message = "Could not open " + filename + " for reading";
}
@Override
public String getMessage(){
return message;
}
}
public static void main(String[] args){
P5 instance = new P5(args);
instance.run();
}
}
| jkoritzinsky/Moo-Type-Analysis | P5.java |
954 | /*
* mGoban - GUI for Go
* Copyright (C) 2007, 2009, 2010 sanpo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import app.App;
import javax.swing.SwingUtilities;
public class Go {
private static void appInit(String[] args){
App app = App.getInstance();
app.start(args);
}
public static void main(final String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
appInit(args);
}
});
}
} | msanpopo/mgoban | Go.java |
955 | /*******************************************************************************************************************
* InputRoutinesWithScannerV4.java
* Author: David A. Freitag
* CIS 129 - Programming and Problem Solving I
* Pima Community College
******************************************************************************************************************
* This program gets input from a user using Scanner.
* Use at your own risk. Test your program well. No guarantee this code works in all situations.
******************************************************************************************************************/
import java.util.Scanner;
public class IR4 {
//Putting the Scanner object here makes it global so it does not have to be passed to modules.
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
/** Main () -
* This program demonstrates various generalized input routines.
* This program also demonstrates generating a random number.
* @param args Arguments can be passed to this program but they are not used.
*/
do {
String stringData = getString("Please enter a word or two");
System.out.println("This is what you entered: " + stringData);
int intData = getInteger("Please enter an integer");
System.out.println("This is what you entered: " + intData);
intData = getIntegerBetweenLowAndHigh("Please enter a number between 1 and 12", 1, 12, "Error: Outside Range");
System.out.println("This is what you entered: " + intData);
//Generating random numbers.
int numberOfRandomNbrs = getIntegerBetweenLowAndHigh("How many random numbers do you want to generate? (1 to 20)", 1, 20, "Error: Outside Range");
int highNumber = getIntegerGTE("What is the highest random number to be generated?", 1);
for (int i = 0; i < numberOfRandomNbrs; i++) {
System.out.println("random number " + (i + 1) + ": " + getRandomNumber(0, highNumber));
}
} while (getYorN("\nDo you want to start over? (y/n)"));
//close the Scanner
closeScanner();
System.out.println("Program Terminating Normally");
}//end of main
public static void displayGoodbye(){
System.out.println("Goodbye!");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// GENERALIZED VALIDATION FUNCTIONS
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** Gets an integer greater than and less than the supplied parameters.
* Rejects null entries, any number of spaces, and non-numbers.
* @param msg is the text that will be displayed the user to ask them to enter a value.
* @param low is the lowest acceptable input value.
* @param high is the highestt acceptable input value.
* @return Returns an int from the keyboard.
*/
public static int getIntegerBetweenLowAndHigh(String msg, int low, int high, String errorMsg) {
int number = getInteger(msg);
while (number < low || number > high) {
System.err.println(errorMsg);
number = getInteger(msg);
}
return number;
}
/** Gets an integer greater than the supplied parameter.
* Rejects null entries, any number of spaces, and non-numbers.
* @param msg is the text that will be displayed the user to ask them to enter a value.
* @param low is the highest unacceptable input value.
* @return Returns an int from the keyboard.
*/
public static int getIntegerGT(String msg, int low, String errorMsg) {
int number = getInteger(msg);
while (number <= low) {
System.err.println(errorMsg);
number = getInteger(msg);
}
return number;
}
/** Gets an integer greater than or equal to the supplied parameter.
* Rejects null entries, any number of spaces, and non-numbers.
* @param msg is the text that will be displayed the user to ask them to enter a value.
* @param low is the lowest acceptable input value.
* @return Returns an int from the keyboard.
*/
public static int getIntegerGTE(String msg, int low) {
int number = getInteger(msg);
while (number < low) {
System.err.println("Invalid input. Number is out of range.");
number = getInteger(msg);
}
return number;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// GENERALIZED INPUT FUNCTIONS
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/** Gets a String from the keyboard. Rejects null entry or any number of spaces.
* @param msg is the text that will be displayed the user to ask them to enter a value.
* @return Returns a String from the keyboard.
*/
public static String getString(String msg) {
String answer = "";
System.out.println(msg);
try {
answer = keyboard.nextLine();
}
catch (Exception e) {
System.err.println("Error reading input from user. Ending program.");
System.exit(-1);
}
while (answer.replace(" ", "").equals("")) {
System.err.println("Error: Missing input.");
try {
System.out.println(msg);
answer = keyboard.nextLine();
}
catch (Exception e) {
System.err.println("Error reading input from user. Ending program.");
System.exit(-1);
}
}
return answer;
}
//------------------------------------------------------------------------------------------------------------------
/** Gets an Integer from the keyboard. Rejects null, spaces and non-integers.
* @param msg is the text that will be displayed the user to ask them to enter a number.
* @return Returns an int from the keyboard.
*/
public static int getInteger(String msg) {
System.out.println(msg);
while (!keyboard.hasNextInt()) {
keyboard.nextLine();
System.err.println("Invalid integer. Try again.");
}
int number = keyboard.nextInt();
keyboard.nextLine(); //flushes the buffer
return number;
}
//------------------------------------------------------------------------------------------------------------------
/** Gets a Double from the keyboard. Rejects null, spaces and non-numbers.
* @param msg is the text that will be displayed the user to ask them to enter a number.
* @return Returns a double from the keyboard.
*/
public static double getDouble(String msg) {
System.out.println(msg);
while (!keyboard.hasNextDouble()) {
keyboard.nextLine();
System.err.println("Invalid number. Try again.");
}
double number = keyboard.nextDouble();
keyboard.nextLine(); //flushes the buffer
return number;
}
//------------------------------------------------------------------------------------------------------------------
/** Gets a Yes or No answer from the keyboard. Calls getString to rejects null input and spaces.
* @param msg is the text that will be displayed the user.
* @return Returns a boolean value. True = yes; False = no.
*/
public static boolean getYorN(String msg) {
String answer = getString(msg);
while (answer.compareToIgnoreCase("y") != 0
&& answer.compareToIgnoreCase("yes") != 0
&& answer.compareToIgnoreCase("n") != 0
&& answer.compareToIgnoreCase("no") != 0) {
if (answer.replace(" ", "").equals("")) {
System.err.println("Error: Missing y/n input.");
} else {
if (answer.compareToIgnoreCase("y") != 0
&& answer.compareToIgnoreCase("yes") != 0
&& answer.compareToIgnoreCase("n") != 0
&& answer.compareToIgnoreCase("no") != 0) {
System.err.println("Error: Unexpected input.");
}
}
answer = getString(msg);
}
if (answer.compareToIgnoreCase("y") == 0
|| answer.compareToIgnoreCase("yes") == 0) {
return true;
}
else {
return false;
}
}
//------------------------------------------------------------------------------------------------------------------
/** Closes the scanner.
*/
public static void closeScanner() {
try {
if(keyboard != null) {
keyboard.close();
}
}
catch (Exception e) { // (Exception) catches all errors java might throw here
System.err.println("Error closing reader.");
}
}
//------------------------------------------------------------------------------------------------------------------
/** Generates a random number between low and high, inclusive.
* @param low is the smallest number that will be randomly generated.
* @param high is the largest number that will be randomly generated.
* @return Returns the random number as an integer.
*/
public static int getRandomNumber (int low, int high) {
return (int)(Math.random() * ((high + 1) - low)) + low;
}
}//end of class | JohnnyPoblano/Hangman_Game | IR4.java |
956 | import java.util.ArrayList;
import java.util.Scanner;
/**
*
* @author Antonio Decastro <[email protected]>
*
*/
/**
*
* This is an abstract class that the Bird.java, Cat.java, and Dog.java classes inherit from
*
*/
public class Pet {
public enum Genders{ MALE, FEMALE }
/**
* Each line of the pet txt files are separated into their individual elements and those elements are added to this ArrayList
*/
protected ArrayList<String> petInfo = new ArrayList<>();
protected int ID;
protected String name;
protected double weight;
protected String owner;
protected Genders gender;
protected String species;
/**
* getID method: <br />
* Returns an int the ID number of this pet
* @return int of this pet's ID number
*/
public int getID() {
return ID;
}
/**
* getName method: <br />
* Returns String of this pet's name
* @return String of this pet's name
*/
public String getName() {
return name;
}
/**
* getWeight method: <br />
* Returns this pet's weight as a double
* @return Double of this pet's weight
*/
public double getWeight() {
return weight;
}
/**
* getOwner method: <br />
* Returns String of this pet's owner's name
* @return String of this pet's owner's name
*/
public String getOwner() {
return owner;
}
/**
* getGender method: <br />
* Returns gender of this pet as a Genders enum object
* @return Genders object of this pet's gender
*/
public Genders getGender() {
return gender;
}
/**
* getSpecies method: <br />
* Returns a String of the name of this pet's species
* @return String of this pet's species
*/
public String getSpecies() {
return species;
}
/**
* setID method: <br />
* Sets the ID number of this pet
* @param id int of this pet's ID number
*/
public void setID(int id) {
ID = id;
}
/**
* setName method: <br />
* Sets the name of this pet
* @param monicker String of this pet's name
*/
public void setName(String monicker) {
name = monicker;
}
/**
* setWeight method: <br />
* Sets the weight of this pet
* @param heft Double of the number of kilograms this pet weighs
*/
public void setWeight(double heft) {
weight = heft;
}
/**
* setOwner method: <br />
* Sets the name of the owner of this pet
* @param human String that contains this pet's owner's name
*/
public void setOwner(String human) {
owner = human;
}
/**
* setGender method: <br />
* Sets the gender of this pet
* @param gndr Genders object that determines this pet's gender
*/
public void setGender(Genders gndr) {
gender = gndr;
}
/**
* setSpecies method: <br />
* Sets this pet's species
* @param specie String that describes this pet's species
*/
public void setSpecies(String specie) {
species = specie;
}
/**
* determineGender method: <br />
* Converts a string into a Genders object
* @param gender A String that determines the gender enum value of this pet
* @return Genders object of this pet's gender
*/
public Genders determineGender(String gender) {
gender = gender.toUpperCase();
if (gender.equals("MALE"))
return Genders.MALE;
else if (gender.equals("FEMALE"))
return Genders.FEMALE;
else {
System.err.println("This is not a valid entry for pet's gender");
return null;
}
}
/**
* Class Constructor <br />
* <p>Separates each line at the commas and puts the Strings between the commas into an ArrayList that is then used to populate the fields of this pet object.
* @param scannerEntry String of one line of a pet text file
*/
public Pet (String scannerEntry) {
Scanner entry = new Scanner(scannerEntry);
entry.useDelimiter(",");
while(entry.hasNext()) {
petInfo.add(entry.next());
}
entry.close();
int IDNumber = Integer.parseInt(petInfo.get(0));
setID(IDNumber);
setName(petInfo.get(1));
double weight = Double.parseDouble(petInfo.get(2));
setWeight(weight);
setOwner(petInfo.get(3));
setGender(determineGender(petInfo.get(4)));
setSpecies(petInfo.get(5));
}
/**
* printFields method: <br />
*
* Provides a string of the first six attributes that all types of pets have in common
* @return A formatted string the pet's first six attributes
*/
public String printFields() {
return ("ID Number: " + getID() +"\n"
+ "Name: " + getName() + "\n"
+ "Weight: " + getWeight() + "kg \n"
+ "Owner: " + getOwner() + "\n"
+ "Gender: " + getGender() + "\n"
+ "Species: " + getSpecies() +"\n");
}
/**
* inNamePresent method: <br />
*
* Checks to see if the provided name is the same as this particular pet's name.
* <p>Takes into account both whitespace and capitalization.
*
* @param searchedName String of the name of a pet that the user is searching for
* @return true if the name in question is the same as this pet's name, returns false otherwise
*/
public boolean isNamePresent(String searchedName) {
return (this.name.toUpperCase().trim().equals(searchedName));
}
/**
* isIDPresent method: <br />
*
* Checks to see if the provided ID is the same as this particular pet's name.
*
* @param searchedID int of the ID number of a pet that the user is searching for
* @return true if the searched ID on question is the same as this pet's ID, returns false otherwise
*/
public boolean isIDPresent(int searchedID) {
return (getID() == searchedID);
}
}
| ACDecastro/Happy-Pets-Terminal-App | Pet.java |
957 | import java.util.Scanner;
public class DFS {
public static void printHelper(int arr[][],int vertice,boolean visited[]) {
//print that vertice
System.out.println(vertice);
// mark that vertices as visited
visited[vertice] = true;
// now call recursion on remaining part
for(int i=0;i<arr.length;i++) {
if(arr[vertice][i]==1 && visited[i]!=true) {
printHelper(arr,i,visited);
}
}
}
public static void print(int arr[][]) {
boolean visited[] = new boolean[arr.length];
//looping over visited array if not visited call the print function to traverse them
for(int i=0;i<arr.length;i++) {
// if not visited call the function to print
if(visited[i]==false)
printHelper(arr,i,visited);
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter No of Vertices : ");
int vertices = sc.nextInt();
System.out.println("Enter No of edges : ");
int edges = sc.nextInt();
int graph[][] = new int[vertices][vertices];
for(int i=0;i<edges;i++) {
System.out.println("Enter Starting point");
int fv = sc.nextInt();
System.out.println("Enter Ending point");
int sv = sc.nextInt();
graph[fv][sv]=1;
graph[sv][fv]=1;
}
print(graph);
}
}
| Trmpsanjay/S4-Lab-Submissions | DFS.java |
958 | package Pacman;
import java.awt.Color;
/**
* The Dot class constructs the small dots that will be laid out in certain points of the board and that
* boost the score of the Game 10 points when eaten. I decided to make it a subclass of the EllipseShape class
* so that it would automatically have all of the methods of this class. Also, because it will be contained in the MazeSquare's ArrayList,
* it implements the Collidable interface.
*
* @author vcano
*
*/
public class Dot extends cs015.prj.Shape.EllipseShape implements Collidable {
private MazeSquare _square;
private GamePanel _gamePanel;
public Dot(GamePanel gamePanel){ //Constructor. Association with GamePanel.
this.setSize(6,6);
this.setColor(Color.WHITE);
this.setVisible(true);
_gamePanel = gamePanel;
}
@Override
public void makeCollision(MazeSquare square) { //When colliding, it removes itself from the ArrayList and updates the score by 10.
_square = square;
_square.removeFromList(this);
_gamePanel.setScore(_gamePanel.getScore()+10);
_gamePanel.updateScoreLabel();
_gamePanel.setDots(_gamePanel.getDots()+1); //Dot counter (keeps track of how many dots have been eaten) incremented by 1.
}
@Override
public void setLocation(double x, double y){ //So that it looked better graphically, I did override to the setLocation method to be off by 10 pixels.
super.setLocation(x+10, y+10);
}
} //class Dot
| canovalentina/pacman | Dot.java |
959 | // SPP -- The main program of the Scheme pretty printer.
import Parse.Scanner;
import Parse.Parser;
import Tokens.Token;
import Tokens.TokenType;
import Tree.Node;
public class SPP {
public static void main(String argv[]) {
// Create scanner that reads from standard input
Scanner scanner = new Scanner(System.in);
if (argv.length > 1 ||
(argv.length == 1 && ! argv[0].equals("-d"))) {
System.err.println("Usage: java SPP [-d]");
System.exit(1);
}
// If command line option -d is provided, debug the scanner
if (argv.length == 1 && argv[0].equals("-d")) {
Token tok = scanner.getNextToken();
while (tok != null) {
TokenType tt = tok.getType();
System.out.print(tt.name());
if (tt == TokenType.INT)
System.out.println(", intVal = " + tok.getIntVal());
else if (tt == TokenType.STRING)
System.out.println(", strVal = " + tok.getStrVal());
else if (tt == TokenType.IDENT)
System.out.println(", name = " + tok.getName());
else
System.out.println();
tok = scanner.getNextToken();
}
System.exit(0);
}
// Create parser
Parser parser = new Parser(scanner);
Node root;
// Parse and pretty-print each input expression
root = parser.parseExp();
while (root != null) {
root.print(0);
root = parser.parseExp();
}
System.exit(0);
}
}
| Emmanuel747/scheme-pretty-printer | SPP.java |
962 | package org.usfirst.frc.team1306.robot;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.buttons.Button;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
/**
* This class is the glue that binds the controls on the physical operator
* interface to the commands and command groups that allow control of the robot.
*/
public class OI {
private final XboxController xbox;
public double getMagnitude() {
double magn = xbox.getRTrigger();
if (magn == 0) { //If the Right Trigger isn't being pressed
magn=xbox.getLTrigger();
magn=-magn; //Left trigger=reverse=opposite direction
}
return magn;
}
//// CREATING BUTTONS
// One type of button is a joystick button which is any button on a joystick.
// You create one by telling it which joystick it's on and which button
// number it is.
// Joystick stick = new Joystick(port);
// Button button = new JoystickButton(stick, buttonNumber);
public double getAngle() {
double x_value = xbox.getX(GenericHID.Hand.kLeft);
double y_value = xbox.getY(GenericHID.Hand.kLeft);
double angle = Math.atan(y_value/x_value); //Given the x, y -> angle is tan^-1(y/x)
return angle;
}
public OI() {
super();
xbox= new XboxController(RobotMap.XBOX_CONTROLLLER);
}
// There are a few additional built in buttons you can use. Additionally,
// by subclassing Button you can create custom triggers and bind those to
// commands the same as any other Button.
//// TRIGGERING COMMANDS WITH BUTTONS
// Once you have a button, it's trivial to bind it to a button in one of
// three ways:
// Start the command when the button is pressed and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenPressed(new ExampleCommand());
// Run the command while the button is being held down and interrupt it once
// the button is released.
// button.whileHeld(new ExampleCommand());
// Start the command when the button is released and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenReleased(new ExampleCommand());
}
| team1306/Dahmenator | OI.java |
963 | package com.methodin.db;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
public abstract class DB {
// id should be defined as the Primary Key in all of your tables
public static final String KEY_ROWID = "id";
// List of columns - should be populated in child class
protected String[] columns = new String[] {};
// Name of the SQLite table - should be populated in child class
protected String table = "";
// Application context
protected Context context;
// Actual database connection object
protected SQLiteDatabase database;
// Our helper class
protected DBHelper dbHelper;
public DB(Context context) {
this.context = context;
}
public DB(Context context, String table, String[] pColumns) {
this.context = context;
this.columns = pColumns;
this.table = table;
}
/**
* Open a connection to the database table
*/
public DB open() throws SQLException {
dbHelper = new DBHelper(context);
database = dbHelper.getWritableDatabase();
return this;
}
/**
* Close the connection to the database table
*/
public void close() {
dbHelper.close();
}
/**
* Start a transaction
*/
public void begin() {
database.beginTransaction();
}
/**
* Flags the transaction for a commit
*/
public void commit() {
database.setTransactionSuccessful();
}
/**
* Finalized the transaction
* This should always be called after a commit or rollback - if not it will not commit
*/
public void end() {
database.endTransaction();
}
/**
* Create a new record If the record is successfully created return the new
* rowId for that note, otherwise return a -1 to indicate failure.
*/
public long create(HashMap<String, String> columns) {
ContentValues initialValues = createContentValues(columns);
return database.insert(table, null, initialValues);
}
/**
* Update the record using a HashMap for a given id
*/
public boolean update(int rowId, HashMap<String, String> columns) {
ContentValues updateValues = createContentValues(columns);
return database.update(table, updateValues, KEY_ROWID + "=" + rowId, null) > 0;
}
/**
* Update the record using a ContentValues object for a given id
*/
public boolean update(int rowId, ContentValues columns) {
return database.update(table, columns, KEY_ROWID + "=" + rowId, null) > 0;
}
/**
* Delets a record that matches the passed id
*/
public boolean delete(int rowId) {
return database.delete(table, KEY_ROWID + "=" + rowId, null) > 0;
}
/**
* Truncates the table
*/
public boolean truncate() {
return database.delete(table, null, null) > 0;
}
/**
* Return a Cursor over the list of all todo in the database
*
* @return Cursor over all notes
*/
public Cursor fetch() {
return fetch(null, null);
}
public Cursor fetch(String conditions) {
return fetch(conditions, null);
}
public Cursor fetch(String conditions, String[] values) {
Cursor mCursor = database.query(table, columns, conditions, values, null,
null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
/**
* Return a ContentValues object that has all of the columns and values
*/
public ContentValues fetchOne(String rowId) throws SQLException {
return fetchOne(KEY_ROWID, rowId);
}
public ContentValues fetchOne(String key, String value) throws SQLException {
ContentValues values = new ContentValues();
Cursor mCursor = database.query(true, table, columns,
key + "='" + value + "'", null, null, null, null, null);
if (mCursor != null) {
if(mCursor.getCount() > 0) {
mCursor.moveToFirst();
for(int i=0,len=mCursor.getColumnCount();i<len;i++) {
values.put(mCursor.getColumnName(i), mCursor.getString(i));
}
}
mCursor.close();
}
return values;
}
public ContentValues fetchOne(String conditions, String[] values) throws SQLException {
ContentValues result = new ContentValues();
Cursor mCursor = database.query(true, table, columns,
conditions, values, null, null, null, null);
if (mCursor != null) {
if(mCursor.getCount() > 0) {
mCursor.moveToFirst();
for(int i=0,len=mCursor.getColumnCount();i<len;i++) {
result.put(mCursor.getColumnName(i), mCursor.getString(i));
}
}
mCursor.deactivate();
mCursor.close();
}
return result;
}
/**
* Converts a HashMap to a ContentValues object
*/
@SuppressWarnings("unchecked")
protected ContentValues createContentValues(HashMap<String, String> columns) {
ContentValues values = new ContentValues();
Iterator it = columns.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
values.put(pairs.getKey().toString(), pairs.getValue().toString());
}
return values;
}
}
| methodin/Android-DB | DB.java |
964 | import java.util.Scanner;
public class a1 {
/*
Problem code: GNY07A
Misspelling is an art form that students seem to excel at.
Write a program that removes the nth character from an input string.
Input
The first line of input contains a single integer N (1 β€ N β€ 1000) which is
the number of datasets that follow.
Each dataset consists of a single line of input containing M, a space,
and a string made up of uppercase letters and spaces only.
M will be less than or equal to the length of the string.
The length of the string is guaranteed to be less than or equal to 80.
Output
For each dataset, you should generate one line of output with the following values:
The dataset number as a decimal integer (start counting at one), a space, and the misspelled string.
The misspelled string is the input string with the indicated character deleted.
Sample Input
4
4 MISSPELL
1 PROGRAMMING
7 CONTEST
3 BALLOON
Sample Output
1 MISPELL
2 ROGRAMMING
3 CONTES
4 BALOON
*/
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numTimes = input.nextInt();
int offset, COUNT = 1;
String word, first, last;
while (numTimes >0){
offset = input.nextInt();
offset--;
word = input.nextLine(); //next();
word = word.substring(1);
if (offset!=0)
first = word.substring(0, offset);
else
first = "";
last = word.substring(offset+1, word.length());
word = first + last;
System.out.println(COUNT + " " + word);
numTimes--;
COUNT++;
}
input.close();
}
}
| smac89/ProjectEuler-OnlineJudge | a1.java |
965 |
//executor that knows how to execute the command
public class TV
{
public TV()
{
}
public void TurnOn()
{
System.out.println("turning on the tv");
}
public void TurnOff()
{
System.out.println("turning off the tv");
}
}
| akshatsh0610/Command-Design-Pattern | TV.java |
966 | package org.usfirst.frc.team5496.robot;
import edu.wpi.first.wpilibj.buttons.Button;
import org.usfirst.frc.team5496.robot.commands.ExampleCommand;
/**
* This class is the glue that binds the controls on the physical operator
* interface to the commands and command groups that allow control of the robot.
*/
public class OI {
//// CREATING BUTTONS
// One type of button is a joystick button which is any button on a joystick.
// You create one by telling it which joystick it's on and which button
// number it is.
// Joystick stick = new Joystick(port);
// Button button = new JoystickButton(stick, buttonNumber);
// There are a few additional built in buttons you can use. Additionally,
// by subclassing Button you can create custom triggers and bind those to
// commands the same as any other Button.
//// TRIGGERING COMMANDS WITH BUTTONS
// Once you have a button, it's trivial to bind it to a button in one of
// three ways:
// Start the command when the button is pressed and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenPressed(new ExampleCommand());
// Run the command while the button is being held down and interrupt it once
// the button is released.
// button.whileHeld(new ExampleCommand());
// Start the command when the button is released and let it run the command
// until it is finished as determined by it's isFinished method.
// button.whenReleased(new ExampleCommand());
}
| Team5496/mordred | OI.java |
967 | /**
WAP to store 'N' different numbers in SDA where 'N' is always odd. Arrange them in such a way that
the smallest element should be in the middle position, second smallest element to the left side of it,
third smallest to the right side and so on β¦..
Input : 71, 40, 66, 56, 19, 31, 85, 99, 23, 91, 59
Output : 91, 71, 59, 40, 23, 19, 31, 56, 66, 85, 99
Class members are specified below:-
Class name: arrange
Data members:-
arr [] : integer type
size : integer type variable to store size of array
Member Functions:-
Arrange (int n) : parameterized constructor to initialize n to size
Void input() : function to input an array of specified size
Void arrange() : to arrange them in such a way that the smallest element should be in the middle position,
second smallest element to the left side of it, third smallest to the right hand side and so on β¦..
Void dsiplay() : function to display the array before and after arrangement
Specify the class arrange and also write the main() function.
*/
import java.io.*;
class Q1
{
static BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
public static void main(String args[])throws IOException
{
System.out.println("Enter size of array (size should be an odd number)");
int n=Integer.parseInt(obj.readLine());
if(n%2==0)
{
System.out.println("Size entered is invalid. You are now exiting.");
System.exit(0);
}
arrange A=new arrange(n);
A.input();
A.display();
}
}
class arrange
{
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
int arr[];
int size;
arrange(int n)
{
size=n;
arr=new int[size];
for(int i=0;i<size;i++)
{
arr[i]=0;
}
}
void input()throws IOException
{
System.out.println("Enter elements of array of specified size");
int i=0;
for(i=0;i<size;i++)
{
arr[i]=Integer.parseInt(obj.readLine());
}
}
void arrange()
{
int t=0;
int i=0;
int j=0;
int temp[]=new int[size];
int u=size/2;
int l=size/2-1;
for(i=0;i<size;i++)
{
for(j=0;j<size-i-1;j++)
{
if(arr[j]>arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}
for(i=0;i<size;i++)
{
if(i%2==0)
{
temp[u]=arr[i];
u++;
}
else
{
temp[l]=arr[i];
l--;
}
}
for(i=0;i<size;i++)
{
arr[i]=temp[i];
}
}
void display()
{
System.out.print("Before arrangement : ");
int i=0;
for(i=0;i<size;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
arrange();
System.out.print("After arrangement : ");
for(i=0;i<size;i++)
{
System.out.print(arr[i]+" ");
}
System.out.println();
}
} | sheivin/Computer-Science-Project-Class-XII-ISC-2013-2014 | Q1.java |
968 | /*
Problem from Topcoder practice problems (http://www.topcoder.com)
https://arena.topcoder.com/#/u/practiceCode/16319/46378/13642/1/325040
Problem Statement
You are given two s: N and K. Lun the dog is interested in strings that satisfy the following conditions:
The string has exactly N characters, each of which is either 'A' or 'B'.
The string s has exactly K pairs (i, j) (0 <= i < j <= N-1) such that s[i] = 'A' and s[j] = 'B'.
If there exists a string that satisfies the conditions, find and return any such string. Otherwise, return an empty string.
*/
public class ABComputed {
public static String createString(int i,int k){
int noA =i;
int noB =0;
int curK = 0;
int bPos =-1;
boolean found=false;
while(noA >= noB && !found){
if( k-curK <noA){
found=true;
bPos= k-curK;
} else {
curK = --noA * ++noB;
if (curK == k) {
found = true;
}else{
curK=curK-noB;
}
}
}
if (!found) {
return "";
}else{
StringBuffer stringBuffer= new StringBuffer();
for(int j=0; j<i; j++){
if (j<noA) {
stringBuffer.append("A");
}else{
stringBuffer.append("B");
}
}
if(bPos >-1){
stringBuffer.replace(bPos,bPos+1,"B");
}
return stringBuffer.toString();
}
}
public static void main(String[] args) {
for (int i = 1; i < 50; i++){
System.out.println("8:"+i+" = "+createString(8, i));
}
}
}
| morganrconnolly/topcoder | AB.java |
969 | package AndroidKeystoreBrute;
/* JKS.java -- implementation of the "JKS" key store.
Copyright (C) 2003 Casey Marshall <[email protected]>
Permission to use, copy, modify, distribute, and sell this software and
its documentation for any purpose is hereby granted without fee,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation. No representations are made about the
suitability of this software for any purpose. It is provided "as is"
without express or implied warranty.
This program was derived by reverse-engineering Sun's own
implementation, using only the public API that is available in the 1.4.1
JDK. Hence nothing in this program is, or is derived from, anything
copyrighted by Sun Microsystems. While the "Binary Evaluation License
Agreement" that the JDK is licensed under contains blanket statements
that forbid reverse-engineering (among other things), it is my position
that US copyright law does not and cannot forbid reverse-engineering of
software to produce a compatible implementation. There are, in fact,
numerous clauses in copyright law that specifically allow
reverse-engineering, and therefore I believe it is outside of Sun's
power to enforce restrictions on reverse-engineering of their software,
and it is irresponsible for them to claim they can. */
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.DigestInputStream;
import java.security.DigestOutputStream;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyStoreException;
import java.security.KeyStoreSpi;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import javax.crypto.EncryptedPrivateKeyInfo;
import javax.crypto.spec.SecretKeySpec;
/**
* This is an implementation of Sun's proprietary key store algorithm, called
* "JKS" for "Java Key Store". This implementation was created entirely through
* reverse-engineering.
*
* <p>
* The format of JKS files is, from the start of the file:
*
* <ol>
* <li>Magic bytes. This is a four-byte integer, in big-endian byte order, equal
* to <code>0xFEEDFEED</code>.</li>
* <li>The version number (probably), as a four-byte integer (all multibyte
* integral types are in big-endian byte order). The current version number (in
* modern distributions of the JDK) is 2.</li>
* <li>The number of entrires in this keystore, as a four-byte integer. Call
* this value <i>n</i></li>
* <li>Then, <i>n</i> times:
* <ol>
* <li>The entry type, a four-byte int. The value 1 denotes a private key entry,
* and 2 denotes a trusted certificate.</li>
* <li>The entry's alias, formatted as strings such as those written by <a href=
* "http://java.sun.com/j2se/1.4.1/docs/api/java/io/DataOutput.html#writeUTF(java.lang.String)">
* DataOutput.writeUTF(String)</a>.</li>
* <li>An eight-byte integer, representing the entry's creation date, in
* milliseconds since the epoch.
*
* <p>
* Then, if the entry is a private key entry:
* <ol>
* <li>The size of the encoded key as a four-byte int, then that number of
* bytes. The encoded key is the DER encoded bytes of the <a href=
* "http://java.sun.com/j2se/1.4.1/docs/api/javax/crypto/EncryptedPrivateKeyInfo.html">
* EncryptedPrivateKeyInfo</a> structure (the encryption algorithm is discussed
* later).</li>
* <li>A four-byte integer, followed by that many encoded certificates, encoded
* as described in the trusted certificates section.</li>
* </ol>
*
* <p>
* Otherwise, the entry is a trusted certificate, which is encoded as the name
* of the encoding algorithm (e.g. X.509), encoded the same way as alias names.
* Then, a four-byte integer representing the size of the encoded certificate,
* then that many bytes representing the encoded certificate (e.g. the DER bytes
* in the case of X.509).</li>
* </ol>
* </li>
* <li>Then, the signature.</li>
* </ol>
* </ol>
* </li>
* </ol>
*
* <p>
* (See <a href="genkey.java">this file</a> for some idea of how I was able to
* figure out these algorithms)
* </p>
*
* <p>
* Decrypting the key works as follows:
*
* <ol>
* <li>The key length is the length of the ciphertext minus 40. The encrypted
* key, <code>ekey</code>, is the middle bytes of the ciphertext.</li>
* <li>Take the first 20 bytes of the encrypted key as a seed value,
* <code>K[0]</code>.</li>
* <li>Compute <code>K[1] ... K[n]</code>, where <code>|K[i]| = 20</code>,
* <code>n = ceil(|ekey| / 20)</code>, and
* <code>K[i] = SHA-1(UTF-16BE(password) + K[i-1])</code>.</li>
* <li><code>key = ekey ^ (K[1] + ... + K[n])</code>.</li>
* <li>The last 20 bytes are the checksum, computed as <code>H =
* SHA-1(UTF-16BE(password) + key)</code>. If this value does not match the last
* 20 bytes of the ciphertext, output <code>FAIL</code>. Otherwise, output
* <code>key</code>.</li>
* </ol>
*
* <p>
* The signature is defined as <code>SHA-1(UTF-16BE(password) +
* US_ASCII("Mighty Aphrodite") + encoded_keystore)</code> (yup, Sun engineers
* are just that clever).
*
* <p>
* (Above, SHA-1 denotes the secure hash algorithm, UTF-16BE the big-endian byte
* representation of a UTF-16 string, and US_ASCII the ASCII byte representation
* of the string.)
*
* <p>
* The source code of this class should be available in the file
* <a href="http://metastatic.org/source/JKS.java">JKS.java</a>.
*
* @author Casey Marshall ([email protected])
*/
public class JKS extends KeyStoreSpi {
// Constants and fields.
// ------------------------------------------------------------------------
/** Ah, Sun. So goddamned clever with those magic bytes. */
private static final int MAGIC = 0xFEEDFEED;
private static final int PRIVATE_KEY = 1;
private static final int TRUSTED_CERT = 2;
private final Vector aliases;
private final HashMap trustedCerts;
private final HashMap privateKeys;
private final HashMap certChains;
private final HashMap dates;
// Constructor.
// ------------------------------------------------------------------------
public JKS() {
super();
aliases = new Vector();
trustedCerts = new HashMap();
privateKeys = new HashMap();
certChains = new HashMap();
dates = new HashMap();
}
// Instance methods.
// ------------------------------------------------------------------------
public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException {
if (!privateKeys.containsKey(alias))
return null;
byte[] key = decryptKey((byte[]) privateKeys.get(alias), charsToBytes(password));
Certificate[] chain = engineGetCertificateChain(alias);
if (chain.length > 0) {
try {
// Private and public keys MUST have the same algorithm.
KeyFactory fact = KeyFactory.getInstance(chain[0].getPublicKey().getAlgorithm());
return fact.generatePrivate(new PKCS8EncodedKeySpec(key));
} catch (InvalidKeySpecException x) {
throw new UnrecoverableKeyException(x.getMessage());
}
} else
return new SecretKeySpec(key, alias);
}
public Certificate[] engineGetCertificateChain(String alias) {
return (Certificate[]) certChains.get(alias);
}
public Certificate engineGetCertificate(String alias) {
return (Certificate) trustedCerts.get(alias);
}
public Date engineGetCreationDate(String alias) {
return (Date) dates.get(alias);
}
// XXX implement writing methods.
public void engineSetKeyEntry(String alias, Key key, char[] passwd, Certificate[] certChain)
throws KeyStoreException {
if (trustedCerts.containsKey(alias))
throw new KeyStoreException("\"" + alias + " is a trusted certificate entry");
privateKeys.put(alias, encryptKey(key, charsToBytes(passwd)));
if (certChain != null)
certChains.put(alias, certChain);
else
certChains.put(alias, new Certificate[0]);
if (!aliases.contains(alias)) {
dates.put(alias, new Date());
aliases.add(alias);
}
}
public void engineSetKeyEntry(String alias, byte[] encodedKey, Certificate[] certChain) throws KeyStoreException {
if (trustedCerts.containsKey(alias))
throw new KeyStoreException("\"" + alias + "\" is a trusted certificate entry");
try {
new EncryptedPrivateKeyInfo(encodedKey);
} catch (IOException ioe) {
throw new KeyStoreException("encoded key is not an EncryptedPrivateKeyInfo");
}
privateKeys.put(alias, encodedKey);
if (certChain != null)
certChains.put(alias, certChain);
else
certChains.put(alias, new Certificate[0]);
if (!aliases.contains(alias)) {
dates.put(alias, new Date());
aliases.add(alias);
}
}
public void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreException {
if (privateKeys.containsKey(alias))
throw new KeyStoreException("\"" + alias + "\" is a private key entry");
if (cert == null)
throw new NullPointerException();
trustedCerts.put(alias, cert);
if (!aliases.contains(alias)) {
dates.put(alias, new Date());
aliases.add(alias);
}
}
public void engineDeleteEntry(String alias) throws KeyStoreException {
aliases.remove(alias);
}
public Enumeration engineAliases() {
return aliases.elements();
}
public boolean engineContainsAlias(String alias) {
return aliases.contains(alias);
}
public int engineSize() {
return aliases.size();
}
public boolean engineIsKeyEntry(String alias) {
return privateKeys.containsKey(alias);
}
public boolean engineIsCertificateEntry(String alias) {
return trustedCerts.containsKey(alias);
}
public String engineGetCertificateAlias(Certificate cert) {
for (Iterator keys = trustedCerts.keySet().iterator(); keys.hasNext();) {
String alias = (String) keys.next();
if (cert.equals(trustedCerts.get(alias)))
return alias;
}
return null;
}
public void engineStore(OutputStream out, char[] passwd)
throws IOException, NoSuchAlgorithmException, CertificateException {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(charsToBytes(passwd));
md.update("Mighty Aphrodite".getBytes("UTF-8"));
DataOutputStream dout = new DataOutputStream(new DigestOutputStream(out, md));
dout.writeInt(MAGIC);
dout.writeInt(2);
dout.writeInt(aliases.size());
for (Enumeration e = aliases.elements(); e.hasMoreElements();) {
String alias = (String) e.nextElement();
if (trustedCerts.containsKey(alias)) {
dout.writeInt(TRUSTED_CERT);
dout.writeUTF(alias);
dout.writeLong(((Date) dates.get(alias)).getTime());
writeCert(dout, (Certificate) trustedCerts.get(alias));
} else {
dout.writeInt(PRIVATE_KEY);
dout.writeUTF(alias);
dout.writeLong(((Date) dates.get(alias)).getTime());
byte[] key = (byte[]) privateKeys.get(alias);
dout.writeInt(key.length);
dout.write(key);
Certificate[] chain = (Certificate[]) certChains.get(alias);
dout.writeInt(chain.length);
for (int i = 0; i < chain.length; i++)
writeCert(dout, chain[i]);
}
}
byte[] digest = md.digest();
dout.write(digest);
}
public void engineLoad(InputStream in, char[] passwd)
throws IOException, NoSuchAlgorithmException, CertificateException {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(charsToBytes(passwd));
md.update("Mighty Aphrodite".getBytes("UTF-8")); // HAR HAR
aliases.clear();
trustedCerts.clear();
privateKeys.clear();
certChains.clear();
dates.clear();
DataInputStream din = new DataInputStream(new DigestInputStream(in, md));
if (din.readInt() != MAGIC)
throw new IOException("not a JavaKeyStore");
din.readInt(); // version no.
final int n = din.readInt();
aliases.ensureCapacity(n);
if (n < 0)
throw new IOException("negative entry count");
for (int i = 0; i < n; i++) {
int type = din.readInt();
String alias = din.readUTF();
aliases.add(alias);
dates.put(alias, new Date(din.readLong()));
switch (type) {
case PRIVATE_KEY:
int len = din.readInt();
byte[] encoded = new byte[len];
din.read(encoded);
privateKeys.put(alias, encoded);
int count = din.readInt();
Certificate[] chain = new Certificate[count];
for (int j = 0; j < count; j++)
chain[j] = readCert(din);
certChains.put(alias, chain);
break;
case TRUSTED_CERT:
trustedCerts.put(alias, readCert(din));
break;
default:
throw new IOException("malformed key store");
}
}
byte[] hash = new byte[20];
din.read(hash);
if (MessageDigest.isEqual(hash, md.digest()))
throw new IOException("signature not verified");
}
// Own methods.
// ------------------------------------------------------------------------
private static Certificate readCert(DataInputStream in)
throws IOException, CertificateException, NoSuchAlgorithmException {
String type = in.readUTF();
int len = in.readInt();
byte[] encoded = new byte[len];
in.read(encoded);
CertificateFactory factory = CertificateFactory.getInstance(type);
return factory.generateCertificate(new ByteArrayInputStream(encoded));
}
private static void writeCert(DataOutputStream dout, Certificate cert) throws IOException, CertificateException {
dout.writeUTF(cert.getType());
byte[] b = cert.getEncoded();
dout.writeInt(b.length);
dout.write(b);
}
private static byte[] decryptKey(byte[] encryptedPKI, byte[] passwd) throws UnrecoverableKeyException {
try {
EncryptedPrivateKeyInfo epki = new EncryptedPrivateKeyInfo(encryptedPKI);
byte[] encr = epki.getEncryptedData();
byte[] keystream = new byte[20];
System.arraycopy(encr, 0, keystream, 0, 20);
byte[] check = new byte[20];
System.arraycopy(encr, encr.length - 20, check, 0, 20);
byte[] key = new byte[encr.length - 40];
MessageDigest sha = MessageDigest.getInstance("SHA1");
int count = 0;
while (count < key.length) {
sha.reset();
sha.update(passwd);
sha.update(keystream);
sha.digest(keystream, 0, keystream.length);
for (int i = 0; i < keystream.length && count < key.length; i++) {
key[count] = (byte) (keystream[i] ^ encr[count + 20]);
count++;
}
}
sha.reset();
sha.update(passwd);
sha.update(key);
if (!MessageDigest.isEqual(check, sha.digest()))
throw new UnrecoverableKeyException("checksum mismatch");
return key;
} catch (Exception x) {
throw new UnrecoverableKeyException(x.getMessage());
}
}
private static byte[] encryptKey(Key key, byte[] passwd) throws KeyStoreException {
try {
MessageDigest sha = MessageDigest.getInstance("SHA1");
SecureRandom rand = SecureRandom.getInstance("SHA1PRNG");
byte[] k = key.getEncoded();
byte[] encrypted = new byte[k.length + 40];
byte[] keystream = rand.getSeed(20);
System.arraycopy(keystream, 0, encrypted, 0, 20);
int count = 0;
while (count < k.length) {
sha.reset();
sha.update(passwd);
sha.update(keystream);
sha.digest(keystream, 0, keystream.length);
for (int i = 0; i < keystream.length && count < k.length; i++) {
encrypted[count + 20] = (byte) (keystream[i] ^ k[count]);
count++;
}
}
sha.reset();
sha.update(passwd);
sha.update(k);
sha.digest(encrypted, encrypted.length - 20, 20);
// 1.3.6.1.4.1.42.2.17.1.1 is Sun's private OID for this
// encryption algorithm.
return new EncryptedPrivateKeyInfo("1.3.6.1.4.1.42.2.17.1.1", encrypted).getEncoded();
} catch (Exception x) {
throw new KeyStoreException(x.getMessage());
}
}
private static byte[] charsToBytes(char[] passwd) {
byte[] buf = new byte[passwd.length * 2];
for (int i = 0, j = 0; i < passwd.length; i++) {
buf[j++] = (byte) (passwd[i] >>> 8);
buf[j++] = (byte) passwd[i];
}
return buf;
}
}
| anson-vandoren/android-keystore-password-recover | JKS.java |
970 | //{ Driver Code Starts
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.*;
public class Driver {
public static void main(String[] args)throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int tc = Integer.parseInt(br.readLine());
while(tc-->0)
{
String s1 = br.readLine();
String s2 = br.readLine();
Solution obj = new Solution();
boolean a = obj.areIsomorphic(s1,s2);
if(a)
System.out.println(1);
else
System.out.println(0);
}
}
}
// } Driver Code Ends
class Solution
{
//Function to check if two strings are isomorphic.
public static boolean areIsomorphic(String str1,String str2)
{
int size = 256;
int m = str1.length();
int n = str2.length();
if(m != n)
return false;
//using a boolean array to mark visited characters in str2.
Boolean[] marked = new Boolean[size];
Arrays.fill(marked, Boolean.FALSE);
//using map to store mapping of every character from str1 to
//that of str2. Initializing all entries of map as -1.
int[] map = new int[size];
Arrays.fill(map, -1);
for (int i = 0; i < n; i++)
{
//if current character of str1 is seen first time in map.
if (map[str1.charAt(i)] == -1)
{
//if current character of str2 is already
//seen, one to one mapping is not possible.
if (marked[str2.charAt(i)] == true)
return false;
//marking current character of str2 as visited.
marked[str2.charAt(i)] = true;
//storing mapping of current characters.
map[str1.charAt(i)] = str2.charAt(i);
}
//if this isn't first appearance of current character in str1 then
//checking if previous appearance mapped to same character of str2.
else if (map[str1.charAt(i)] != str2.charAt(i))
return false;
}
return true;
}
}
| dhruvabhat24/Geeks-4-Geeks_November | 11.java |
974 | import greenfoot.*;
import java.awt.Color;
/**
* Write a description of class Gun here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Gun extends Weapon
{
/**
* Act - do whatever the Gun wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
/**
* Class: Gun (subclass of Actor -- inner class of Chased): the gun for this actor
*/
private GunDec decGun1;
private GunDec decGun2;
/**
* creates image for actor
*/
public Gun()
{
// the image for this actor
decGun1 = new ConcreteDecoratorA(Gun.this);
decGun2 = new ConcreteDecoratorB(decGun1);
GreenfootImage image = new GreenfootImage(50, 10);
image.setColor(Color.black);
for (int i=0; i<4; i++) image.fillRect(20, i, 9+i*4, 10-i*2);
setImage(image);
}
public void addedToWorld(World world) {
world.addObject(decGun1, getX(), getY());
world.addObject(decGun2, getX(), getY());
}
/**
* responds to mouse movement and mouse button clicks
*/
public void act()
{
// turn towards mouse when mouse moves
if (Greenfoot.mouseMoved(null) || Greenfoot.mouseDragged(null))
{
MouseInfo mouse = Greenfoot.getMouseInfo();
if (mouse != null) turnTowards(mouse.getX(), mouse.getY());
}
decGun1.setLocation(getX(), getY());
decGun2.setLocation(getX(), getY());
// detect mouse clicks to fire shot
if (Greenfoot.mouseClicked(null)) {
int curScore = ((Welt)getWorld()).score;
if (curScore < 10) {
updateGun();
} else if (curScore < 50) {
decGun1.updateGun();
} else {
decGun2.updateGun();
}
}
}
/**
* overwrite updateGun() method
*/
public void updateGun(){
getWorld().addObject(new Shot(0, Gun.this), getX(), getY());
}
public void morePower() {
getWorld().addObject(new Shot(0, Gun.this), getX(), getY());
getWorld().addObject(new Shot(22, Gun.this), getX(), getY());
getWorld().addObject(new Shot(-22, Gun.this), getX(), getY());
}
public void mostPower() {
getWorld().addObject(new Shot(0, Gun.this), getX(), getY());
getWorld().addObject(new Shot(22, Gun.this), getX(), getY());
getWorld().addObject(new Shot(-22, Gun.this), getX(), getY());
getWorld().addObject(new Shot(45, Gun.this), getX(), getY());
getWorld().addObject(new Shot(-45, Gun.this), getX(), getY());
}
/**
* Class Shot (subclass of QActor -- inner class of Chased.Gun): the shots from this gun
*/
// private class Shot extends QActor
// {
// /**
// * sets bounds fields and creates the image for this actor
// */
// private int RotationDegree;
// public Shot(int degree)
// {
// this.RotationDegree = degree;
// setBoundedAction(QActor.REMOVE, 5); // set bounds fields
// // create image for this actor
// GreenfootImage image = new GreenfootImage(5, 2);
// image.fill();
// setImage(image);
// }
//
// /**
// * initializes rotation and position of actor
// *
// * @param world the world this actor was added into
// */
// public void addedToWorld(World world)
// {
// setRotation(Gun.this.getRotation() + RotationDegree); // set rotation (to that of gun)
// move(Gun.this.getImage().getWidth()/2); // set position (at end of gun)
// }
//
// /**
// * moves actor and checks for removal of actor
// */
// public void act()
// {
// setVX(0);
// setVY(0);
// addForce(500, getRotation()*QVAL);
// move(); // moving (equivalent to 'move(5)' for a non-QActor)
// if (hits(Chaser.class) || atWorldEdge()) getWorld().removeObject(this); // removing
// }
//
// /**
// * internal method to detect object collision; returns true if collision detected, else false
// *
// * @param cls the class of object to check for collision with
// * @return a flag indicating whether an object of given class was detected or not
// */
// private boolean hits(Class cls)
// {
// // get intersecting object and return result
// Actor clsActor = getOneIntersectingObject(cls);
// if (clsActor != null)
// {
// // remove intersector and bump score
// getWorld().removeObject(clsActor);
// ((Welt)getWorld()).adjustScore(1);
// return true;
// }
// return false;
// }
//
// /**
// * internal method that returns a flag indicating world edge encroachment
// *
// * @return a flag indicating whether the actor has encroached on a world edge or not
// */
// private boolean atWorldEdge()
// {
// // return state of encroachment on world edge
// return getX() <= 0 || getY() <= 0 ||
// getX() >= getWorld().getWidth()-1 ||
// getY() >= getWorld().getHeight()-1;
// }
// }
}
| chenxuesdu/cmpe202-groupProject | Gun.java |
975 | import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
/**
* Takes in a file and removes: HTML, Punctuation and special characters
*
*/
/**
* @author Jeremy Aldrich
*
*
*/
public class P1 {
private boolean startFlag = false;
TreeNode<Term> node;
//private ArrayList<String> fileText = new ArrayList<String>();
//private ArrayList<Integer> occurList = new ArrayList<Integer>();
// private ArrayList<Term> terms = new ArrayList<Term>();
//private ArrayList<Term> termIndex = new ArrayList<Term>();
// public ArrayList<Term>getTermList() {
//
// return terms;
// }
//
public TreeNode<Term> readFile(String fileName,String docName) {
String word = null;
String wordPuncRemoved = null;
String htmlRemoved = null;
BinarySearch search = new BinarySearch();
BST bst = new BST();
try {
Scanner read = new Scanner(new File(fileName));
while(read.hasNext() ) {
String temp = null;
String tempTwo = null;
word = read.next();
boolean flag = false;
//System.out.println(word);
//System.out.println(word+" =");
if(word.isEmpty() == false)
{
htmlRemoved = removeHTML(word).replaceAll("\\s+","");
wordPuncRemoved = removePunctuation(htmlRemoved).toLowerCase();
for(int i=0;i<wordPuncRemoved.length();i++) {
if(wordPuncRemoved.charAt(i) == ' ' && i >= 1) {
flag = true;
temp = wordPuncRemoved.substring(0, i);
tempTwo = wordPuncRemoved.substring(i+1,wordPuncRemoved.length() );
//System.out.println(temp+"...."+tempTwo);
}
}
if(flag) {
temp = temp.replaceAll("\\s+","");
tempTwo = tempTwo.replaceAll("\\s+","");
if(!temp.isEmpty())
bst.add(docName,temp);
//termIndex = search.searchList(termIndex, temp,docName);
if(!tempTwo.isEmpty())
bst.add(docName,tempTwo);
//termIndex = search.searchList(termIndex, tempTwo,docName);
flag = false;
}else {
wordPuncRemoved = wordPuncRemoved.replaceAll("[\\s]*","");
if(wordPuncRemoved.isEmpty() == false) {
bst.add(docName,wordPuncRemoved);
//System.out.println(wordPuncRemoved);
//termIndex = search.searchList(termIndex, wordPuncRemoved,fileName);
}
}
//if(wordPuncRemoved.length() > 0)
// tempWord.add(wordPuncRemoved);
//wordCount++;
}
//text = removeWhiteSpace(wordPuncRemoved);
//System.out.println(wordPuncRemoved);
// if(!wordPuncRemoved.isEmpty()) {
// fileText.add(wordPuncRemoved);
// //System.out.println(wordPuncRemoved);
// }
//System.out.println(fileText);
//System.out.println(removeWhiteSpace("Test"));
//System.out.println(removeWhiteSpace("12 "));
//System.out.println(removeWhiteSpace("Test"));
//System.out.println(text);
//check for punctuation
//check for html
//check if word already exists
// if exists ++ else add to list
}
read.close();
//occurList = search.getOccurrList();
//System.out.println(occurList.size() );
//System.out.println(termIndex.size()+"\n");
// for(int i=0;i<fileText.size();i++) {
// System.out.print(fileText.get(i)+"\n");
//
// }
// for(int i=0;i<occurList.size();i++) {
// System.out.print("Index: "+i+" "+occurList.get(i)+" = "+fileText.get(i)+"\n");
// }
//System.out.println("");
//System.out.println("NUMBER OF WORDS: "+fileText.size() );
} catch (FileNotFoundException e) {
System.err.println("Error: found in output!");
}
node = bst.getNode();
return node;
}
/*
* Removes special characters including Punctuation
*
*/
private String removePunctuation(String word) {
//removes all punctuation and special characters
// adds a space so we can deal with words such as pre-req
return word.replaceAll("[&@#$%^*()\\\"\\\\/$\\-\\!\\+\\=|(){},.;:!?\\%]+", " ");
}
/*
*
* Removes the HTML tags starting with < and ending with >
*/
private String removeHTML(String word) {
String result = "";
String temp = null;
for(int i=0;i<word.length();i++) {
char character = word.charAt(i);
//if < is found we don't add that text
if(word.charAt(i) == '<') {
startFlag = true;
}
//if < is found we don't add that text
if(startFlag == true) {
//System.out.println(word.charAt(i)+" Removed");
//end bracket > found so we can continue to add now
if(character == '>') {
startFlag = false;
}
}else {
if(i == 0) {
result = Character.toString(character);
} else {
result += character;
}
}
}
temp = result;
return temp;
}
/*
* Returns the the number of occurances each word has.
* Each element matches up with the word in the textFile List
*/
//public ArrayList<Integer> getOccurrList() {
//
// return occurList;
// }
public static void main(String[] args) {
if(args.length ==0) {
System.err.println("Error: No args found!");
}
String fileName = args[0];
String docName = "test";
P1 p = new P1();
//p.readFile(fileName,docName);
}
}
| aldrichj/CS200- | P1.java |
976 | import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.*;
/**
See docs and examples at https://github.com/curtcox/Loopy-Java/
*/
public class To<X>
extends Observable
implements Iterator<X>, Collection<X>, Enumeration<X>, Runnable, Callable, Observer
{
/**
* The iterator we defer to
*/
private Iterator<X> iterator;
/**
* The loop variable value
*/
public final X x;
/**
* The arguments for this To
*/
private final List<X> args = new ArrayList();
/**
* The constructor for the (generally anonymous) class that extends this one.
*/
private final Constructor<?> extending;
/**
* The formal parameters of the extending constructor.
*/
private final Class[] formals;
/**
* The type of argument that was passed in the constructor
*/
private final Type type;
/**
* The types of arguments that can be passed in the constructor.
*/
private enum Type { VARARG, ITERATOR, ITERABLE, ENUMERATION; }
/**
* This wraps an arg, so that it can be passed through the constructor.
*/
private static final class ArgWrapper implements Iterator, Iterable, Enumeration {
/**
* The single value we hold.
*/
final Object x;
final Constructor<?> extending;
final Class[] formals;
ArgWrapper(Object x, Constructor<?> extending, Class[] formals) {
this.x = x;
this.extending = extending;
this.formals = formals;
}
public Iterator iterator() { return this; }
public boolean hasMoreElements() { return true; }
public Object nextElement() { return x; }
public boolean hasNext() { return true; }
public Object next() { return x; }
public void remove() {}
} // ArgWrapper
/**
* Override this constructor for looping through individually specified values.
*/
protected To(X... xs) {
type = Type.VARARG;
if (xs==null || xs.length==0) {
throw badArgs(xs);
}
// ArgWrapper
// This was created by the last if block in this constructor.
// Reflectively create a new normal instance.
if (xs[0] instanceof ArgWrapper) {
ArgWrapper wrapper = (ArgWrapper) xs[0];
x = (X) wrapper.x;
extending = wrapper.extending;
formals = wrapper.formals;
return;
}
extending = extendingConstructor();
formals = extending.getParameterTypes();
// single value -- we can handle this
if (xs.length == 1) {
x = xs[0];
return;
}
// Multiple values
// This is the constructor our subclass will use.
if (xs.length > 1) {
for (int i=0; i<xs.length-1; i++) {
X arg = xs[i];
args.add(arg);
newInstanceWithArg(this,arg);
}
x = xs[xs.length - 1];
args.add(x);
return;
}
throw badArgs(xs);
}
/**
* Override this constructor for looping through individually specified values.
*/
protected To(Iterable<X> iterable) {
type = Type.ITERABLE;
if (iterable==null) {
throw badArgs();
}
extending = extendingConstructor();
formals = extending.getParameterTypes();
// ArgWrapper
// This was created by the last if block in this constructor.
// Reflectively create a new normal instance.
if (iterable instanceof ArgWrapper) {
ArgWrapper wrapper = (ArgWrapper) iterable;
x = (X) wrapper.x;
return;
}
// must not be empty
Iterator i = iterable.iterator();
if (!i.hasNext()) {
throw badArgs();
}
X arg = (X) i.next();
// single value -- we can handle this
if (!i.hasNext()) {
x = arg;
args.add(arg);
return;
}
// Multiple values
// This is the constructor our subclass will use.
for (; i.hasNext(); arg = (X) i.next()) {
args.add(arg);
if (i.hasNext()) {
newInstanceWithArg(this,arg);
}
}
args.add(arg);
x = arg;
}
/**
* Override this constructor for looping through individually specified values.
*/
protected To(Iterator<X> i) {
type = Type.ITERATOR;
if (i==null) {
throw badArgs();
}
// ArgWrapper
// This was created by the last if block in this constructor.
// Reflectively create a new normal instance.
if (i instanceof ArgWrapper) {
ArgWrapper wrapper = (ArgWrapper) i;
x = (X) wrapper.x;
extending = wrapper.extending;
formals = wrapper.formals;
return;
}
extending = extendingConstructor();
formals = extending.getParameterTypes();
// must not be empty
if (!i.hasNext()) {
throw badArgs();
}
X arg = i.next();
// single value -- we can handle this
if (!i.hasNext()) {
x = arg;
args.add(arg);
return;
}
// Multiple values
// This is the constructor our subclass will use.
for (; i.hasNext(); arg = i.next()) {
args.add(arg);
if (i.hasNext()) {
newInstanceWithArg(this,arg);
}
}
args.add(arg);
x = arg;
}
/**
* Override this constructor for looping through individually specified values.
*/
protected To(Enumeration<X> e) {
type = Type.ENUMERATION;
if (e==null) {
throw badArgs();
}
// ArgWrapper
// This was created by the last if block in this constructor.
// Reflectively create a new normal instance.
if (e instanceof ArgWrapper) {
ArgWrapper wrapper = (ArgWrapper) e;
x = (X) wrapper.x;
extending = wrapper.extending;
formals = wrapper.formals;
return;
}
extending = extendingConstructor();
formals = extending.getParameterTypes();
// must not be empty
if (!e.hasMoreElements()) {
throw badArgs();
}
X arg = e.nextElement();
// single value -- we can handle this
if (!e.hasMoreElements()) {
x = arg;
args.add(arg);
return;
}
// Multiple values
// This is the constructor our subclass will use.
for (; e.hasMoreElements(); arg = e.nextElement()) {
args.add(arg);
if (e.hasMoreElements()) {
newInstanceWithArg(this,arg);
}
}
args.add(arg);
x = arg;
}
private static IllegalArgumentException badArgs(Object... xs) {
return new IllegalArgumentException("" + xs);
}
/**
* Use the same constructor that is invoking us, to create a new instance.
* We do this in order to run whatever code is in the subclass instance
* initializer again. It can refer to x, which will have the given value.
*/
private void newInstanceWithArg(To to,Object x) {
try {
newInstanceWithArgWrapper0(to,x);
} catch (IllegalArgumentException e) {
String message = x + " not valid for constructor " + extending + " taking "+ Arrays.asList(formals);
throw new IllegalArgumentException(message,e);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
setChanged();
notifyObservers(x);
}
}
private To newInstanceWithArgWrapper0(To to,Object x)
throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
Field[] declaredFields = to.getClass().getDeclaredFields();
Object[] params = new Object[formals.length];
boolean hasThis = declaredFields.length==1;
boolean varArgs = extending.isVarArgs();
ArgWrapper wrapped = new ArgWrapper(x,extending,formals);
Object arg = varArgs ? new Object[] {wrapped} : wrapped;
if (hasThis) {
params[0] = declaredFields[0].get(to);
params[1] = arg;
} else {
params[0] = arg;
}
return (To) extending.newInstance(params);
}
/**
* Return the constructor of the class that is extending this one.
*/
private static Constructor<?> extendingConstructor() {
try {
return extendingConstructor0();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
private static Constructor<?> extendingConstructor0() throws ClassNotFoundException {
Class<? extends To> c = (Class<To>) Class.forName(extendingClass());
Constructor<?> con = c.getDeclaredConstructors()[0];
return con;
}
/**
* Return the (usually anonymous) class that extends this one.
*/
private static String extendingClass() {
for (StackTraceElement e : Thread.currentThread().getStackTrace()) {
String c = e.getClassName();
if (isExtendingClass(c)) {
return c;
}
}
throw new IllegalStateException();
}
private static boolean isExtendingClass(String c) {
return c !=null &&
! c.equals(To.class.getName()) &&
! c.equals(Thread.class.getName());
}
/*
* The next set of methods are for Iteration and Enumeration.
*/
public boolean hasMoreElements() { return hasNext(); }
public X nextElement() { return next(); }
public boolean hasNext() {
if (iterator==null) {
iterator();
}
return iterator.hasNext();
}
final public void remove() { iterator.remove(); }
public X next() {
X x = (X) iterator.next();
newInstanceWithArg(this,x);
this.notifyObservers(x);
return x;
}
/**
* Run this To loop.
*/
public void run() {
for (Object x : args) {
newInstanceWithArg(this,x);
}
}
/**
* Call this To loop;
*/
public Object call() {
run();
return null;
}
/**
* Return an iterator that can be used to iterate through this loop.
*/
public Iterator<X> iterator() {
iterator = args.iterator();
return this;
}
// the next several methods are from Collection
public int size() {
return args.size();
}
public boolean isEmpty() {
return args.isEmpty();
}
public boolean contains(Object o) {
return args.contains(o);
}
public Object[] toArray() {
return args.toArray();
}
public Object[] toArray(Object[] a) {
return args.toArray(a);
}
public boolean add(X e) {
boolean flag = args.add(e);
notifyObservers(e);
return flag;
}
public boolean remove(Object o) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean containsAll(Collection c) {
return args.containsAll(c);
}
public boolean addAll(Collection<? extends X> c) {
boolean flag = args.addAll(c);
for (Object o : c) {
notifyObservers(o);
}
return flag;
}
public boolean removeAll(Collection c) {
throw new UnsupportedOperationException("Not supported yet.");
}
public boolean retainAll(Collection c) {
throw new UnsupportedOperationException("Not supported yet.");
}
public void clear() {
throw new UnsupportedOperationException("Not supported yet.");
}
public void update(Observable o, Object arg) {
if (!hasNext()) {
iterator();
}
next();
}
}
| curtcox/Loopy-Java | To.java |
978 | /*
The design principle used in the provided code is the Liskov Substitution
Principle (LSP).
This principle states that objects of a superclass should be replaceable
with objects of its subclasses without affecting the correctness of the
program.
If class B is subtype of class A, then we should be able to replace object
of A with B without breaking the behaviour of the program.
*** subclass should extend the capability of parent class not narrow it down
*/
abstract class Shape {
abstract double getArea();
}
class Rectangle extends Shape {
double width;
double height;
public Rectangle (double width, double height){
this.width = width;
this.height = height;
}
@Override
double getArea() {
return width * height;
}
}
class Square extends Shape {
double side;
public Square (double side){
this.side = side;
}
@Override
double getArea(){
return side * side;
}
}
public class L {
public static void main (){
Rectangle R = new Rectangle(4, 5);
double rectangleArea = R.getArea();
System.out.println("Area of Rectangle : "+ rectangleArea);
Square s = new Square(9);
double SquareArea = s.getArea();
System.out.println("Area of Square : "+ SquareArea);
}
}
| Lakhan-Gurjar/SOLID-Design-Principles | L.java |
979 | /*
The design principle used in the provided code is the Interface Segregation
Principle (ISP). This code also illustrates OCP.
The Interface Segregation Principle states that clients should not be
forced to depend on interfaces they do not use. It suggests that you
should break down interfaces into smaller, specific ones so that classes
implementing those interfaces are not forced to implement methods they
don't need.
In the provided code:
The Shape interface declares a single method getArea(), which is a
minimalistic approach to defining the behavior common to all shapes.
The Rectangle and Square classes implement the Shape interface, but they
only provide implementations for the getArea() method, which is relevant
to their respective shapes.
By adhering to the Interface Segregation Principle, the code ensures that
each class implements only the methods it needs, keeping the interfaces
cohesive and the classes focused on their specific responsibilities.
*/
interface Shape {
float getArea();
}
class Rectangle implements Shape {
private float length;
private float width;
public Rectangle(float length, float width) {
this.length = length;
this.width = width;
}
@Override
public float getArea() {
return length * width ;
}
}
class Square implements Shape {
float side;
public Square (float side){
this.side = side;
}
@Override
public float getArea(){
return side * side;
}
}
public class I {
public static void main(String [] arg){
Rectangle R = new Rectangle(4, 5);
float rectangleArea = R.getArea();
System.out.println("Area of Rectangle : " + rectangleArea);
Square S = new Square(4);
float SquareArea = S.getArea();
System.out.println("Area of Square : "+ SquareArea);
}
} | Lakhan-Gurjar/SOLID-Design-Principles | I.java |
982 | // 26. Remove Duplicates from Sorted Array
// Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.
// Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
// Example 1:
// Given nums = [1,1,2],
// Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively.
// It doesn't matter what you leave beyond the returned length.
// Example 2:
// Given nums = [0,0,1,1,1,2,2,3,3,4],
// Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively.
// It doesn't matter what values are set beyond the returned length.
// Clarification:
// Confused why the returned value is an integer but your answer is an array?
// Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.
// Internally you can think of this:
// nums is passed in by reference. (i.e., without making a copy)
// int len = removeDuplicates(nums);
// any modification to nums in your function would be known by the caller.
// using the length returned by your function, it prints the first len elements.
// for (int i = 0; i < len; i++) {
// print(nums[i]);
// }
// Runtime: 1 ms, faster than 99.99% of Java online submissions for Remove Duplicates from Sorted Array.
// Memory Usage: 40.9 MB, less than 84.12% of Java online submissions for Remove Duplicates from Sorted Array.
class Solution {
public int removeDuplicates(int[] nums) {
int len = nums.length;
int res = len;
if (len < 2) return len;
int head = 0;
int cur;
for (int i = 1; i < len; i++) {
cur = nums[i];
if (cur != nums[head]) {
head++;
nums[head] = cur;
} else {
res--;
}
}
return res;
}
} | ishuen/leetcode | 26.java |
983 | // 75. Sort Colors
// Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.
//
// We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.
//
// You must solve this problem without using the library's sort function.
//
//
//
// Example 1:
//
// Input: nums = [2,0,2,1,1,0]
// Output: [0,0,1,1,2,2]
// Example 2:
//
// Input: nums = [2,0,1]
// Output: [0,1,2]
// Example 3:
//
// Input: nums = [0]
// Output: [0]
// Example 4:
//
// Input: nums = [1]
// Output: [1]
//
//
// Constraints:
//
// n == nums.length
// 1 <= n <= 300
// nums[i] is 0, 1, or 2.
//
// Runtime: 0 ms, faster than 100.00% of Java online submissions for Sort Colors.
// Memory Usage: 37.5 MB, less than 60.25% of Java online submissions for Sort Colors.
class Solution {
public void sortColors(int[] nums) {
int zero = 0;
int one = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 0) {
zero++;
} else if (nums[i] == 1) {
one++;
}
}
for(int i = 0; i < nums.length; i++) {
if (i < zero) {
nums[i] = 0;
} else if (i < zero + one) {
nums[i] = 1;
} else {
nums[i] = 2;
}
}
}
}
// 0, 1, 2
// length >> 3, colors
// traverse and get count of each color
| ishuen/leetcode | 75.java |
984 | // 74. Search a 2D Matrix
// Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
//
// Integers in each row are sorted from left to right.
// The first integer of each row is greater than the last integer of the previous row.
//
//
// Example 1:
//
//
// Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3
// Output: true
// Example 2:
//
//
// Input: matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 13
// Output: false
//
//
// Constraints:
//
// m == matrix.length
// n == matrix[i].length
// 1 <= m, n <= 100
// -10^4 <= matrix[i][j], target <= 10^4
//
// Runtime: 0 ms, faster than 100.00% of Java online submissions for Search a 2D Matrix.
// Memory Usage: 38 MB, less than 97.58% of Java online submissions for Search a 2D Matrix.
class Solution {
public boolean searchMatrix(int[][] matrix, int target) {
int row = 0;
for (int i = 0; i < matrix.length; i++) {
if (matrix[i][0] == target) return true;
if (i == 0 && matrix[i][0] > target) return false;
if (i > 0 && matrix[i][0] > target) {
row = i - 1;
break;
}
if (i == matrix.length - 1 && matrix[i][0] < target) {
row = matrix.length - 1;
}
}
for (int i = 1; i < matrix[0].length; i++) {
if (matrix[row][i] == target) return true;
if (matrix[row][i] > target) return false;
}
return false;
}
}
// bucket sort but the range is not defined
// 1. to check which row a target might belong to
// 2. to check which cell in that row has the target | ishuen/leetcode | 74.java |
985 | // 52. N-Queens II
// The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other.
//
// Given an integer n, return the number of distinct solutions to the n-queens puzzle.
//
// Example 1:
//
//
// Input: n = 4
// Output: 2
// Explanation: There are two distinct solutions to the 4-queens puzzle as shown.
// Example 2:
//
// Input: n = 1
// Output: 1
//
// Constraints:
//
// 1 <= n <= 9
//
// Runtime: 1 ms, faster than 84.97% of Java online submissions for N-Queens II.
// Memory Usage: 35.8 MB, less than 71.03% of Java online submissions for N-Queens II.
class Solution {
public int totalNQueens(int n) {
boolean[][] board = new boolean[n][n];
return totalNQueens(board, 0, n);
}
private int totalNQueens(boolean[][] board, int cur, int target) {
int count = 0;
for (int i = 0; i < board.length; i++) {
board[cur][i] = true;
if (isValid(board, cur, i)) {
if (cur == target - 1) count++;
else count = count + totalNQueens(board, cur + 1, target);
}
board[cur][i] = false;
}
return count;
}
private boolean isValid(boolean[][] board, int cur, int col) {
for (int i = 1; i <= cur; i++) {
if (board[cur - i][col] == true) return false;
if (col + i < board.length && board[cur - i][col + i] == true) return false;
if (col - i >= 0 && board[cur - i][col - i] == true) return false;
}
return true;
}
} | ishuen/leetcode | 52.java |
986 | // 45. Jump Game II
// Given an array of non-negative integers nums, you are initially positioned at the first index of the array.
//
// Each element in the array represents your maximum jump length at that position.
//
// Your goal is to reach the last index in the minimum number of jumps.
//
// You can assume that you can always reach the last index.
//
//
//
// Example 1:
//
// Input: nums = [2,3,1,1,4]
// Output: 2
// Explanation: The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
// Example 2:
//
// Input: nums = [2,3,0,1,4]
// Output: 2
//
//
// Constraints:
//
// 1 <= nums.length <= 104
// 0 <= nums[i] <= 1000
//
// Runtime: 57 ms, faster than 23.60% of Java online submissions for Jump Game II.
// Memory Usage: 39.7 MB, less than 51.41% of Java online submissions for Jump Game II.
class Solution {
public int jump(int[] nums) {
int[] jumps = new int[nums.length];
Arrays.fill(jumps, Integer.MAX_VALUE);
jumps[nums.length - 1] = 0;
for (int i = nums.length - 2; i >= 0; i--) {
for (int j = 1; j <= nums[i]; j++) {
if (i + j < nums.length && jumps[i + j] != Integer.MAX_VALUE)
jumps[i] = Math.min(jumps[i], 1 + jumps[i + j]);
}
}
return jumps[0];
}
}
// Runtime: 1 ms, faster than 99.34% of Java online submissions for Jump Game II.
// Memory Usage: 40 MB, less than 34.54% of Java online submissions for Jump Game II.
class Solution {
public int jump(int[] nums) {
int i = 0;
int lastJump = 0;
int maxReachable = 0;
int jump = 0;
while (lastJump < nums.length - 1) {
maxReachable = Math.max(maxReachable, i + nums[i]);
if (i == lastJump) {
lastJump = maxReachable;
jump++;
}
i++;
}
return jump;
}
} | ishuen/leetcode | 45.java |
987 | // 47. Permutations II
// Given a collection of numbers, nums, that might contain duplicates, return all possible unique permutations in any order.
//
//
// Example 1:
//
// Input: nums = [1,1,2]
// Output:
// [[1,1,2],
// [1,2,1],
// [2,1,1]]
// Example 2:
//
// Input: nums = [1,2,3]
// Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
//
//
// Constraints:
//
// 1 <= nums.length <= 8
// -10 <= nums[i] <= 10
//
// Runtime: 1 ms, faster than 99.36% of Java online submissions for Permutations II.
// Memory Usage: 39.3 MB, less than 97.20% of Java online submissions for Permutations II.
class Solution {
public List<List<Integer>> permuteUnique(int[] nums) {
Arrays.sort(nums);
List<List<Integer>> ans = new ArrayList<>();
permutation(nums, new boolean[nums.length], new ArrayList<>(), ans);
return ans;
}
private void permutation(int[] nums, boolean[] used, List<Integer> tempList, List<List<Integer>> ans) {
if (tempList.size() == nums.length) {
ans.add(new ArrayList<>(tempList));
return;
}
for (int i = 0; i < nums.length; i++) {
if (i < nums.length - 1 && nums[i + 1] == nums[i] && used[i + 1] == used[i]) continue;
if (used[i] == true) continue;
used[i] = true;
tempList.add(nums[i]);
permutation(nums, used, tempList, ans);
tempList.remove(tempList.size() - 1);
used[i] = false;
}
}
}
| ishuen/leetcode | 47.java |
988 | // 41. First Missing Positive
// Given an unsorted integer array nums, find the smallest missing positive integer.
//
// You must implement an algorithm that runs in O(n) time and uses constant extra space.
//
// Example 1:
//
// Input: nums = [1,2,0]
// Output: 3
// Example 2:
//
// Input: nums = [3,4,-1,1]
// Output: 2
// Example 3:
//
// Input: nums = [7,8,9,11,12]
// Output: 1
//
//
// Constraints:
//
// 1 <= nums.length <= 5 * 105
// -231 <= nums[i] <= 231 - 1
//
// Runtime: 212 ms, faster than 5.34% of Java online submissions for First Missing Positive.
// Memory Usage: 100.5 MB, less than 6.07% of Java online submissions for First Missing Positive.
class Solution {
public int firstMissingPositive(int[] nums) {
PriorityQueue<Integer> pq = new PriorityQueue<>();
int count = 1;
for (int i = 0; i < nums.length; i++) {
if (nums[i] > 0) pq.add(nums[i]);
}
while (!pq.isEmpty()) {
if (pq.peek() == count) {
count++;
pq.poll();
} else if (pq.peek() == count - 1) {
pq.poll();
} else {
return count;
}
}
return count;
}
}
Runtime: 7 ms, faster than 11.82% of Java online submissions for First Missing Positive.
Memory Usage: 93.7 MB, less than 8.74% of Java online submissions for First Missing Positive.
class Solution {
public int firstMissingPositive(int[] nums) {
boolean[] arr = new boolean[nums.length];
for (int i = 0; i < nums.length; i++) {
if (nums[i] > 0 && nums[i] <= nums.length) {
arr[nums[i] - 1] = true;
}
}
for (int i = 0; i < arr.length; i++) {
if (arr[i] != true) return i + 1;
}
return arr.length + 1;
}
} | ishuen/leetcode | 41.java |
989 | // 91. Decode Ways
// A message containing letters from A-Z can be encoded into numbers using the following mapping:
//
// 'A' -> "1"
// 'B' -> "2"
// ...
// 'Z' -> "26"
// To decode an encoded message, all the digits must be grouped then mapped back into letters using the reverse of the mapping above (there may be multiple ways). For example, "11106" can be mapped into:
//
// "AAJF" with the grouping (1 1 10 6)
// "KJF" with the grouping (11 10 6)
// Note that the grouping (1 11 06) is invalid because "06" cannot be mapped into 'F' since "6" is different from "06".
//
// Given a string s containing only digits, return the number of ways to decode it.
//
// The answer is guaranteed to fit in a 32-bit integer.
//
//
//
// Example 1:
//
// Input: s = "12"
// Output: 2
// Explanation: "12" could be decoded as "AB" (1 2) or "L" (12).
// Example 2:
//
// Input: s = "226"
// Output: 3
// Explanation: "226" could be decoded as "BZ" (2 26), "VF" (22 6), or "BBF" (2 2 6).
// Example 3:
//
// Input: s = "0"
// Output: 0
// Explanation: There is no character that is mapped to a number starting with 0.
// The only valid mappings with 0 are 'J' -> "10" and 'T' -> "20", neither of which start with 0.
// Hence, there are no valid ways to decode this since all digits need to be mapped.
// Example 4:
//
// Input: s = "06"
// Output: 0
// Explanation: "06" cannot be mapped to "F" because of the leading zero ("6" is different from "06").
//
//
// Constraints:
//
// 1 <= s.length <= 100
// s contains only digits and may contain leading zero(s).
//
// Runtime: 1 ms, faster than 93.65% of Java online submissions for Decode Ways.
// Memory Usage: 37.1 MB, less than 90.95% of Java online submissions for Decode Ways.
class Solution {
public int numDecodings(String s) {
int[] counts = new int[s.length() + 1];
counts[0] = 1;
counts[1] = s.charAt(0) == '0' ? 0 : 1;
for (int i = 1; i < s.length(); i++) {
int num = Integer.parseInt(s.substring(i - 1, i + 1));
if (num >= 10 && num <= 26) counts[i + 1] += counts[i - 1];
if (s.charAt(i) != '0') counts[i + 1] += counts[i];
}
return counts[s.length()];
}
} | ishuen/leetcode | 91.java |
990 | // 68. Text Justification
// Given an array of words and a width maxWidth, format the text such that each line has exactly maxWidth characters and is fully (left and right) justified.
//
// You should pack your words in a greedy approach; that is, pack as many words as you can in each line. Pad extra spaces ' ' when necessary so that each line has exactly maxWidth characters.
//
// Extra spaces between words should be distributed as evenly as possible. If the number of spaces on a line do not divide evenly between words, the empty slots on the left will be assigned more spaces than the slots on the right.
//
// For the last line of text, it should be left justified and no extra space is inserted between words.
//
// Note:
//
// A word is defined as a character sequence consisting of non-space characters only.
// Each word's length is guaranteed to be greater than 0 and not exceed maxWidth.
// The input array words contains at least one word.
//
//
// Example 1:
//
// Input: words = ["This", "is", "an", "example", "of", "text", "justification."], maxWidth = 16
// Output:
// [
// "This is an",
// "example of text",
// "justification. "
// ]
// Example 2:
//
// Input: words = ["What","must","be","acknowledgment","shall","be"], maxWidth = 16
// Output:
// [
// "What must be",
// "acknowledgment ",
// "shall be "
// ]
// Explanation: Note that the last line is "shall be " instead of "shall be", because the last line must be left-justified instead of fully-justified.
// Note that the second line is also left-justified becase it contains only one word.
// Example 3:
//
// Input: words = ["Science","is","what","we","understand","well","enough","to","explain","to","a","computer.","Art","is","everything","else","we","do"], maxWidth = 20
// Output:
// [
// "Science is what we",
// "understand well",
// "enough to explain to",
// "a computer. Art is",
// "everything else we",
// "do "
// ]
//
//
// Constraints:
//
// 1 <= words.length <= 300
// 1 <= words[i].length <= 20
// words[i] consists of only English letters and symbols.
// 1 <= maxWidth <= 100
// words[i].length <= maxWidth
//
// Runtime: 1 ms, faster than 54.75% of Java online submissions for Text Justification.
// Memory Usage: 37.3 MB, less than 80.73% of Java online submissions for Text Justification.
class Solution {
public List<String> fullJustify(String[] words, int maxWidth) {
List<String> ans = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (String word: words) {
if (sb.length() == 0) {
sb.append(word);
} else {
if (maxWidth - sb.length() >= word.length() + 1) {
sb.append(" " + word);
} else {
ans.add(insertSpaces(sb, maxWidth));
sb = new StringBuilder();
sb.append(word);
}
}
}
if (sb.length() > 0) {
int num = maxWidth - sb.length();
for (int i = 0; i < num; i++) {
sb.append(" ");
}
ans.add(sb.toString());
}
return ans;
}
private String insertSpaces(StringBuilder sb, int maxWidth) {
int num = maxWidth - sb.length();
int count = 0;
int index = 0;
while (index < sb.length()) {
if (sb.charAt(index) != ' ') index++;
else break;
}
if (index == sb.length()) {
for (int i = 0; i < num; i++) {
sb.append(" ");
}
} else {
while(count < num) {
if (sb.charAt(index) == ' ') {
sb.insert(index, ' ');
count++;
index++;
while(sb.charAt(index) == ' ' && index < sb.length()) index++;
} else index++;
if (index > sb.length() - 1) index = 0;
}
}
return sb.toString();
}
}
// if at the beginning - add word
// else spaces > 1 + word.length => add
// else go back and expand the spaces
// if EOL add spaces | ishuen/leetcode | 68.java |
991 | // 16. 3Sum Closest
// Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would have exactly one solution.
//
//
//
// Example 1:
//
// Input: nums = [-1,2,1,-4], target = 1
// Output: 2
// Explanation: The sum that is closest to the target is 2. (-1 + 2 + 1 = 2).
//
//
// Constraints:
//
// 3 <= nums.length <= 10^3
// -10^3 <= nums[i] <= 10^3
// -10^4 <= target <= 10^4
//
// Runtime: 4 ms, faster than 86.56% of Java online submissions for 3Sum Closest.
// Memory Usage: 38.4 MB, less than 89.18% of Java online submissions for 3Sum Closest.
class Solution {
public int threeSumClosest(int[] nums, int target) {
if (nums.length == 3) return nums[0] + nums[1] + nums[2];
Arrays.sort(nums);
int start = 0;
int end = nums.length - 1;
int mid = start + 1;
int closest = nums[start] + nums[mid] + nums[end];
while(start < nums.length - 2) {
mid = start + 1;
end = nums.length - 1;
while (mid < end) {
int sum = nums[start] + nums[mid] + nums[end];
if (sum < target) {
mid++;
} else if (sum == target) return sum;
else {
end--;
}
if (Math.abs(sum - target) < Math.abs(closest - target))
closest = sum;
}
start++;
}
return closest;
}
} | ishuen/leetcode | 16.java |
992 | // 17. Letter Combinations of a Phone Number
// Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
//
// A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
//
// Example:
// Input: "23"
// Output: ["ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"].
// Note:
// Although the above answer is in lexicographical order, your answer could be in any order you want.
// Runtime: 2 ms, faster than 50.63% of Java online submissions for Letter Combinations of a Phone Number.
// Memory Usage: 38.4 MB, less than 6.16% of Java online submissions for Letter Combinations of a Phone Number.
public class Solution {
List<String> ans = new ArrayList<>();
List<String> key2 = Arrays.asList("a", "b", "c");
List<String> key3 = Arrays.asList("d", "e", "f");
List<String> key4 = Arrays.asList("g", "h", "i");
List<String> key5 = Arrays.asList("j", "k", "l");
List<String> key6 = Arrays.asList("m", "n", "o");
List<String> key7 = Arrays.asList("p", "q", "r", "s");
List<String> key8 = Arrays.asList("t", "u", "v");
List<String> key9 = Arrays.asList("w", "x", "y", "z");
Map<String, List<String>> map = new HashMap<>();
public List<String> letterCombinations(String digits) {
if (digits.length() == 0) return new ArrayList<>();
createMap();
dfs(new String(), 0, digits);
return ans;
}
private void dfs(final String str, int cur, String digits) {
String k = Character.toString(digits.charAt(cur));
if (cur == digits.length() - 1) {
map.get(k).forEach(x -> {
ans.add(str + x);
});
} else {
map.get(k).forEach(x -> {
dfs(str + x, cur + 1, digits);
});
}
}
private void createMap() {
map.put("2", key2);
map.put("3", key3);
map.put("4", key4);
map.put("5", key5);
map.put("6", key6);
map.put("7", key7);
map.put("8", key8);
map.put("9", key9);
}
}
// Runtime: 0 ms, faster than 100.00% of Java online submissions for Letter Combinations of a Phone Number.
// Memory Usage: 38.2 MB, less than 6.16% of Java online submissions for Letter Combinations of a Phone Number.
public class Solution {
List<String> ans = new ArrayList<>();
String[] phone = new String[]{"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
public List<String> letterCombinations(String digits) {
if (digits.length() == 0) return ans;
dfs(digits, 0, new StringBuilder(digits));
return ans;
}
void dfs(String digits, int i, StringBuilder sb) {
if (i == digits.length()) {
ans.add(sb.toString());
return;
}
int digit = Character.getNumericValue(digits.charAt(i));
for (char c : phone[digit - 2].toCharArray()) {
sb.setCharAt(i, c);
dfs(digits, i+1, sb);
}
}
}
| ishuen/leetcode | 17.java |
993 | // 81. Search in Rotated Sorted Array II
// There is an integer array nums sorted in non-decreasing order (not necessarily with distinct values).
//
// Before being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,4,4,5,6,6,7] might be rotated at pivot index 5 and become [4,5,6,6,7,0,1,2,4,4].
//
// Given the array nums after the rotation and an integer target, return true if target is in nums, or false if it is not in nums.
//
// You must decrease the overall operation steps as much as possible.
//
//
//
// Example 1:
//
// Input: nums = [2,5,6,0,0,1,2], target = 0
// Output: true
// Example 2:
//
// Input: nums = [2,5,6,0,0,1,2], target = 3
// Output: false
//
//
// Constraints:
//
// 1 <= nums.length <= 5000
// -104 <= nums[i] <= 104
// nums is guaranteed to be rotated at some pivot.
// -104 <= target <= 104
//
// Runtime: 1 ms, faster than 27.64% of Java online submissions for Search in Rotated Sorted Array II.
// Memory Usage: 40.7 MB, less than 10.31% of Java online submissions for Search in Rotated Sorted Array II.
class Solution {
public boolean search(int[] nums, int target) {
int start = 0;
int end = nums.length - 1;
int mid = 0;
while (start <= end) {
mid = (start + end) / 2;
if (target == nums[mid]) return true;
if (nums[start] > nums[mid]) {
if (nums[mid] < target && target <= nums[end]) {
start = mid + 1;
} else {
end = mid - 1;
}
} else if (nums[start] < nums[mid]) {
if (nums[start] <= target && target < nums[mid]) {
end = mid - 1;
} else {
start = mid + 1;
}
} else {
start++;
}
}
return false;
}
} | ishuen/leetcode | 81.java |
994 | // 62. Unique Paths
// A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).
//
// The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).
//
// How many possible unique paths are there?
//
// Example 1:
//
//
// Input: m = 3, n = 7
// Output: 28
// Example 2:
//
// Input: m = 3, n = 2
// Output: 3
// Explanation:
// From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
// 1. Right -> Down -> Down
// 2. Down -> Down -> Right
// 3. Down -> Right -> Down
// Example 3:
//
// Input: m = 7, n = 3
// Output: 28
// Example 4:
//
// Input: m = 3, n = 3
// Output: 6
//
// Constraints:
//
// 1 <= m, n <= 100
// It's guaranteed that the answer will be less than or equal to 2 * 109.
//
// Runtime: 0 ms, faster than 100.00% of Java online submissions for Unique Paths.
// Memory Usage: 37.4 MB, less than 11.54% of Java online submissions for Unique Paths.
class Solution {
public int uniquePaths(int m, int n) {
int[][] vertice = new int[m][n];
for (int i = 0; i < m; i++) {
vertice[i][0] = 1;
}
for (int i = 0; i < n; i++) {
vertice[0][i] = 1;
}
for (int i = 1; i < m; i++) {
for (int j = 1; j < n; j++) {
vertice[i][j] = vertice[i - 1][j] + vertice[i][j - 1];
}
}
return vertice[m - 1][n - 1];
}
} | ishuen/leetcode | 62.java |
995 | // 90. Subsets II
// Given an integer array nums that may contain duplicates, return all possible subsets (the power set).
//
// The solution set must not contain duplicate subsets. Return the solution in any order.
//
//
//
// Example 1:
//
// Input: nums = [1,2,2]
// Output: [[],[1],[1,2],[1,2,2],[2],[2,2]]
// Example 2:
//
// Input: nums = [0]
// Output: [[],[0]]
//
//
// Constraints:
//
// 1 <= nums.length <= 10
// -10 <= nums[i] <= 10
//
// Runtime: 1 ms, faster than 99.59% of Java online submissions for Subsets II.
// Memory Usage: 39.1 MB, less than 71.59% of Java online submissions for Subsets II.
class Solution {
public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> ans = new ArrayList<>();
ans.add(new ArrayList<>());
Arrays.sort(nums);
subset(nums, 0, new ArrayList<>(), ans);
return ans;
}
private void subset(int[] nums, int startIndex, List<Integer> tempList, List<List<Integer>> ans) {
for (int i = startIndex; i < nums.length; i++) {
List<Integer> newList = new ArrayList<>(tempList);
newList.add(nums[i]);
ans.add(newList);
subset(nums, i + 1, newList, ans);
while (i < nums.length - 1 && nums[i] == nums[i + 1]) i++;
}
}
}
| ishuen/leetcode | 90.java |
996 | // 33. Search in Rotated Sorted Array
// There is an integer array nums sorted in ascending order (with distinct values).
//
// Prior to being passed to your function, nums is rotated at an unknown pivot index k (0 <= k < nums.length) such that the resulting array is [nums[k], nums[k+1], ..., nums[n-1], nums[0], nums[1], ..., nums[k-1]] (0-indexed). For example, [0,1,2,4,5,6,7] might be rotated at pivot index 3 and become [4,5,6,7,0,1,2].
//
// Given the array nums after the rotation and an integer target, return the index of target if it is in nums, or -1 if it is not in nums.
//
// You must write an algorithm with O(log n) runtime complexity.
//
//
//
// Example 1:
//
// Input: nums = [4,5,6,7,0,1,2], target = 0
// Output: 4
// Example 2:
//
// Input: nums = [4,5,6,7,0,1,2], target = 3
// Output: -1
// Example 3:
//
// Input: nums = [1], target = 0
// Output: -1
//
//
// Constraints:
//
// 1 <= nums.length <= 5000
// -104 <= nums[i] <= 104
// All values of nums are unique.
// nums is guaranteed to be rotated at some pivot.
// -104 <= target <= 104
//
// Runtime: 0 ms, faster than 100.00% of Java online submissions for Search in Rotated Sorted Array.
// Memory Usage: 37.9 MB, less than 98.99% of Java online submissions for Search in Rotated Sorted Array.
class Solution {
public int search(int[] nums, int target) {
int start = 0;
int end = nums.length;
while (start < end) {
int mid = (start + end) / 2;
if (nums[mid] == target) return mid;
if (nums[start] < nums[mid]) {
if (target < nums[mid] && target >= nums[start]) end = mid;
else start = mid;
} else {
if (target < nums[mid] || target >= nums[start]) end = mid;
else start = mid;
}
}
return -1;
}
}
| ishuen/leetcode | 33.java |
997 | // 38. Count and Say
// The count-and-say sequence is a sequence of digit strings defined by the recursive formula:
//
// countAndSay(1) = "1"
// countAndSay(n) is the way you would "say" the digit string from countAndSay(n-1), which is then converted into a different digit string.
// To determine how you "say" a digit string, split it into the minimal number of groups so that each group is a contiguous section all of the same character. Then for each group, say the number of characters, then say the character. To convert the saying into a digit string, replace the counts with a number and concatenate every saying.
//
// For example, the saying and conversion for digit string "3322251":
//
//
// Given a positive integer n, return the nth term of the count-and-say sequence.
//
// Example 1:
//
// Input: n = 1
// Output: "1"
// Explanation: This is the base case.
// Example 2:
// Input: n = 4
// Output: "1211"
// Explanation:
// countAndSay(1) = "1"
// countAndSay(2) = say "1" = one 1 = "11"
// countAndSay(3) = say "11" = two 1's = "21"
// countAndSay(4) = say "21" = one 2 + one 1 = "12" + "11" = "1211"
//
// Constraints:
// 1 <= n <= 30
// Runtime: 4 ms, faster than 57.63% of Java online submissions for Count and Say.
// Memory Usage: 36.5 MB, less than 83.55% of Java online submissions for Count and Say.
class Solution {
public String countAndSay(int n) {
String str = "1";
if (n == 1) return str;
for (int i = 2; i <= n; i++) {
StringBuilder newStr = new StringBuilder();
char base = str.charAt(0);
int count = 0;
for (int j = 0; j < str.length(); j++) {
if (str.charAt(j) != base) {
newStr.append(count).append(base);
base = str.charAt(j);
count = 1;
} else {
count++;
}
}
newStr.append(count).append(base);
str = newStr.toString();
}
return str;
}
} | ishuen/leetcode | 38.java |
998 | // 11. Container With Most Water
// Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
//
// Note: You may not slant the container and n is at least 2.
//
// Example:
// Input: [1,8,6,2,5,4,8,3,7]
// Output: 49
// Runtime: 425 ms, faster than 8.33% of Java online submissions for Container With Most Water.
// Memory Usage: 39.9 MB, less than 94.87% of Java online submissions for Container With Most Water.
class Solution {
public int maxArea(int[] height) {
int x1 = 0;
int x2 = 1;
int cur = 0;
int max = 0;
int fin = height.length;
while (x2 < fin) {
cur = (x2 - x1) * Math.min(height[x1], height[x2]);
if (cur > max) {
max = cur;
}
if (x2 == fin - 1) {
x1 = x1 + 1;
x2 = x1 + 1;
} else {
x2 = x2 + 1;
}
}
return max;
}
}
// Runtime: 1 ms, faster than 100.00% of Java online submissions for Container With Most Water.
// Memory Usage: 40 MB, less than 94.87% of Java online submissions for Container With Most Water.
class Solution {
public int maxArea(int[] height) {
int x1 = 0;
int x2 = height.length - 1;
int max = 0;
while (x2 != x1) {
if (height[x1] > height[x2]) {
max = Math.max((x2 - x1) * height[x2], max);
x2--;
} else {
max = Math.max((x2 - x1) * height[x1], max);
x1++;
}
}
return max;
}
} | ishuen/leetcode | 11.java |
999 | // 30. Substring with Concatenation of All Words
// You are given a string s and an array of strings words. All the strings of words are of the same length.
//
// A concatenated substring in s is a substring that contains all the strings of any permutation of words concatenated.
//
// For example, if words = ["ab","cd","ef"], then "abcdef", "abefcd", "cdabef", "cdefab", "efabcd", and "efcdab" are all concatenated strings. "acdbef" is not a concatenated substring because it is not the concatenation of any permutation of words.
// Return the starting indices of all the concatenated substrings in s. You can return the answer in any order.
//
//
//
// Example 1:
//
// Input: s = "barfoothefoobarman", words = ["foo","bar"]
// Output: [0,9]
// Explanation: Since words.length == 2 and words[i].length == 3, the concatenated substring has to be of length 6.
// The substring starting at 0 is "barfoo". It is the concatenation of ["bar","foo"] which is a permutation of words.
// The substring starting at 9 is "foobar". It is the concatenation of ["foo","bar"] which is a permutation of words.
// The output order does not matter. Returning [9,0] is fine too.
// Example 2:
//
// Input: s = "wordgoodgoodgoodbestword", words = ["word","good","best","word"]
// Output: []
// Explanation: Since words.length == 4 and words[i].length == 4, the concatenated substring has to be of length 16.
// There is no substring of length 16 is s that is equal to the concatenation of any permutation of words.
// We return an empty array.
// Example 3:
//
// Input: s = "barfoofoobarthefoobarman", words = ["bar","foo","the"]
// Output: [6,9,12]
// Explanation: Since words.length == 3 and words[i].length == 3, the concatenated substring has to be of length 9.
// The substring starting at 6 is "foobarthe". It is the concatenation of ["foo","bar","the"] which is a permutation of words.
// The substring starting at 9 is "barthefoo". It is the concatenation of ["bar","the","foo"] which is a permutation of words.
// The substring starting at 12 is "thefoobar". It is the concatenation of ["the","foo","bar"] which is a permutation of words.
//
//
// Constraints:
//
// 1 <= s.length <= 104
// 1 <= words.length <= 5000
// 1 <= words[i].length <= 30
// s and words[i] consist of lowercase English letters.
//
// Runtime 168 ms Beats 30.44%
// Memory 42.8 MB Beats 91.97%
class Solution {
public List<Integer> findSubstring(String s, String[] words) {
List<Integer> ans = new ArrayList<>();
Map<String, Integer> targetCounts = new HashMap<>();
for (String word: words) {
targetCounts.put(word, targetCounts.getOrDefault(word, 0) + 1);
}
int len = words[0].length();
int totalLen = len * words.length;
for (int start = 0; start < s.length() - totalLen + 1; start++) {
Map<String, Integer> currentCounts = new HashMap<>();
int count = 0;
while (count < words.length) {
String key = s.substring(start + count * len, start + (count + 1) * len);
if (!targetCounts.containsKey(key)) break;
int current = currentCounts.getOrDefault(key, 0) + 1;
currentCounts.put(key, current);
count++;
}
if (count == words.length && checkCounts(currentCounts, targetCounts)) {
ans.add(start);
}
}
return ans;
}
private boolean checkCounts(Map<String, Integer> currentCounts, Map<String, Integer> targetCounts) {
for (String key: targetCounts.keySet()) {
int count = currentCounts.getOrDefault(key, 0);
if (count != targetCounts.get(key)) {
return false;
}
}
return true;
}
} | ishuen/leetcode | 30.java |
1,000 | // 29. Divide Two Integers
// Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator.
//
// Return the quotient after dividing dividend by divisor.
//
// The integer division should truncate toward zero, which means losing its fractional part. For example, truncate(8.345) = 8 and truncate(-2.7335) = -2.
//
// Note: Assume we are dealing with an environment that could only store integers within the 32-bit signed integer range: [β231, 231 β 1]. For this problem, assume that your function returns 231 β 1 when the division result overflows.
//
//
//
// Example 1:
//
// Input: dividend = 10, divisor = 3
// Output: 3
// Explanation: 10/3 = truncate(3.33333..) = 3.
// Example 2:
//
// Input: dividend = 7, divisor = -3
// Output: -2
// Explanation: 7/-3 = truncate(-2.33333..) = -2.
// Example 3:
//
// Input: dividend = 0, divisor = 1
// Output: 0
// Example 4:
//
// Input: dividend = 1, divisor = 1
// Output: 1
//
//
// Constraints:
//
// -231 <= dividend, divisor <= 231 - 1
// divisor != 0
//
// Runtime: 1 ms, faster than 99.98% of Java online submissions for Divide Two Integers.
// Memory Usage: 35.7 MB, less than 92.76% of Java online submissions for Divide Two Integers.
class Solution {
public int divide(int dividend, int divisor) {
boolean isNagative = dividend < 0 ^ divisor < 0;
long ldividend = Math.abs((long)dividend);
long ldivisor = Math.abs((long)divisor);
long counter = 1;
long ans = 0;
long product = ldivisor;
while (ldividend >= ldivisor) {
while (product <= ldividend) {
product = product << 1;
counter = counter << 1;
}
ans = ans + (counter >> 1);
ldividend = ldividend - (product >> 1);
product = ldivisor;
counter = 1;
}
return isNagative ? (int) ~ans + 1 : ans > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) ans;
}
} | ishuen/leetcode | 29.java |
1,001 | /*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* net.minecraft.util.math.BlockPos
*/
import i.gishreloaded.deadcode.xray.XRayData;
import net.minecraft.util.math.BlockPos;
public class by {
private BlockPos a;
private XRayData b;
public by(BlockPos blockPos, XRayData xRayData) {
this.a = blockPos;
this.b = xRayData;
}
public BlockPos a() {
return this.a;
}
public XRayData b() {
return this.b;
}
}
| n3xtbyte/deadcode-source | by.java |
1,002 | import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.mojang.authlib.GameProfile;
import de.labystudio.labymod.ConfigManager;
import de.labystudio.labymod.ModSettings;
import de.labystudio.utils.Allowed;
import de.labystudio.utils.OldSneaking;
import de.labystudio.utils.TiltSupport;
import de.labystudio.utils.TiltSupport.RenderCallback;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
public abstract class wn
extends pr
{
public wm bi = new wm(this);
private yd a = new yd();
public xi bj;
public xi bk;
protected xg bl = new xg();
protected int bm;
public float bn;
public float bo;
public int bp;
public double bq;
public double br;
public double bs;
public double bt;
public double bu;
public double bv;
protected boolean bw;
public cj bx;
private int b;
public float by;
public float bZ;
public float bz;
private cj c;
private boolean d;
private cj e;
public wl bA = new wl();
public int bB;
public int bC;
public float bD;
private int f;
private zx g;
private int h;
protected float bE = 0.1F;
protected float bF = 0.02F;
private int i;
private final GameProfile bH;
private boolean bI = false;
public ur bG;
public wn(adm worldIn, GameProfile gameProfileIn)
{
super(worldIn);
this.aq = a(gameProfileIn);
this.bH = gameProfileIn;
this.bj = new xy(this.bi, !worldIn.D, this);
this.bk = this.bj;
cj blockpos = worldIn.M();
b(blockpos.n() + 0.5D, blockpos.o() + 1, blockpos.p() + 0.5D, 0.0F, 0.0F);
this.aV = 180.0F;
this.X = 20;
}
protected void aX()
{
super.aX();
by().b(vy.e).a(1.0D);
a(vy.d).a(0.10000000149011612D);
}
protected void h()
{
super.h();
this.ac.a(16, Byte.valueOf((byte)0));
this.ac.a(17, Float.valueOf(0.0F));
this.ac.a(18, Integer.valueOf(0));
this.ac.a(10, Byte.valueOf((byte)0));
}
public zx bQ()
{
return this.g;
}
public int bR()
{
return this.h;
}
public boolean bS()
{
return this.g != null;
}
public int bT()
{
return bS() ? this.g.l() - this.h : 0;
}
public void bU()
{
if (this.g != null) {
this.g.b(this.o, this, this.h);
}
bV();
}
public void bV()
{
this.g = null;
this.h = 0;
if (!this.o.D) {
f(false);
}
}
public boolean bW()
{
return (bS()) && (this.g.b().e(this.g) == aba.d);
}
public void t_()
{
this.T = v();
if (v()) {
this.C = false;
}
if (this.g != null)
{
zx itemstack = this.bi.h();
if (itemstack == this.g)
{
if ((this.h <= 25) && (this.h % 4 == 0)) {
b(itemstack, 5);
}
if ((--this.h == 0) && (!this.o.D)) {
s();
}
}
else
{
bV();
}
}
if (this.bp > 0) {
this.bp -= 1;
}
if (bJ())
{
this.b += 1;
if (this.b > 100) {
this.b = 100;
}
if (!this.o.D) {
if (!p()) {
a(true, true, false);
} else if (this.o.w()) {
a(false, true, true);
}
}
}
else if (this.b > 0)
{
this.b += 1;
if (this.b >= 110) {
this.b = 0;
}
}
super.t_();
if ((!this.o.D) && (this.bk != null) && (!this.bk.a(this)))
{
n();
this.bk = this.bj;
}
if ((at()) && (this.bA.a)) {
N();
}
this.bq = this.bt;
this.br = this.bu;
this.bs = this.bv;
double d5 = this.s - this.bt;
double d0 = this.t - this.bu;
double d1 = this.u - this.bv;
double d2 = 10.0D;
if (d5 > d2) {
this.bq = (this.bt = this.s);
}
if (d1 > d2) {
this.bs = (this.bv = this.u);
}
if (d0 > d2) {
this.br = (this.bu = this.t);
}
if (d5 < -d2) {
this.bq = (this.bt = this.s);
}
if (d1 < -d2) {
this.bs = (this.bv = this.u);
}
if (d0 < -d2) {
this.br = (this.bu = this.t);
}
this.bt += d5 * 0.25D;
this.bv += d1 * 0.25D;
this.bu += d0 * 0.25D;
if (this.m == null) {
this.e = null;
}
if (!this.o.D)
{
this.bl.a(this);
b(na.g);
if (ai()) {
b(na.h);
}
}
int i = 29999999;
double d3 = ns.a(this.s, -2.9999999E7D, 2.9999999E7D);
double d4 = ns.a(this.u, -2.9999999E7D, 2.9999999E7D);
if ((d3 != this.s) || (d4 != this.u)) {
b(d3, this.t, d4);
}
}
public int L()
{
return this.bA.a ? 0 : 80;
}
protected String P()
{
return "game.player.swim";
}
protected String aa()
{
return "game.player.swim.splash";
}
public int aq()
{
return 10;
}
public void a(String name, float volume, float pitch)
{
this.o.a(this, name, volume, pitch);
}
protected void b(zx itemStackIn, int p_71010_2_)
{
if (itemStackIn.m() == aba.c) {
a("random.drink", 0.5F, this.o.s.nextFloat() * 0.1F + 0.9F);
}
if (itemStackIn.m() == aba.b)
{
for (int i = 0; i < p_71010_2_; i++)
{
aui vec3 = new aui((this.V.nextFloat() - 0.5D) * 0.1D, Math.random() * 0.1D + 0.1D, 0.0D);
vec3 = vec3.a(-this.z * 3.1415927F / 180.0F);
vec3 = vec3.b(-this.y * 3.1415927F / 180.0F);
double d0 = -this.V.nextFloat() * 0.6D - 0.3D;
aui vec31 = new aui((this.V.nextFloat() - 0.5D) * 0.3D, d0, 0.6D);
vec31 = vec31.a(-this.z * 3.1415927F / 180.0F);
vec31 = vec31.b(-this.y * 3.1415927F / 180.0F);
vec31 = vec31.b(this.s, this.t + aS(), this.u);
if (itemStackIn.f()) {
this.o.a(cy.K, vec31.a, vec31.b, vec31.c, vec3.a, vec3.b + 0.05D, vec3.c, new int[] { zw.b(itemStackIn.b()), itemStackIn.i() });
} else {
this.o.a(cy.K, vec31.a, vec31.b, vec31.c, vec3.a, vec3.b + 0.05D, vec3.c, new int[] { zw.b(itemStackIn.b()) });
}
}
a("random.eat", 0.5F + 0.5F * this.V.nextInt(2), (this.V.nextFloat() - this.V.nextFloat()) * 0.2F + 1.0F);
}
}
protected void s()
{
if (this.g != null)
{
b(this.g, 16);
int i = this.g.b;
zx itemstack = this.g.b(this.o, this);
if ((itemstack != this.g) || ((itemstack != null) && (itemstack.b != i)))
{
this.bi.a[this.bi.c] = itemstack;
if (itemstack.b == 0) {
this.bi.a[this.bi.c] = null;
}
}
bV();
}
}
public void a(byte id)
{
if (id == 9) {
s();
} else if (id == 23) {
this.bI = false;
} else if (id == 22) {
this.bI = true;
} else {
super.a(id);
}
}
protected boolean bD()
{
return (bn() <= 0.0F) || (bJ());
}
protected void n()
{
this.bk = this.bj;
}
public void ak()
{
if ((!this.o.D) && (av()))
{
a((pk)null);
c(false);
}
else
{
double d0 = this.s;
double d1 = this.t;
double d2 = this.u;
float f = this.y;
float f1 = this.z;
super.ak();
this.bn = this.bo;
this.bo = 0.0F;
l(this.s - d0, this.t - d1, this.u - d2);
if ((this.m instanceof tt))
{
this.z = f1;
this.y = f;
this.aI = ((tt)this.m).aI;
}
}
}
public void I()
{
a(0.6F, 1.8F);
super.I();
i(bu());
this.ax = 0;
}
protected void bK()
{
super.bK();
bx();
this.aK = this.y;
}
public void m()
{
if (this.bm > 0) {
this.bm -= 1;
}
if ((this.o.aa() == oj.a) && (this.o.Q().b("naturalRegeneration")))
{
if ((bn() < bu()) && (this.W % 20 == 0)) {
h(1.0F);
}
if ((this.bl.c()) && (this.W % 10 == 0)) {
this.bl.a(this.bl.a() + 1);
}
}
this.bi.k();
this.bn = this.bo;
super.m();
qc iattributeinstance = a(vy.d);
if (!this.o.D) {
iattributeinstance.a(this.bA.b());
}
this.aM = this.bF;
if (aw()) {
this.aM = ((float)(this.aM + this.bF * 0.3D));
}
k((float)iattributeinstance.e());
float f = ns.a(this.v * this.v + this.x * this.x);
float f1 = (float)(Math.atan(-this.w * 0.20000000298023224D) * 15.0D);
if (f > 0.1F) {
f = 0.1F;
}
if ((!this.C) || (bn() <= 0.0F)) {
f = 0.0F;
}
if ((this.C) || (bn() <= 0.0F)) {
f1 = 0.0F;
}
this.bo += (f - this.bo) * 0.4F;
this.aF += (f1 - this.aF) * 0.8F;
if ((bn() > 0.0F) && (!v()))
{
aug axisalignedbb = null;
if ((this.m != null) && (!this.m.I)) {
axisalignedbb = aR().a(this.m.aR()).b(1.0D, 0.0D, 1.0D);
} else {
axisalignedbb = aR().b(1.0D, 0.5D, 1.0D);
}
List<pk> list = this.o.b(this, axisalignedbb);
for (int i = 0; i < list.size(); i++)
{
pk entity = (pk)list.get(i);
if (!entity.I) {
d(entity);
}
}
}
}
private void d(pk p_71044_1_)
{
p_71044_1_.d(this);
}
public int bX()
{
return this.ac.c(18);
}
public void r(int p_85040_1_)
{
this.ac.b(18, Integer.valueOf(p_85040_1_));
}
public void s(int p_85039_1_)
{
int i = bX();
this.ac.b(18, Integer.valueOf(i + p_85039_1_));
}
public void a(ow cause)
{
super.a(cause);
a(0.2F, 0.2F);
b(this.s, this.t, this.u);
this.w = 0.10000000149011612D;
if (e_().equals("Notch")) {
a(new zx(zy.e, 1), true, false);
}
if (!this.o.Q().b("keepInventory")) {
this.bi.n();
}
if (cause != null)
{
this.v = (-ns.b((this.aw + this.y) * 3.1415927F / 180.0F) * 0.1F);
this.x = (-ns.a((this.aw + this.y) * 3.1415927F / 180.0F) * 0.1F);
}
else
{
this.v = (this.x = 0.0D);
}
b(na.y);
a(na.h);
}
protected String bo()
{
return "game.player.hurt";
}
protected String bp()
{
return "game.player.die";
}
public void b(pk entityIn, int amount)
{
s(amount);
Collection<auk> collection = cp().a(auu.f);
if ((entityIn instanceof wn))
{
b(na.B);
collection.addAll(cp().a(auu.e));
collection.addAll(e(entityIn));
}
else
{
b(na.z);
}
for (auk scoreobjective : collection)
{
aum score = cp().c(e_(), scoreobjective);
score.a();
}
}
private Collection<auk> e(pk p_175137_1_)
{
aul scoreplayerteam = cp().h(e_());
if (scoreplayerteam != null)
{
int i = scoreplayerteam.l().b();
if ((i >= 0) && (i < auu.i.length)) {
for (auk scoreobjective : cp().a(auu.i[i]))
{
aum score = cp().c(p_175137_1_.e_(), scoreobjective);
score.a();
}
}
}
aul scoreplayerteam1 = cp().h(p_175137_1_.e_());
if (scoreplayerteam1 != null)
{
int j = scoreplayerteam1.l().b();
if ((j >= 0) && (j < auu.h.length)) {
return cp().a(auu.h[j]);
}
}
return Lists.newArrayList();
}
public uz a(boolean dropAll)
{
return a(this.bi.a(this.bi.c, (dropAll) && (this.bi.h() != null) ? this.bi.h().b : 1), false, true);
}
public uz a(zx itemStackIn, boolean unused)
{
return a(itemStackIn, false, false);
}
public uz a(zx droppedItem, boolean dropAround, boolean traceItem)
{
if (droppedItem == null) {
return null;
}
if (droppedItem.b == 0) {
return null;
}
double d0 = this.t - 0.30000001192092896D + aS();
uz entityitem = new uz(this.o, this.s, d0, this.u, droppedItem);
entityitem.a(40);
if (traceItem) {
entityitem.c(e_());
}
if (dropAround)
{
float f = this.V.nextFloat() * 0.5F;
float f1 = this.V.nextFloat() * 3.1415927F * 2.0F;
entityitem.v = (-ns.a(f1) * f);
entityitem.x = (ns.b(f1) * f);
entityitem.w = 0.20000000298023224D;
}
else
{
float f2 = 0.3F;
entityitem.v = (-ns.a(this.y / 180.0F * 3.1415927F) * ns.b(this.z / 180.0F * 3.1415927F) * f2);
entityitem.x = (ns.b(this.y / 180.0F * 3.1415927F) * ns.b(this.z / 180.0F * 3.1415927F) * f2);
entityitem.w = (-ns.a(this.z / 180.0F * 3.1415927F) * f2 + 0.1F);
float f3 = this.V.nextFloat() * 3.1415927F * 2.0F;
f2 = 0.02F * this.V.nextFloat();
entityitem.v += Math.cos(f3) * f2;
entityitem.w += (this.V.nextFloat() - this.V.nextFloat()) * 0.1F;
entityitem.x += Math.sin(f3) * f2;
}
a(entityitem);
if (traceItem) {
b(na.v);
}
return entityitem;
}
protected void a(uz itemIn)
{
this.o.d(itemIn);
}
public float a(afh p_180471_1_)
{
float f = this.bi.a(p_180471_1_);
if (f > 1.0F)
{
int i = ack.c(this);
zx itemstack = this.bi.h();
if ((i > 0) && (itemstack != null)) {
f += i * i + 1;
}
}
if (a(pe.e)) {
f *= (1.0F + (b(pe.e).c() + 1) * 0.2F);
}
if (a(pe.f))
{
float f1 = 1.0F;
switch (b(pe.f).c())
{
case 0:
f1 = 0.3F;
break;
case 1:
f1 = 0.09F;
break;
case 2:
f1 = 0.0027F;
break;
case 3:
default:
f1 = 8.1E-4F;
}
f *= f1;
}
if ((a(arm.h)) && (!ack.j(this))) {
f /= 5.0F;
}
if (!this.C) {
f /= 5.0F;
}
return f;
}
public boolean b(afh blockToHarvest)
{
return this.bi.b(blockToHarvest);
}
public void a(dn tagCompund)
{
super.a(tagCompund);
this.aq = a(this.bH);
du nbttaglist = tagCompund.c("Inventory", 10);
this.bi.b(nbttaglist);
this.bi.c = tagCompund.f("SelectedItemSlot");
this.bw = tagCompund.n("Sleeping");
this.b = tagCompund.e("SleepTimer");
this.bD = tagCompund.h("XpP");
this.bB = tagCompund.f("XpLevel");
this.bC = tagCompund.f("XpTotal");
this.f = tagCompund.f("XpSeed");
if (this.f == 0) {
this.f = this.V.nextInt();
}
r(tagCompund.f("Score"));
if (this.bw)
{
this.bx = new cj(this);
a(true, true, false);
}
if ((tagCompund.b("SpawnX", 99)) && (tagCompund.b("SpawnY", 99)) && (tagCompund.b("SpawnZ", 99)))
{
this.c = new cj(tagCompund.f("SpawnX"), tagCompund.f("SpawnY"), tagCompund.f("SpawnZ"));
this.d = tagCompund.n("SpawnForced");
}
this.bl.a(tagCompund);
this.bA.b(tagCompund);
if (tagCompund.b("EnderItems", 9))
{
du nbttaglist1 = tagCompund.c("EnderItems", 10);
this.a.a(nbttaglist1);
}
}
public void b(dn tagCompound)
{
super.b(tagCompound);
tagCompound.a("Inventory", this.bi.a(new du()));
tagCompound.a("SelectedItemSlot", this.bi.c);
tagCompound.a("Sleeping", this.bw);
tagCompound.a("SleepTimer", (short)this.b);
tagCompound.a("XpP", this.bD);
tagCompound.a("XpLevel", this.bB);
tagCompound.a("XpTotal", this.bC);
tagCompound.a("XpSeed", this.f);
tagCompound.a("Score", bX());
if (this.c != null)
{
tagCompound.a("SpawnX", this.c.n());
tagCompound.a("SpawnY", this.c.o());
tagCompound.a("SpawnZ", this.c.p());
tagCompound.a("SpawnForced", this.d);
}
this.bl.b(tagCompound);
this.bA.a(tagCompound);
tagCompound.a("EnderItems", this.a.h());
zx itemstack = this.bi.h();
if ((itemstack != null) && (itemstack.b() != null)) {
tagCompound.a("SelectedItem", itemstack.b(new dn()));
}
}
public boolean a(ow source, float amount)
{
if (b(source)) {
return false;
}
if ((this.bA.a) && (!source.g())) {
return false;
}
this.aQ = 0;
if (bn() <= 0.0F) {
return false;
}
if ((bJ()) && (!this.o.D)) {
a(true, true, false);
}
if (source.r())
{
if (this.o.aa() == oj.a) {
amount = 0.0F;
}
if (this.o.aa() == oj.b) {
amount = amount / 2.0F + 1.0F;
}
if (this.o.aa() == oj.d) {
amount = amount * 3.0F / 2.0F;
}
}
if (amount == 0.0F) {
return false;
}
pk entity = source.j();
if (((entity instanceof wq)) && (((wq)entity).c != null)) {
entity = ((wq)entity).c;
}
return super.a(source, amount);
}
public boolean a(wn other)
{
auq team = bO();
auq team1 = other.bO();
return !team.a(team1) ? true : team == null ? true : team.g();
}
protected void j(float p_70675_1_)
{
this.bi.a(p_70675_1_);
}
public int br()
{
return this.bi.m();
}
public float bY()
{
int i = 0;
for (zx itemstack : this.bi.b) {
if (itemstack != null) {
i++;
}
}
return i / this.bi.b.length;
}
protected void d(ow damageSrc, float damageAmount)
{
if (!b(damageSrc))
{
if ((!damageSrc.e()) && (bW()) && (damageAmount > 0.0F)) {
damageAmount = (1.0F + damageAmount) * 0.5F;
}
damageAmount = b(damageSrc, damageAmount);
damageAmount = c(damageSrc, damageAmount);
float f = damageAmount;
damageAmount = Math.max(damageAmount - bN(), 0.0F);
m(bN() - (f - damageAmount));
if (damageAmount != 0.0F)
{
a(damageSrc.f());
float f1 = bn();
i(bn() - damageAmount);
bs().a(damageSrc, f1, damageAmount);
if (damageAmount < 3.4028235E37F) {
a(na.x, Math.round(damageAmount * 10.0F));
}
}
}
}
public void a(aln signTile) {}
public void a(adc cmdBlockLogic) {}
public void a(acy villager) {}
public void a(og chestInventory) {}
public void a(tp horse, og horseInventory) {}
public void a(ol guiOwner) {}
public void a(zx bookStack) {}
public boolean u(pk p_70998_1_)
{
if (v())
{
if ((p_70998_1_ instanceof og)) {
a((og)p_70998_1_);
}
return false;
}
zx itemstack = bZ();
zx itemstack1 = itemstack != null ? itemstack.k() : null;
if (!p_70998_1_.e(this))
{
if ((itemstack != null) && ((p_70998_1_ instanceof pr)))
{
if (this.bA.d) {
itemstack = itemstack1;
}
if (itemstack.a(this, (pr)p_70998_1_))
{
if ((itemstack.b <= 0) && (!this.bA.d)) {
ca();
}
return true;
}
}
return false;
}
if ((itemstack != null) && (itemstack == bZ())) {
if ((itemstack.b <= 0) && (!this.bA.d)) {
ca();
} else if ((itemstack.b < itemstack1.b) && (this.bA.d)) {
itemstack.b = itemstack1.b;
}
}
return true;
}
public zx bZ()
{
return this.bi.h();
}
public void ca()
{
this.bi.a(this.bi.c, (zx)null);
}
public double am()
{
return -0.35D;
}
public void f(pk targetEntity)
{
if (targetEntity.aD()) {
if (!targetEntity.l(this))
{
float f = (float)a(vy.e).e();
int i = 0;
float f1 = 0.0F;
if ((targetEntity instanceof pr)) {
f1 = ack.a(bA(), ((pr)targetEntity).bz());
} else {
f1 = ack.a(bA(), pw.a);
}
i += ack.a(this);
if (aw()) {
i++;
}
if ((f > 0.0F) || (f1 > 0.0F))
{
boolean flag = (this.O > 0.0F) && (!this.C) && (!k_()) && (!V()) && (!a(pe.q)) && (this.m == null) && ((targetEntity instanceof pr));
if ((flag) && (f > 0.0F)) {
f *= 1.5F;
}
f += f1;
boolean flag1 = false;
int j = ack.b(this);
if (((targetEntity instanceof pr)) && (j > 0) && (!targetEntity.at()))
{
flag1 = true;
targetEntity.e(1);
}
double d0 = targetEntity.v;
double d1 = targetEntity.w;
double d2 = targetEntity.x;
boolean flag2 = targetEntity.a(ow.a(this), f);
if (flag2)
{
if (i > 0)
{
targetEntity.g(-ns.a(this.y * 3.1415927F / 180.0F) * i * 0.5F, 0.1D, ns.b(this.y * 3.1415927F / 180.0F) * i * 0.5F);
this.v *= 0.6D;
this.x *= 0.6D;
d(false);
}
if (((targetEntity instanceof lf)) && (targetEntity.G))
{
((lf)targetEntity).a.a(new hm(targetEntity));
targetEntity.G = false;
targetEntity.v = d0;
targetEntity.w = d1;
targetEntity.x = d2;
}
if (flag) {
b(targetEntity);
}
if (f1 > 0.0F) {
c(targetEntity);
}
if (f >= 18.0F) {
b(mr.F);
}
p(targetEntity);
if ((targetEntity instanceof pr)) {
ack.a((pr)targetEntity, this);
}
ack.b(this, targetEntity);
zx itemstack = bZ();
pk entity = targetEntity;
if ((targetEntity instanceof ue))
{
ud ientitymultipart = ((ue)targetEntity).a;
if ((ientitymultipart instanceof pr)) {
entity = (pr)ientitymultipart;
}
}
if ((itemstack != null) && ((entity instanceof pr)))
{
itemstack.a((pr)entity, this);
if (itemstack.b <= 0) {
ca();
}
}
if ((targetEntity instanceof pr))
{
a(na.w, Math.round(f * 10.0F));
if (j > 0) {
targetEntity.e(j * 4);
}
}
a(0.3F);
}
else if (flag1)
{
targetEntity.N();
}
}
}
}
}
public void b(pk entityHit) {}
public void c(pk entityHit) {}
public void cb() {}
public void J()
{
super.J();
this.bj.b(this);
if (this.bk != null) {
this.bk.b(this);
}
}
public boolean aj()
{
return (!this.bw) && (super.aj());
}
public boolean cc()
{
return false;
}
public GameProfile cd()
{
return this.bH;
}
public wn.a a(cj bedLocation)
{
if (!this.o.D)
{
if ((bJ()) || (!ai())) {
return wn.a.e;
}
if (!this.o.t.d()) {
return wn.a.b;
}
if (this.o.w()) {
return wn.a.c;
}
if ((Math.abs(this.s - bedLocation.n()) > 3.0D) || (Math.abs(this.t - bedLocation.o()) > 2.0D) || (Math.abs(this.u - bedLocation.p()) > 3.0D)) {
return wn.a.d;
}
double d0 = 8.0D;
double d1 = 5.0D;
List<vv> list = this.o.a(vv.class, new aug(bedLocation.n() - d0, bedLocation.o() - d1, bedLocation.p() - d0, bedLocation.n() + d0, bedLocation.o() + d1, bedLocation.p() + d0));
if (!list.isEmpty()) {
return wn.a.f;
}
}
if (au()) {
a((pk)null);
}
a(0.2F, 0.2F);
if (this.o.e(bedLocation))
{
cq enumfacing = (cq)this.o.p(bedLocation).b(age.O);
float f = 0.5F;
float f1 = 0.5F;
switch (enumfacing)
{
case d:
f1 = 0.9F;
break;
case c:
f1 = 0.1F;
break;
case e:
f = 0.1F;
break;
case f:
f = 0.9F;
}
a(enumfacing);
b(bedLocation.n() + f, bedLocation.o() + 0.6875F, bedLocation.p() + f1);
}
else
{
b(bedLocation.n() + 0.5F, bedLocation.o() + 0.6875F, bedLocation.p() + 0.5F);
}
this.bw = true;
this.b = 0;
this.bx = bedLocation;
this.v = (this.x = this.w = 0.0D);
if (!this.o.D) {
this.o.d();
}
return wn.a.a;
}
private void a(cq p_175139_1_)
{
this.by = 0.0F;
this.bz = 0.0F;
switch (p_175139_1_)
{
case d:
this.bz = -1.8F;
break;
case c:
this.bz = 1.8F;
break;
case e:
this.by = 1.8F;
break;
case f:
this.by = -1.8F;
}
}
public void a(boolean p_70999_1_, boolean updateWorldFlag, boolean setSpawn)
{
a(0.6F, 1.8F);
alz iblockstate = this.o.p(this.bx);
if ((this.bx != null) && (iblockstate.c() == afi.C))
{
this.o.a(this.bx, iblockstate.a(afg.b, Boolean.valueOf(false)), 4);
cj blockpos = afg.a(this.o, this.bx, 0);
if (blockpos == null) {
blockpos = this.bx.a();
}
b(blockpos.n() + 0.5F, blockpos.o() + 0.1F, blockpos.p() + 0.5F);
}
this.bw = false;
if ((!this.o.D) && (updateWorldFlag)) {
this.o.d();
}
this.b = (p_70999_1_ ? 0 : 100);
if (setSpawn) {
a(this.bx, false);
}
}
private boolean p()
{
return this.o.p(this.bx).c() == afi.C;
}
public static cj a(adm worldIn, cj bedLocation, boolean forceSpawn)
{
afh block = worldIn.p(bedLocation).c();
if (block != afi.C)
{
if (!forceSpawn) {
return null;
}
boolean flag = block.g();
boolean flag1 = worldIn.p(bedLocation.a()).c().g();
return (flag) && (flag1) ? bedLocation : null;
}
return afg.a(worldIn, bedLocation, 0);
}
public float ce()
{
if (this.bx != null)
{
cq enumfacing = (cq)this.o.p(this.bx).b(age.O);
switch (enumfacing)
{
case d:
return 90.0F;
case c:
return 270.0F;
case e:
return 0.0F;
case f:
return 180.0F;
}
}
return 0.0F;
}
public boolean bJ()
{
return this.bw;
}
public boolean cf()
{
return (this.bw) && (this.b >= 100);
}
public int cg()
{
return this.b;
}
public void b(eu chatComponent) {}
public cj ch()
{
return this.c;
}
public boolean ci()
{
return this.d;
}
public void a(cj pos, boolean forced)
{
if (pos != null)
{
this.c = pos;
this.d = forced;
}
else
{
this.c = null;
this.d = false;
}
}
public void b(mw achievementIn)
{
a(achievementIn, 1);
}
public void a(mw stat, int amount) {}
public void a(mw p_175145_1_) {}
public void bF()
{
super.bF();
b(na.u);
if (aw()) {
a(0.8F);
} else {
a(0.2F);
}
}
public void g(float strafe, float forward)
{
double d0 = this.s;
double d1 = this.t;
double d2 = this.u;
if ((this.bA.b) && (this.m == null))
{
double d3 = this.w;
float f = this.aM;
this.aM = (this.bA.a() * (aw() ? 2 : 1));
super.g(strafe, forward);
this.w = (d3 * 0.6D);
this.aM = f;
}
else
{
super.g(strafe, forward);
}
k(this.s - d0, this.t - d1, this.u - d2);
}
public float bI()
{
return (float)a(vy.d).e();
}
public void k(double p_71000_1_, double p_71000_3_, double p_71000_5_)
{
if (this.m == null) {
if (a(arm.h))
{
int i = Math.round(ns.a(p_71000_1_ * p_71000_1_ + p_71000_3_ * p_71000_3_ + p_71000_5_ * p_71000_5_) * 100.0F);
if (i > 0)
{
a(na.p, i);
a(0.015F * i * 0.01F);
}
}
else if (V())
{
int j = Math.round(ns.a(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F);
if (j > 0)
{
a(na.l, j);
a(0.015F * j * 0.01F);
}
}
else if (k_())
{
if (p_71000_3_ > 0.0D) {
a(na.n, (int)Math.round(p_71000_3_ * 100.0D));
}
}
else if (this.C)
{
int k = Math.round(ns.a(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F);
if (k > 0)
{
a(na.i, k);
if (aw())
{
a(na.k, k);
a(0.099999994F * k * 0.01F);
}
else
{
if (av()) {
a(na.j, k);
}
a(0.01F * k * 0.01F);
}
}
}
else
{
int l = Math.round(ns.a(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F);
if (l > 25) {
a(na.o, l);
}
}
}
}
private void l(double p_71015_1_, double p_71015_3_, double p_71015_5_)
{
if (this.m != null)
{
int i = Math.round(ns.a(p_71015_1_ * p_71015_1_ + p_71015_3_ * p_71015_3_ + p_71015_5_ * p_71015_5_) * 100.0F);
if (i > 0) {
if ((this.m instanceof va))
{
a(na.q, i);
if (this.e == null) {
this.e = new cj(this);
} else if (this.e.c(ns.c(this.s), ns.c(this.t), ns.c(this.u)) >= 1000000.0D) {
b(mr.q);
}
}
else if ((this.m instanceof ux))
{
a(na.r, i);
}
else if ((this.m instanceof tt))
{
a(na.s, i);
}
else if ((this.m instanceof tp))
{
a(na.t, i);
}
}
}
}
public void e(float distance, float damageMultiplier)
{
if (!this.bA.c)
{
if (distance >= 2.0F) {
a(na.m, (int)Math.round(distance * 100.0D));
}
super.e(distance, damageMultiplier);
}
}
protected void X()
{
if (!v()) {
super.X();
}
}
protected String n(int damageValue)
{
return damageValue > 4 ? "game.player.hurt.fall.big" : "game.player.hurt.fall.small";
}
public void a(pr entityLivingIn)
{
if ((entityLivingIn instanceof vq)) {
b(mr.s);
}
pm.a entitylist$entityegginfo = (pm.a)pm.a.get(Integer.valueOf(pm.a(entityLivingIn)));
if (entitylist$entityegginfo != null) {
b(entitylist$entityegginfo.d);
}
}
public void aA()
{
if (!this.bA.b) {
super.aA();
}
}
public zx q(int slotIn)
{
return this.bi.e(slotIn);
}
public void u(int amount)
{
s(amount);
int i = Integer.MAX_VALUE - this.bC;
if (amount > i) {
amount = i;
}
this.bD += amount / ck();
for (this.bC += amount; this.bD >= 1.0F; this.bD /= ck())
{
this.bD = ((this.bD - 1.0F) * ck());
a(1);
}
}
public int cj()
{
return this.f;
}
public void b(int levels)
{
this.bB -= levels;
if (this.bB < 0)
{
this.bB = 0;
this.bD = 0.0F;
this.bC = 0;
}
this.f = this.V.nextInt();
}
public void a(int levels)
{
this.bB += levels;
if (this.bB < 0)
{
this.bB = 0;
this.bD = 0.0F;
this.bC = 0;
}
if ((levels > 0) && (this.bB % 5 == 0) && (this.i < this.W - 100.0F))
{
float f = this.bB > 30 ? 1.0F : this.bB / 30.0F;
this.o.a(this, "random.levelup", f * 0.75F, 1.0F);
this.i = this.W;
}
}
public int ck()
{
return this.bB >= 15 ? 37 + (this.bB - 15) * 5 : this.bB >= 30 ? 112 + (this.bB - 30) * 9 : 7 + this.bB * 2;
}
public void a(float p_71020_1_)
{
if (!this.bA.a) {
if (!this.o.D) {
this.bl.a(p_71020_1_);
}
}
}
public xg cl()
{
return this.bl;
}
public boolean j(boolean ignoreHunger)
{
return ((ignoreHunger) || (this.bl.c())) && (!this.bA.a);
}
public boolean cm()
{
return (bn() > 0.0F) && (bn() < bu());
}
public void a(zx stack, int duration)
{
if (stack != this.g)
{
this.g = stack;
this.h = duration;
if (!this.o.D) {
f(true);
}
}
}
public boolean cn()
{
return this.bA.e;
}
public boolean a(cj p_175151_1_, cq p_175151_2_, zx p_175151_3_)
{
if (this.bA.e) {
return true;
}
if (p_175151_3_ == null) {
return false;
}
cj blockpos = p_175151_1_.a(p_175151_2_.d());
afh block = this.o.p(blockpos).c();
return (p_175151_3_.d(block)) || (p_175151_3_.x());
}
protected int b(wn player)
{
if (this.o.Q().b("keepInventory")) {
return 0;
}
int i = this.bB * 7;
return i > 100 ? 100 : i;
}
protected boolean bb()
{
return true;
}
public boolean aO()
{
return true;
}
public void a(wn oldPlayer, boolean respawnFromEnd)
{
if (respawnFromEnd)
{
this.bi.b(oldPlayer.bi);
i(oldPlayer.bn());
this.bl = oldPlayer.bl;
this.bB = oldPlayer.bB;
this.bC = oldPlayer.bC;
this.bD = oldPlayer.bD;
r(oldPlayer.bX());
this.an = oldPlayer.an;
this.ao = oldPlayer.ao;
this.ap = oldPlayer.ap;
}
else if (this.o.Q().b("keepInventory"))
{
this.bi.b(oldPlayer.bi);
this.bB = oldPlayer.bB;
this.bC = oldPlayer.bC;
this.bD = oldPlayer.bD;
r(oldPlayer.bX());
}
this.f = oldPlayer.f;
this.a = oldPlayer.a;
H().b(10, Byte.valueOf(oldPlayer.H().a(10)));
}
protected boolean s_()
{
return !this.bA.b;
}
public void t() {}
public void a(adp.a gameType) {}
public String e_()
{
return this.bH.getName();
}
public yd co()
{
return this.a;
}
public zx p(int slotIn)
{
return slotIn == 0 ? this.bi.h() : this.bi.b[(slotIn - 1)];
}
public zx bA()
{
return this.bi.h();
}
public void c(int slotIn, zx stack)
{
this.bi.b[slotIn] = stack;
}
public boolean f(wn player)
{
if (!ax()) {
return false;
}
if (player.v()) {
return false;
}
auq team = bO();
return (team == null) || (player == null) || (player.bO() != team) || (!team.h());
}
public abstract boolean v();
public zx[] as()
{
return this.bi.b;
}
public boolean aL()
{
return !this.bA.b;
}
public auo cp()
{
return this.o.Z();
}
public auq bO()
{
return cp().h(e_());
}
public eu f_()
{
eu ichatcomponent = new fa(aul.a(bO(), e_()));
ichatcomponent.b().a(new et(et.a.e, "/msg " + e_() + " "));
ichatcomponent.b().a(aQ());
ichatcomponent.b().a(e_());
return ichatcomponent;
}
public float aS()
{
float f = 1.62F;
if (bJ()) {
f = 0.2F;
}
if (av()) {
f -= 0.08F;
}
if ((ConfigManager.settings.oldSneak) && (ave.A().h != null) && (equals(ave.A().h)) &&
(ave.A().t.aA == 0) && (Allowed.sneakingAnimation())) {
f = OldSneaking.getCustomEyeHeight(this);
}
if (TiltSupport.tiltCamera != null) {
TiltSupport.tiltCamera.render(this);
}
return f;
}
public void m(float amount)
{
if (amount < 0.0F) {
amount = 0.0F;
}
H().b(17, Float.valueOf(amount));
}
public float bN()
{
return H().d(17);
}
public static UUID a(GameProfile profile)
{
UUID uuid = profile.getId();
if (uuid == null) {
uuid = b(profile.getName());
}
return uuid;
}
public static UUID b(String username)
{
return UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes(Charsets.UTF_8));
}
public boolean a(on code)
{
if (code.a()) {
return true;
}
zx itemstack = bZ();
return (itemstack != null) && (itemstack.s()) ? itemstack.q().equals(code.b()) : false;
}
public boolean a(wo p_175148_1_)
{
return (H().a(10) & p_175148_1_.a()) == p_175148_1_.a();
}
public boolean u_()
{
return net.minecraft.server.MinecraftServer.N().d[0].Q().b("sendCommandFeedback");
}
public boolean d(int inventorySlot, zx itemStackIn)
{
if ((inventorySlot >= 0) && (inventorySlot < this.bi.a.length))
{
this.bi.a(inventorySlot, itemStackIn);
return true;
}
int i = inventorySlot - 100;
if ((i >= 0) && (i < this.bi.b.length))
{
int k = i + 1;
if ((itemStackIn != null) && (itemStackIn.b() != null)) {
if ((itemStackIn.b() instanceof yj))
{
if (ps.c(itemStackIn) != k) {
return false;
}
}
else if ((k != 4) || ((itemStackIn.b() != zy.bX) && (!(itemStackIn.b() instanceof yo)))) {
return false;
}
}
this.bi.a(i + this.bi.a.length, itemStackIn);
return true;
}
int j = inventorySlot - 200;
if ((j >= 0) && (j < this.a.o_()))
{
this.a.a(j, itemStackIn);
return true;
}
return false;
}
public boolean cq()
{
return this.bI;
}
public void k(boolean reducedDebug)
{
this.bI = reducedDebug;
}
public static enum a
{
private a() {}
}
public static enum b
{
private static final b[] d;
private final int e;
private final String f;
private b(int id, String resourceKey)
{
this.e = id;
this.f = resourceKey;
}
public int a()
{
return this.e;
}
public static b a(int id)
{
return d[(id % d.length)];
}
public String b()
{
return this.f;
}
static
{
d = new b[values().length];
for (b entityplayer$enumchatvisibility : values()) {
d[entityplayer$enumchatvisibility.e] = entityplayer$enumchatvisibility;
}
}
}
}
| Tominous/LabyMod-1.8 | wn.java |
1,003 | import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import net.minecraft.server.MinecraftServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public abstract class rr
implements m
{
private static final Logger a = ;
private static final bbh b = new bbh(0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D);
private static double c = 1.0D;
private static int f;
private int g = f++;
public boolean i;
private final List<rr> h = Lists.newArrayList();
protected int j;
private rr as;
public boolean k;
public aht l;
public double m;
public double n;
public double o;
public double p;
public double q;
public double r;
public double s;
public double t;
public double u;
public float v;
public float w;
public float x;
public float y;
private bbh at = b;
public boolean z;
public boolean A;
public boolean B;
public boolean C;
public boolean D;
protected boolean E;
private boolean au;
public boolean F;
public float G = 0.6F;
public float H = 1.8F;
public float I;
public float J;
public float K;
public float L;
private int av = 1;
public double M;
public double N;
public double O;
public float P;
public boolean Q;
public float R;
protected Random S = new Random();
public int T;
public int U = 1;
private int aw;
protected boolean V;
public int W;
protected boolean X = true;
protected boolean Y;
protected kh Z;
private static final ke<Byte> ax = kh.a(rr.class, kg.a);
private static final ke<Integer> ay = kh.a(rr.class, kg.b);
private static final ke<String> az = kh.a(rr.class, kg.d);
private static final ke<Boolean> aA = kh.a(rr.class, kg.h);
private static final ke<Boolean> aB = kh.a(rr.class, kg.h);
public boolean aa;
public int ab;
public int ac;
public int ad;
public long ae;
public long af;
public long ag;
public boolean ah;
public boolean ai;
public int aj;
protected boolean ak;
protected int al;
public int am;
protected cj an;
protected bbj ao;
protected cq ap;
private boolean aC;
protected UUID aq = on.a(this.S);
private final n aD = new n();
private final List<adq> aE = Lists.newArrayList();
protected boolean ar;
private final Set<String> aF = Sets.newHashSet();
private boolean aG;
public rr(aht β)
{
this.l = β;
b(0.0D, 0.0D, 0.0D);
if (β != null) {
this.am = β.s.p().a();
}
this.Z = new kh(this);
this.Z.a(ax, Byte.valueOf((byte)0));
this.Z.a(ay, Integer.valueOf(300));
this.Z.a(aA, Boolean.valueOf(false));
this.Z.a(az, "");
this.Z.a(aB, Boolean.valueOf(false));
i();
}
public int O()
{
return this.g;
}
public void f(int β)
{
this.g = β;
}
public Set<String> P()
{
return this.aF;
}
public boolean a(String β)
{
if (this.aF.size() >= 1024) {
return false;
}
this.aF.add(β);
return true;
}
public boolean b(String β)
{
return this.aF.remove(β);
}
public void Q()
{
T();
}
protected abstract void i();
public kh R()
{
return this.Z;
}
public boolean equals(Object β)
{
if ((β instanceof rr)) {
return ((rr)β).g == this.g;
}
return false;
}
public int hashCode()
{
return this.g;
}
protected void S()
{
if (this.l == null) {
return;
}
while ((this.q > 0.0D) && (this.q < 256.0D))
{
b(this.p, this.q, this.r);
if (this.l.a(this, bl()).isEmpty()) {
break;
}
this.q += 1.0D;
}
this.s = (this.t = this.u = 0.0D);
this.w = 0.0F;
}
public void T()
{
this.F = true;
}
public void b(boolean β) {}
protected void a(float β, float β)
{
if ((β != this.G) || (β != this.H))
{
float β = this.G;
this.G = β;
this.H = β;
bbh β = bl();
a(new bbh(β.a, β.b, β.c, β.a + this.G, β.b + this.H, β.c + this.G));
if ((this.G > β) && (!this.X) && (!this.l.E)) {
d(β - this.G, 0.0D, β - this.G);
}
}
}
protected void b(float β, float β)
{
this.v = (β % 360.0F);
this.w = (β % 360.0F);
}
public void b(double β, double β, double β)
{
this.p = β;
this.q = β;
this.r = β;
float β = this.G / 2.0F;
float β = this.H;
a(new bbh(β - β, β, β - β, β + β, β + β, β + β));
}
public void c(float β, float β)
{
float β = this.w;
float β = this.v;
this.v = ((float)(this.v + β * 0.15D));
this.w = ((float)(this.w - β * 0.15D));
this.w = on.a(this.w, -90.0F, 90.0F);
this.y += this.w - β;
this.x += this.v - β;
if (this.as != null) {
this.as.l(this);
}
}
public void m()
{
if (!this.l.E) {
b(6, aM());
}
U();
}
public void U()
{
this.l.C.a("entityBaseTick");
if ((aI()) && (by().F)) {
p();
}
if (this.j > 0) {
this.j -= 1;
}
this.I = this.J;
this.m = this.p;
this.n = this.q;
this.o = this.r;
this.y = this.w;
this.x = this.v;
if ((!this.l.E) && ((this.l instanceof lp)))
{
this.l.C.a("portal");
if (this.ak)
{
MinecraftServer β = this.l.u();
if (β.E())
{
if (!aI())
{
int β = V();
if (this.al++ >= β)
{
this.al = β;
this.aj = aC();
int β;
int β;
if (this.l.s.p().a() == -1) {
β = 0;
} else {
β = -1;
}
c(β);
}
}
this.ak = false;
}
}
else
{
if (this.al > 0) {
this.al -= 4;
}
if (this.al < 0) {
this.al = 0;
}
}
H();
this.l.C.b();
}
al();
aj();
if (this.l.E) {
this.aw = 0;
} else if (this.aw > 0) {
if (this.Y)
{
this.aw -= 4;
if (this.aw < 0) {
this.aw = 0;
}
}
else
{
if (this.aw % 20 == 0) {
a(rc.c, 1.0F);
}
this.aw -= 1;
}
}
if (an())
{
W();
this.L *= 0.5F;
}
if (this.q < -64.0D) {
Y();
}
if (!this.l.E) {
b(0, this.aw > 0);
}
this.X = false;
this.l.C.b();
}
protected void H()
{
if (this.aj > 0) {
this.aj -= 1;
}
}
public int V()
{
return 1;
}
protected void W()
{
if (this.Y) {
return;
}
a(rc.d, 4.0F);
g(15);
}
public void g(int β)
{
int β = β * 20;
if ((this instanceof sa)) {
β = agy.a((sa)this, β);
}
if (this.aw < β) {
this.aw = β;
}
}
public void X()
{
this.aw = 0;
}
protected void Y()
{
T();
}
public boolean c(double β, double β, double β)
{
bbh β = bl().c(β, β, β);
return b(β);
}
private boolean b(bbh β)
{
return (this.l.a(this, β).isEmpty()) && (!this.l.e(β));
}
public void d(double β, double β, double β)
{
if (this.Q)
{
a(bl().c(β, β, β));
Z();
return;
}
this.l.C.a("move");
double β = this.p;
double β = this.q;
double β = this.r;
if (this.E)
{
this.E = false;
β *= 0.25D;
β *= 0.05000000074505806D;
β *= 0.25D;
this.s = 0.0D;
this.t = 0.0D;
this.u = 0.0D;
}
double β = β;
double β = β;
double β = β;
boolean β = (this.z) && (aK()) && ((this instanceof zj));
if (β)
{
double β = 0.05D;
while ((β != 0.0D) && (this.l.a(this, bl().c(β, -1.0D, 0.0D)).isEmpty()))
{
if ((β < β) && (β >= -β)) {
β = 0.0D;
} else if (β > 0.0D) {
β -= β;
} else {
β += β;
}
β = β;
}
while ((β != 0.0D) && (this.l.a(this, bl().c(0.0D, -1.0D, β)).isEmpty()))
{
if ((β < β) && (β >= -β)) {
β = 0.0D;
} else if (β > 0.0D) {
β -= β;
} else {
β += β;
}
β = β;
}
while ((β != 0.0D) && (β != 0.0D) && (this.l.a(this, bl().c(β, -1.0D, β)).isEmpty()))
{
if ((β < β) && (β >= -β)) {
β = 0.0D;
} else if (β > 0.0D) {
β -= β;
} else {
β += β;
}
β = β;
if ((β < β) && (β >= -β)) {
β = 0.0D;
} else if (β > 0.0D) {
β -= β;
} else {
β += β;
}
β = β;
}
}
List<bbh> β = this.l.a(this, bl().a(β, β, β));
bbh β = bl();
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).b(bl(), β);
}
a(bl().c(0.0D, β, 0.0D));
boolean β = (this.z) || ((β != β) && (β < 0.0D));
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).a(bl(), β);
}
a(bl().c(β, 0.0D, 0.0D));
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).c(bl(), β);
}
a(bl().c(0.0D, 0.0D, β));
if ((this.P > 0.0F) && (β) && ((β != β) || (β != β)))
{
double β = β;
double β = β;
double β = β;
bbh β = bl();
a(β);
β = β;
β = this.P;
β = β;
List<bbh> β = this.l.a(this, bl().a(β, β, β));
bbh β = bl();
bbh β = β.a(β, 0.0D, β);
double β = β;
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).b(β, β);
}
β = β.c(0.0D, β, 0.0D);
double β = β;
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).a(β, β);
}
β = β.c(β, 0.0D, 0.0D);
double β = β;
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).c(β, β);
}
β = β.c(0.0D, 0.0D, β);
bbh β = bl();
double β = β;
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).b(β, β);
}
β = β.c(0.0D, β, 0.0D);
double β = β;
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).a(β, β);
}
β = β.c(β, 0.0D, 0.0D);
double β = β;
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).c(β, β);
}
β = β.c(0.0D, 0.0D, β);
double β = β * β + β * β;
double β = β * β + β * β;
if (β > β)
{
β = β;
β = β;
β = -β;
a(β);
}
else
{
β = β;
β = β;
β = -β;
a(β);
}
int β = 0;
for (int β = β.size(); β < β; β++) {
β = ((bbh)β.get(β)).b(bl(), β);
}
a(bl().c(0.0D, β, 0.0D));
if (β * β + β * β >= β * β + β * β)
{
β = β;
β = β;
β = β;
a(β);
}
}
this.l.C.b();
this.l.C.a("rest");
Z();
this.A = ((β != β) || (β != β));
this.B = (β != β);
this.z = ((this.B) && (β < 0.0D));
this.C = ((this.A) || (this.B));
int β = on.c(this.p);
int β = on.c(this.q - 0.20000000298023224D);
int β = on.c(this.r);
cj β = new cj(β, β, β);
arc β = this.l.o(β);
if (β.a() == axe.a)
{
cj β = β.b();
arc β = this.l.o(β);
ajt β = β.t();
if (((β instanceof alj)) || ((β instanceof apk)) || ((β instanceof alk)))
{
β = β;
β = β;
}
}
a(β, this.z, β, β);
if (β != β) {
this.s = 0.0D;
}
if (β != β) {
this.u = 0.0D;
}
ajt β = β.t();
if (β != β) {
β.a(this.l, this);
}
if ((ae()) && (!β) && (!aI()))
{
double β = this.p - β;
double β = this.q - β;
double β = this.r - β;
if (β != aju.au) {
β = 0.0D;
}
if ((β != null) && (this.z)) {
β.a(this.l, β, this);
}
this.J = ((float)(this.J + on.a(β * β + β * β) * 0.6D));
this.K = ((float)(this.K + on.a(β * β + β * β + β * β) * 0.6D));
if ((this.K > this.av) && (β.a() != axe.a))
{
this.av = ((int)this.K + 1);
if (ai())
{
float β = on.a(this.s * this.s * 0.20000000298023224D + this.t * this.t + this.u * this.u * 0.20000000298023224D) * 0.35F;
if (β > 1.0F) {
β = 1.0F;
}
a(aa(), β, 1.0F + (this.S.nextFloat() - this.S.nextFloat()) * 0.4F);
}
a(β, β);
}
}
try
{
ac();
}
catch (Throwable β)
{
b β = b.a(β, "Checking entity block collision");
c β = β.a("Entity being checked for collision");
a(β);
throw new e(β);
}
boolean β = ah();
if (this.l.f(bl().h(0.001D)))
{
h(1);
if (!β)
{
this.aw += 1;
if (this.aw == 0) {
g(8);
}
}
}
else if (this.aw <= 0)
{
this.aw = (-this.U);
}
if ((β) && (this.aw > 0))
{
a(ng.bE, 0.7F, 1.6F + (this.S.nextFloat() - this.S.nextFloat()) * 0.4F);
this.aw = (-this.U);
}
this.l.C.b();
}
public void Z()
{
bbh β = bl();
this.p = ((β.a + β.d) / 2.0D);
this.q = β.b;
this.r = ((β.c + β.f) / 2.0D);
}
protected nf aa()
{
return ng.bI;
}
protected nf ab()
{
return ng.bH;
}
protected void ac()
{
bbh β = bl();
cj.b β = cj.b.c(β.a + 0.001D, β.b + 0.001D, β.c + 0.001D);
cj.b β = cj.b.c(β.d - 0.001D, β.e - 0.001D, β.f - 0.001D);
cj.b β = cj.b.s();
if (this.l.a(β, β)) {
for (int β = β.p(); β <= β.p(); β++) {
for (int β = β.q(); β <= β.q(); β++) {
for (int β = β.r(); β <= β.r(); β++)
{
β.d(β, β, β);
arc β = this.l.o(β);
try
{
β.t().a(this.l, β, β, this);
}
catch (Throwable β)
{
b β = b.a(β, "Colliding entity with block");
c β = β.a("Block being collided with");
c.a(β, β, β);
throw new e(β);
}
}
}
}
}
β.t();
β.t();
β.t();
}
protected void a(cj β, ajt β)
{
aop β = β.w();
if (this.l.o(β.a()).t() == aju.aH)
{
β = aju.aH.w();
a(β.d(), β.a() * 0.15F, β.b());
}
else if (!β.u().a().d())
{
a(β.d(), β.a() * 0.15F, β.b());
}
}
public void a(nf β, float β, float β)
{
if (!ad()) {
this.l.a(null, this.p, this.q, this.r, β, bz(), β, β);
}
}
public boolean ad()
{
return ((Boolean)this.Z.a(aB)).booleanValue();
}
public void c(boolean β)
{
this.Z.b(aB, Boolean.valueOf(β));
}
protected boolean ae()
{
return true;
}
protected void a(double β, boolean β, arc β, cj β)
{
if (β)
{
if (this.L > 0.0F) {
β.t().a(this.l, β, this, this.L);
}
this.L = 0.0F;
}
else if (β < 0.0D)
{
this.L = ((float)(this.L - β));
}
}
public bbh af()
{
return null;
}
protected void h(int β)
{
if (!this.Y) {
a(rc.a, β);
}
}
public final boolean ag()
{
return this.Y;
}
public void e(float β, float β)
{
if (aJ()) {
for (rr β : bu()) {
β.e(β, β);
}
}
}
public boolean ah()
{
if (this.V) {
return true;
}
cj.b β = cj.b.c(this.p, this.q, this.r);
if ((!this.l.B(β)) && (!this.l.B(β.d(this.p, this.q + this.H, this.r))))
{
β.t();
return false;
}
β.t();
return true;
}
public boolean ai()
{
return this.V;
}
public boolean aj()
{
if ((by() instanceof aag))
{
this.V = false;
}
else if (this.l.a(bl().b(0.0D, -0.4000000059604645D, 0.0D).h(0.001D), axe.h, this))
{
if ((!this.V) && (!this.X)) {
ak();
}
this.L = 0.0F;
this.V = true;
this.aw = 0;
}
else
{
this.V = false;
}
return this.V;
}
protected void ak()
{
float β = on.a(this.s * this.s * 0.20000000298023224D + this.t * this.t + this.u * this.u * 0.20000000298023224D) * 0.2F;
if (β > 1.0F) {
β = 1.0F;
}
a(ab(), β, 1.0F + (this.S.nextFloat() - this.S.nextFloat()) * 0.4F);
float β = on.c(bl().b);
for (int β = 0; β < 1.0F + this.G * 20.0F; β++)
{
float β = (this.S.nextFloat() * 2.0F - 1.0F) * this.G;
float β = (this.S.nextFloat() * 2.0F - 1.0F) * this.G;
this.l.a(cy.e, this.p + β, β + 1.0F, this.r + β, this.s, this.t - this.S.nextFloat() * 0.2F, this.u, new int[0]);
}
for (int β = 0; β < 1.0F + this.G * 20.0F; β++)
{
float β = (this.S.nextFloat() * 2.0F - 1.0F) * this.G;
float β = (this.S.nextFloat() * 2.0F - 1.0F) * this.G;
this.l.a(cy.f, this.p + β, β + 1.0F, this.r + β, this.s, this.t, this.u, new int[0]);
}
}
public void al()
{
if ((aL()) && (!ai())) {
am();
}
}
protected void am()
{
int β = on.c(this.p);
int β = on.c(this.q - 0.20000000298023224D);
int β = on.c(this.r);
cj β = new cj(β, β, β);
arc β = this.l.o(β);
if (β.i() != aob.a) {
this.l.a(cy.L, this.p + (this.S.nextFloat() - 0.5D) * this.G, bl().b + 0.1D, this.r + (this.S.nextFloat() - 0.5D) * this.G, -this.s * 4.0D, 1.5D, -this.u * 4.0D, new int[] { ajt.j(β) });
}
}
public boolean a(axe β)
{
if ((by() instanceof aag)) {
return false;
}
double β = this.q + bn();
cj β = new cj(this.p, β, this.r);
arc β = this.l.o(β);
if (β.a() == β)
{
float β = amo.e(β.t().e(β)) - 0.11111111F;
float β = β.q() + 1 - β;
boolean β = β < β;
if ((!β) && ((this instanceof zj))) {
return false;
}
return β;
}
return false;
}
public boolean an()
{
return this.l.a(bl().b(-0.10000000149011612D, -0.4000000059604645D, -0.10000000149011612D), axe.i);
}
public void a(float β, float β, float β)
{
float β = β * β + β * β;
if (β < 1.0E-4F) {
return;
}
β = on.c(β);
if (β < 1.0F) {
β = 1.0F;
}
β = β / β;
β *= β;
β *= β;
float β = on.a(this.v * 0.017453292F);
float β = on.b(this.v * 0.017453292F);
this.s += β * β - β * β;
this.u += β * β + β * β;
}
public int d(float β)
{
cj.a β = new cj.a(on.c(this.p), 0, on.c(this.r));
if (this.l.e(β))
{
β.p(on.c(this.q + bn()));
return this.l.b(β, 0);
}
return 0;
}
public float e(float β)
{
cj.a β = new cj.a(on.c(this.p), 0, on.c(this.r));
if (this.l.e(β))
{
β.p(on.c(this.q + bn()));
return this.l.n(β);
}
return 0.0F;
}
public void a(aht β)
{
this.l = β;
}
public void a(double β, double β, double β, float β, float β)
{
this.m = (this.p = on.a(β, -3.0E7D, 3.0E7D));
this.n = (this.q = β);
this.o = (this.r = on.a(β, -3.0E7D, 3.0E7D));
β = on.a(β, -90.0F, 90.0F);
this.x = (this.v = β);
this.y = (this.w = β);
double β = this.x - β;
if (β < -180.0D) {
this.x += 360.0F;
}
if (β >= 180.0D) {
this.x -= 360.0F;
}
b(this.p, this.q, this.r);
b(β, β);
}
public void a(cj β, float β, float β)
{
b(β.p() + 0.5D, β.q(), β.r() + 0.5D, β, β);
}
public void b(double β, double β, double β, float β, float β)
{
this.M = (this.m = this.p = β);
this.N = (this.n = this.q = β);
this.O = (this.o = this.r = β);
this.v = β;
this.w = β;
b(this.p, this.q, this.r);
}
public float g(rr β)
{
float β = (float)(this.p - β.p);
float β = (float)(this.q - β.q);
float β = (float)(this.r - β.r);
return on.c(β * β + β * β + β * β);
}
public double e(double β, double β, double β)
{
double β = this.p - β;
double β = this.q - β;
double β = this.r - β;
return β * β + β * β + β * β;
}
public double c(cj β)
{
return β.e(this.p, this.q, this.r);
}
public double d(cj β)
{
return β.f(this.p, this.q, this.r);
}
public double f(double β, double β, double β)
{
double β = this.p - β;
double β = this.q - β;
double β = this.r - β;
return on.a(β * β + β * β + β * β);
}
public double h(rr β)
{
double β = this.p - β.p;
double β = this.q - β.q;
double β = this.r - β.r;
return β * β + β * β + β * β;
}
public void d(zj β) {}
public void i(rr β)
{
if (x(β)) {
return;
}
if ((β.Q) || (this.Q)) {
return;
}
double β = β.p - this.p;
double β = β.r - this.r;
double β = on.a(β, β);
if (β >= 0.009999999776482582D)
{
β = on.a(β);
β /= β;
β /= β;
double β = 1.0D / β;
if (β > 1.0D) {
β = 1.0D;
}
β *= β;
β *= β;
β *= 0.05000000074505806D;
β *= 0.05000000074505806D;
β *= (1.0F - this.R);
β *= (1.0F - this.R);
if (!aJ()) {
g(-β, 0.0D, -β);
}
if (!β.aJ()) {
β.g(β, 0.0D, β);
}
}
}
public void g(double β, double β, double β)
{
this.s += β;
this.t += β;
this.u += β;
this.ai = true;
}
protected void ao()
{
this.D = true;
}
public boolean a(rc β, float β)
{
if (b(β)) {
return false;
}
ao();
return false;
}
public bbj f(float β)
{
if (β == 1.0F) {
return f(this.w, this.v);
}
float β = this.y + (this.w - this.y) * β;
float β = this.x + (this.v - this.x) * β;
return f(β, β);
}
protected final bbj f(float β, float β)
{
float β = on.b(-β * 0.017453292F - 3.1415927F);
float β = on.a(-β * 0.017453292F - 3.1415927F);
float β = -on.b(-β * 0.017453292F);
float β = on.a(-β * 0.017453292F);
return new bbj(β * β, β, β * β);
}
public bbj g(float β)
{
if (β == 1.0F) {
return new bbj(this.p, this.q + bn(), this.r);
}
double β = this.m + (this.p - this.m) * β;
double β = this.n + (this.q - this.n) * β + bn();
double β = this.o + (this.r - this.o) * β;
return new bbj(β, β, β);
}
public bbi a(double β, float β)
{
bbj β = g(β);
bbj β = f(β);
bbj β = β.b(β.b * β, β.c * β, β.d * β);
return this.l.a(β, β, false, false, true);
}
public boolean ap()
{
return false;
}
public boolean aq()
{
return false;
}
public void b(rr β, int β) {}
public boolean h(double β, double β, double β)
{
double β = this.p - β;
double β = this.q - β;
double β = this.r - β;
double β = β * β + β * β + β * β;
return a(β);
}
public boolean a(double β)
{
double β = bl().a();
if (Double.isNaN(β)) {
β = 1.0D;
}
β *= 64.0D * c;
return β < β * β;
}
public boolean c(dn β)
{
String β = as();
if ((this.F) || (β == null)) {
return false;
}
β.a("id", β);
e(β);
return true;
}
public boolean d(dn β)
{
String β = as();
if ((this.F) || (β == null) || (aI())) {
return false;
}
β.a("id", β);
e(β);
return true;
}
public void e(dn β)
{
try
{
β.a("Pos", a(new double[] { this.p, this.q, this.r }));
β.a("Motion", a(new double[] { this.s, this.t, this.u }));
β.a("Rotation", a(new float[] { this.v, this.w }));
β.a("FallDistance", this.L);
β.a("Fire", (short)this.aw);
β.a("Air", (short)aP());
β.a("OnGround", this.z);
β.a("Dimension", this.am);
β.a("Invulnerable", this.aC);
β.a("PortalCooldown", this.aj);
β.a("UUID", bc());
if ((bf() != null) && (!bf().isEmpty())) {
β.a("CustomName", bf());
}
if (bg()) {
β.a("CustomNameVisible", bg());
}
this.aD.b(β);
if (ad()) {
β.a("Silent", ad());
}
if (this.ar) {
β.a("Glowing", this.ar);
}
if (this.aF.size() > 0)
{
du β = new du();
for (String β : this.aF) {
β.a(new ea(β));
}
β.a("Tags", β);
}
b(β);
if (aJ())
{
du β = new du();
for (rr β : bu())
{
dn β = new dn();
if (β.c(β)) {
β.a(β);
}
}
if (!β.c_()) {
β.a("Passengers", β);
}
}
}
catch (Throwable β)
{
b β = b.a(β, "Saving entity NBT");
c β = β.a("Entity being saved");
a(β);
throw new e(β);
}
}
public void f(dn β)
{
try
{
du β = β.c("Pos", 6);
du β = β.c("Motion", 6);
du β = β.c("Rotation", 5);
this.s = β.e(0);
this.t = β.e(1);
this.u = β.e(2);
if (Math.abs(this.s) > 10.0D) {
this.s = 0.0D;
}
if (Math.abs(this.t) > 10.0D) {
this.t = 0.0D;
}
if (Math.abs(this.u) > 10.0D) {
this.u = 0.0D;
}
this.m = (this.M = this.p = β.e(0));
this.n = (this.N = this.q = β.e(1));
this.o = (this.O = this.r = β.e(2));
this.x = (this.v = β.f(0));
this.y = (this.w = β.f(1));
h(this.v);
i(this.v);
this.L = β.j("FallDistance");
this.aw = β.g("Fire");
j(β.g("Air"));
this.z = β.p("OnGround");
if (β.e("Dimension")) {
this.am = β.h("Dimension");
}
this.aC = β.p("Invulnerable");
this.aj = β.h("PortalCooldown");
if (β.b("UUID")) {
this.aq = β.a("UUID");
}
b(this.p, this.q, this.r);
b(this.v, this.w);
if (β.b("CustomName", 8)) {
c(β.l("CustomName"));
}
i(β.p("CustomNameVisible"));
this.aD.a(β);
c(β.p("Silent"));
f(β.p("Glowing"));
if (β.b("Tags", 9))
{
this.aF.clear();
du β = β.c("Tags", 8);
int β = Math.min(β.c(), 1024);
for (int β = 0; β < β; β++) {
this.aF.add(β.g(β));
}
}
a(β);
if (ar()) {
b(this.p, this.q, this.r);
}
}
catch (Throwable β)
{
b β = b.a(β, "Loading entity NBT");
c β = β.a("Entity being loaded");
a(β);
throw new e(β);
}
}
protected boolean ar()
{
return true;
}
protected final String as()
{
return rt.b(this);
}
protected abstract void a(dn paramdn);
protected abstract void b(dn paramdn);
public void at() {}
protected du a(double... β)
{
du β = new du();
for (double β : β) {
β.a(new dp(β));
}
return β;
}
protected du a(float... β)
{
du β = new du();
for (float β : β) {
β.a(new dr(β));
}
return β;
}
public yd a(ado β, int β)
{
return a(β, β, 0.0F);
}
public yd a(ado β, int β, float β)
{
return a(new adq(β, β, 0), β);
}
public yd a(adq β, float β)
{
if ((β.b == 0) || (β.b() == null)) {
return null;
}
yd β = new yd(this.l, this.p, this.q + β, this.r, β);
β.q();
this.l.a(β);
return β;
}
public boolean au()
{
return !this.F;
}
public boolean av()
{
if (this.Q) {
return false;
}
cj.b β = cj.b.s();
for (int β = 0; β < 8; β++)
{
int β = on.c(this.q + ((β >> 0) % 2 - 0.5F) * 0.1F + bn());
int β = on.c(this.p + ((β >> 1) % 2 - 0.5F) * this.G * 0.8F);
int β = on.c(this.r + ((β >> 2) % 2 - 0.5F) * this.G * 0.8F);
if ((β.p() != β) || (β.q() != β) || (β.r() != β))
{
β.d(β, β, β);
if (this.l.o(β).t().j())
{
β.t();
return true;
}
}
}
β.t();
return false;
}
public boolean a(zj β, adq β, qm β)
{
return false;
}
public bbh j(rr β)
{
return null;
}
public void aw()
{
rr β = by();
if ((aI()) && (β.F))
{
p();
return;
}
this.s = 0.0D;
this.t = 0.0D;
this.u = 0.0D;
m();
if (!aI()) {
return;
}
β.k(this);
}
public void k(rr β)
{
if (!w(β)) {
return;
}
β.b(this.p, this.q + ay() + β.ax(), this.r);
}
public void l(rr β) {}
public double ax()
{
return 0.0D;
}
public double ay()
{
return this.H * 0.75D;
}
public boolean m(rr β)
{
return a(β, false);
}
public boolean a(rr β, boolean β)
{
if ((!β) && ((!n(β)) || (!β.q(this)))) {
return false;
}
if (aI()) {
p();
}
this.as = β;
this.as.o(this);
return true;
}
protected boolean n(rr β)
{
return this.j <= 0;
}
public void az()
{
for (int β = this.h.size() - 1; β >= 0; β--) {
((rr)this.h.get(β)).p();
}
}
public void p()
{
if (this.as != null)
{
rr β = this.as;
this.as = null;
β.p(this);
}
}
protected void o(rr β)
{
if (β.by() != this) {
throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
}
if ((!this.l.E) && ((β instanceof zj)) && (!(bt() instanceof zj))) {
this.h.add(0, β);
} else {
this.h.add(β);
}
}
protected void p(rr β)
{
if (β.by() == this) {
throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(x)");
}
this.h.remove(β);
β.j = 60;
}
protected boolean q(rr β)
{
return bu().size() < 1;
}
public void a(double β, double β, double β, float β, float β, int β, boolean β)
{
b(β, β, β);
b(β, β);
}
public float aA()
{
return 0.0F;
}
public bbj aB()
{
return null;
}
public void e(cj β)
{
if (this.aj > 0)
{
this.aj = aC();
return;
}
if ((!this.l.E) && (!β.equals(this.an)))
{
this.an = new cj(β);
arg.b β = aju.aY.c(this.l, this.an);
double β = β.b().k() == cq.a.a ? β.a().r() : β.a().p();
double β = β.b().k() == cq.a.a ? this.r : this.p;
β = Math.abs(on.c(β - (β.b().e().c() == cq.b.b ? 1 : 0), β, β - β.d()));
double β = on.c(this.q - 1.0D, β.a().q(), β.a().q() - β.e());
this.ao = new bbj(β, β, 0.0D);
this.ap = β.b();
}
this.ak = true;
}
public int aC()
{
return 300;
}
public void i(double β, double β, double β)
{
this.s = β;
this.t = β;
this.u = β;
}
public void a(byte β) {}
public void aD() {}
public Iterable<adq> aE()
{
return this.aE;
}
public Iterable<adq> aF()
{
return this.aE;
}
public Iterable<adq> aG()
{
return Iterables.concat(aE(), aF());
}
public void a(rw β, adq β) {}
public boolean aH()
{
boolean β = (this.l != null) && (this.l.E);
return (!this.Y) && ((this.aw > 0) || ((β) && (i(0))));
}
public boolean aI()
{
return by() != null;
}
public boolean aJ()
{
return !bu().isEmpty();
}
public boolean aK()
{
return i(1);
}
public void d(boolean β)
{
b(1, β);
}
public boolean aL()
{
return i(3);
}
public void e(boolean β)
{
b(3, β);
}
public boolean aM()
{
return (this.ar) || ((this.l.E) && (i(6)));
}
public void f(boolean β)
{
this.ar = β;
if (!this.l.E) {
b(6, this.ar);
}
}
public boolean aN()
{
return i(5);
}
public boolean e(zj β)
{
if (β.y()) {
return false;
}
bbr β = aO();
if ((β != null) && (β != null) && (β.aO() == β) && (β.h())) {
return false;
}
return aN();
}
public bbr aO()
{
return this.l.ad().g(bc().toString());
}
public boolean r(rr β)
{
return a(β.aO());
}
public boolean a(bbr β)
{
if (aO() != null) {
return aO().a(β);
}
return false;
}
public void g(boolean β)
{
b(5, β);
}
protected boolean i(int β)
{
return (((Byte)this.Z.a(ax)).byteValue() & 1 << β) != 0;
}
protected void b(int β, boolean β)
{
byte β = ((Byte)this.Z.a(ax)).byteValue();
if (β) {
this.Z.b(ax, Byte.valueOf((byte)(β | 1 << β)));
} else {
this.Z.b(ax, Byte.valueOf((byte)(β & (1 << β ^ 0xFFFFFFFF))));
}
}
public int aP()
{
return ((Integer)this.Z.a(ay)).intValue();
}
public void j(int β)
{
this.Z.b(ay, Integer.valueOf(β));
}
public void a(ya β)
{
a(rc.b, 5.0F);
this.aw += 1;
if (this.aw == 0) {
g(8);
}
}
public void b(sa β) {}
protected boolean j(double β, double β, double β)
{
cj β = new cj(β, β, β);
double β = β - β.p();
double β = β - β.q();
double β = β - β.r();
List<bbh> β = this.l.a(bl());
if (β.isEmpty()) {
return false;
}
cq β = cq.b;
double β = Double.MAX_VALUE;
if ((!this.l.t(β.e())) && (β < β))
{
β = β;
β = cq.e;
}
if ((!this.l.t(β.f())) && (1.0D - β < β))
{
β = 1.0D - β;
β = cq.f;
}
if ((!this.l.t(β.c())) && (β < β))
{
β = β;
β = cq.c;
}
if ((!this.l.t(β.d())) && (1.0D - β < β))
{
β = 1.0D - β;
β = cq.d;
}
if ((!this.l.t(β.a())) && (1.0D - β < β))
{
β = 1.0D - β;
β = cq.b;
}
float β = this.S.nextFloat() * 0.2F + 0.1F;
float β = β.c().a();
if (β.k() == cq.a.a) {
this.s += β * β;
} else if (β.k() == cq.a.b) {
this.t += β * β;
} else if (β.k() == cq.a.c) {
this.u += β * β;
}
return true;
}
public void aQ()
{
this.E = true;
this.L = 0.0F;
}
public String h_()
{
if (o_()) {
return bf();
}
String β = rt.b(this);
if (β == null) {
β = "generic";
}
return di.a("entity." + β + ".name");
}
public rr[] aR()
{
return null;
}
public boolean s(rr β)
{
return this == β;
}
public float aS()
{
return 0.0F;
}
public void h(float β) {}
public void i(float β) {}
public boolean aT()
{
return true;
}
public boolean t(rr β)
{
return false;
}
public String toString()
{
return String.format("%s['%s'/%d, l='%s', x=%.2f, y=%.2f, z=%.2f]", new Object[] { getClass().getSimpleName(), h_(), Integer.valueOf(this.g), this.l == null ? "~NULL~" : this.l.T().j(), Double.valueOf(this.p), Double.valueOf(this.q), Double.valueOf(this.r) });
}
public boolean b(rc β)
{
return (this.aC) && (β != rc.k) && (!β.u());
}
public void h(boolean β)
{
this.aC = β;
}
public void u(rr β)
{
b(β.p, β.q, β.r, β.v, β.w);
}
private void a(rr β)
{
dn β = new dn();
β.e(β);
β.q("Dimension");
f(β);
this.aj = β.aj;
this.an = β.an;
this.ao = β.ao;
this.ap = β.ap;
}
public rr c(int β)
{
if ((this.l.E) || (this.F)) {
return null;
}
this.l.C.a("changeDimension");
MinecraftServer β = h();
int β = this.am;
lp β = β.a(β);
lp β = β.a(β);
this.am = β;
if ((β == 1) && (β == 1))
{
β = β.a(0);
this.am = 0;
}
this.l.e(this);
this.F = false;
this.l.C.a("reposition");
cj β;
cj β;
if (β == 1)
{
β = β.p();
}
else
{
double β = this.p;
double β = this.r;
double β = 8.0D;
if (β == -1)
{
β = on.a(β / β, β.aj().b() + 16.0D, β.aj().d() - 16.0D);
β = on.a(β / β, β.aj().c() + 16.0D, β.aj().e() - 16.0D);
}
else if (β == 0)
{
β = on.a(β * β, β.aj().b() + 16.0D, β.aj().d() - 16.0D);
β = on.a(β * β, β.aj().c() + 16.0D, β.aj().e() - 16.0D);
}
β = on.a((int)β, -29999872, 29999872);
β = on.a((int)β, -29999872, 29999872);
float β = this.v;
b(β, this.q, β, 90.0F, 0.0F);
aib β = β.x();
β.b(this, β);
β = new cj(this);
}
β.a(this, false);
this.l.C.c("reloading");
rr β = rt.a(rt.b(this), β);
if (β != null)
{
β.a(this);
if ((β == 1) && (β == 1))
{
cj β = β.q(β.R());
β.a(β, β.v, β.w);
}
else
{
β.a(β, β.v, β.w);
}
boolean β = β.k;
β.k = true;
β.a(β);
β.k = β;
β.a(β, false);
}
this.F = true;
this.l.C.b();
β.m();
β.m();
this.l.C.b();
return β;
}
public boolean aV()
{
return true;
}
public float a(ahp β, aht β, cj β, arc β)
{
return β.t().a(this);
}
public boolean a(ahp β, aht β, cj β, arc β, float β)
{
return true;
}
public int aW()
{
return 3;
}
public bbj aY()
{
return this.ao;
}
public cq aZ()
{
return this.ap;
}
public boolean ba()
{
return false;
}
public void a(c β)
{
β.a("Entity Type", new Callable()
{
public String a()
throws Exception
{
return rt.b(rr.this) + " (" + rr.this.getClass().getCanonicalName() + ")";
}
});
β.a("Entity ID", Integer.valueOf(this.g));
β.a("Entity Name", new Callable()
{
public String a()
throws Exception
{
return rr.this.h_();
}
});
β.a("Entity's Exact location", String.format("%.2f, %.2f, %.2f", new Object[] { Double.valueOf(this.p), Double.valueOf(this.q), Double.valueOf(this.r) }));
β.a("Entity's Block location", c.a(on.c(this.p), on.c(this.q), on.c(this.r)));
β.a("Entity's Momentum", String.format("%.2f, %.2f, %.2f", new Object[] { Double.valueOf(this.s), Double.valueOf(this.t), Double.valueOf(this.u) }));
β.a("Entity's Passengers", new Callable()
{
public String a()
throws Exception
{
return rr.this.bu().toString();
}
});
β.a("Entity's Vehicle", new Callable()
{
public String a()
throws Exception
{
return rr.this.by().toString();
}
});
}
public boolean bb()
{
return aH();
}
public void a(UUID β)
{
this.aq = β;
}
public UUID bc()
{
return this.aq;
}
public boolean bd()
{
return true;
}
public static double be()
{
return c;
}
public static void b(double β)
{
c = β;
}
public eu i_()
{
fa β = new fa(bbm.a(aO(), h_()));
β.b().a(bk());
β.b().a(bc().toString());
return β;
}
public void c(String β)
{
this.Z.b(az, β);
}
public String bf()
{
return (String)this.Z.a(az);
}
public boolean o_()
{
return !((String)this.Z.a(az)).isEmpty();
}
public void i(boolean β)
{
this.Z.b(aA, Boolean.valueOf(β));
}
public boolean bg()
{
return ((Boolean)this.Z.a(aA)).booleanValue();
}
public void a(double β, double β, double β)
{
this.aG = true;
b(β, β, β, this.v, this.w);
this.l.a(this, false);
}
public boolean bh()
{
return bg();
}
public void a(ke<?> β) {}
public cq bi()
{
return cq.b(on.c(this.v * 4.0F / 360.0F + 0.5D) & 0x3);
}
public cq bj()
{
return bi();
}
protected ew bk()
{
dn β = new dn();
String β = rt.b(this);
β.a("id", bc().toString());
if (β != null) {
β.a("type", β);
}
β.a("name", h_());
return new ew(ew.a.d, new fa(β.toString()));
}
public boolean a(lr β)
{
return true;
}
public bbh bl()
{
return this.at;
}
public bbh bm()
{
return bl();
}
public void a(bbh β)
{
this.at = β;
}
public float bn()
{
return this.H * 0.85F;
}
public boolean bo()
{
return this.au;
}
public void j(boolean β)
{
this.au = β;
}
public boolean c(int β, adq β)
{
return false;
}
public void a(eu β) {}
public boolean a(int β, String β)
{
return true;
}
public cj c()
{
return new cj(this.p, this.q + 0.5D, this.r);
}
public bbj d()
{
return new bbj(this.p, this.q, this.r);
}
public aht e()
{
return this.l;
}
public rr f()
{
return this;
}
public boolean z_()
{
return false;
}
public void a(n.a β, int β)
{
if ((this.l != null) && (!this.l.E)) {
this.aD.a(this.l.u(), this, β, β);
}
}
public MinecraftServer h()
{
return this.l.u();
}
public n bp()
{
return this.aD;
}
public void v(rr β)
{
this.aD.a(β.bp());
}
public qo a(zj β, bbj β, adq β, qm β)
{
return qo.b;
}
public boolean bq()
{
return false;
}
protected void a(sa β, rr β)
{
if ((β instanceof sa)) {
ago.a((sa)β, β);
}
ago.b(β, β);
}
public void b(lr β) {}
public void c(lr β) {}
public float a(aoe β)
{
float β = on.g(this.v);
switch (rr.5.a[β.ordinal()])
{
case 1:
return β + 180.0F;
case 2:
return β + 270.0F;
case 3:
return β + 90.0F;
}
return β;
}
public float a(amr β)
{
float β = on.g(this.v);
switch (rr.5.b[β.ordinal()])
{
case 1:
return -β;
case 2:
return 180.0F - β;
}
return β;
}
public boolean br()
{
return false;
}
public boolean bs()
{
boolean β = this.aG;
this.aG = false;
return β;
}
public rr bt()
{
return null;
}
public List<rr> bu()
{
if (this.h.isEmpty()) {
return Collections.emptyList();
}
return Lists.newArrayList(this.h);
}
public boolean w(rr β)
{
for (rr β : bu()) {
if (β.equals(β)) {
return true;
}
}
return false;
}
public Collection<rr> bv()
{
Set<rr> β = Sets.newHashSet();
a(rr.class, β);
return β;
}
public <T extends rr> Collection<T> b(Class<T> β)
{
Set<T> β = Sets.newHashSet();
a(β, β);
return β;
}
private <T extends rr> void a(Class<T> β, Set<T> β)
{
for (rr β : bu())
{
if (β.isAssignableFrom(β.getClass())) {
β.add(β);
}
β.a(β, β);
}
}
public rr bw()
{
rr β = this;
while (β.aI()) {
β = β.by();
}
return β;
}
public boolean x(rr β)
{
return bw() == β.bw();
}
public boolean y(rr β)
{
for (rr β : bu())
{
if (β.equals(β)) {
return true;
}
if (β.y(β)) {
return true;
}
}
return false;
}
public boolean bx()
{
rr β = bt();
if ((β instanceof zj)) {
return ((zj)β).cJ();
}
return !this.l.E;
}
public rr by()
{
return this.as;
}
public axh z()
{
return axh.a;
}
public nh bz()
{
return nh.g;
}
}
| MCLabyMod/LabyMod-1.9 | rr.java |
1,004 | /* h - Decompiled by JODE
* Visit http://jode.sourceforge.net/
*/
public class h extends Class387 implements Interface25 {
long nativeid;
ja aJa6674;
ba aBa6675;
Class68[] aClass68Array6676;
Class85[] aClass85Array6677;
public native int dp();
h(ja var_ja) {
((h) this).aJa6674 = var_ja;
((h) this).aBa6675 = null;
ba(var_ja);
}
void method4757() {
if (((ja) ((h) this).aJa6674).anInt6692 > 1) {
synchronized (this) {
while (aBoolean4148) {
try {
this.wait();
} catch (InterruptedException interruptedexception) {
/* empty */
}
}
aBoolean4148 = true;
}
}
}
native void ba(ja var_ja);
public native void ma(boolean bool);
public void method4786(Class222 class222) {
method4852(ja.anIntArray6681, class222);
int i = 0;
if (((h) this).aClass85Array6677 != null) {
for (int i_0_ = 0; i_0_ < ((h) this).aClass85Array6677.length; i_0_++) {
Class85 class85 = ((h) this).aClass85Array6677[i_0_];
class85.anInt777 = ja.anIntArray6681[i++] * -1879868075;
class85.anInt783 = ja.anIntArray6681[i++] * -2041556771;
class85.anInt779 = ja.anIntArray6681[i++] * -1434499227;
class85.anInt772 = ja.anIntArray6681[i++] * 1070341177;
class85.anInt781 = ja.anIntArray6681[i++] * 1802851857;
class85.anInt782 = ja.anIntArray6681[i++] * 103846281;
class85.anInt771 = ja.anIntArray6681[i++] * -2103324039;
class85.anInt784 = ja.anIntArray6681[i++] * -526039059;
class85.anInt785 = ja.anIntArray6681[i++] * 491030489;
}
}
if (((h) this).aClass68Array6676 != null) {
for (int i_1_ = 0; i_1_ < ((h) this).aClass68Array6676.length; i_1_++) {
Class68 class68 = ((h) this).aClass68Array6676[i_1_];
Class68 class68_2_ = class68;
if (class68.aClass68_672 != null)
class68_2_ = class68.aClass68_672;
if (class68.aClass233_677 == null)
class68.aClass233_677 = new Class233();
class68.aClass233_677.method2145(class222);
class68_2_.anInt671 = ja.anIntArray6681[i++] * -1436341053;
class68_2_.anInt675 = ja.anIntArray6681[i++] * 449866009;
class68_2_.anInt676 = ja.anIntArray6681[i++] * 1336328763;
}
}
}
void method4852(int[] is, Class222 class222) {
((h) this).aJa6674.method5571().method280(this, is, class222);
}
public Class387 method4755(byte i, int i_3_, boolean bool) {
return ((h) this).aJa6674.method5571().method276(this, i, i_3_, bool);
}
native void BA(h var_h_4_, h var_h_5_, int i, boolean bool, boolean bool_6_);
public void method4784() {
/* empty */
}
public native int m();
public void method4745(Class387 class387, int i, int i_7_, int i_8_, boolean bool) {
((h) this).aJa6674.method5571().method285(this, class387, i, i_7_, i_8_, bool);
}
public native void f(int i);
public native void S(int i);
public native void t(int i);
public native void EA(int i);
public native void ia(int i, int i_9_, int i_10_);
public native void wa();
public native void by(int i);
public native void pa(int i, int i_11_, Class_xa class_xa, Class_xa class_xa_12_, int i_13_, int i_14_, int i_15_);
public native int ya();
public native int o();
native boolean ea();
final void method4738(int i, int[] is, int i_16_, int i_17_, int i_18_, int i_19_, boolean bool) {
J(((h) this).nativeid, i, is, i_16_, i_17_, i_18_, i_19_, bool);
}
public native void bc(int i);
native void e(int i, int[] is, int i_20_, int i_21_, int i_22_, boolean bool, int i_23_, int[] is_24_);
public native void bs(int i, int i_25_, Class_xa class_xa, Class_xa class_xa_26_, int i_27_, int i_28_, int i_29_);
public native void bl(int i, int i_30_, int i_31_);
public void method4741(Class222 class222, int i, boolean bool) {
Class233 class233 = ((a) ((h) this).aJa6674.method5571()).aClass233_6673;
class233.method2145(class222);
aa(class233.aFloatArray2594, i, bool);
}
native void aa(float[] fs, int i, boolean bool);
native void fq(long l, int i, int[] is, int i_32_, int i_33_, int i_34_, int i_35_, boolean bool);
public boolean method4787(int i, int i_36_, Class222 class222, boolean bool, int i_37_) {
return ((h) this).aJa6674.method5571().method284(this, i, i_36_, class222, bool);
}
public void method4779(Class387 class387, int i, int i_38_, int i_39_, boolean bool) {
((h) this).aJa6674.method5571().method285(this, class387, i, i_38_, i_39_, bool);
}
public native int N();
public native int n();
public native void dc(int i);
public native int cu();
public native int YA();
public native Class_na ct(Class_na class_na);
native void cw(int i, int i_40_, int i_41_, int i_42_);
public native int ha();
public native void p(int i);
public native void Q(int i);
public native int c();
native void ka();
public native byte[] ah();
public native void X(short i, short i_43_);
native void fp(h var_h_44_, h var_h_45_, int i, boolean bool, boolean bool_46_);
native void IA(byte i, byte[] is);
public Class68[] method4774() {
return ((h) this).aClass68Array6676;
}
public native void PA(int i, int i_47_, int i_48_, int i_49_);
public boolean method4743() {
return true;
}
public native void dz(short i, short i_50_);
void method4734() {
if (((ja) ((h) this).aJa6674).anInt6692 > 1) {
synchronized (this) {
aBoolean4148 = false;
this.notifyAll();
}
}
}
public Class85[] method4781() {
return ((h) this).aClass85Array6677;
}
public Class68[] method4728() {
return ((h) this).aClass68Array6676;
}
public native void ey(short i, short i_51_);
public Class85[] method4772() {
return ((h) this).aClass85Array6677;
}
native void U(ja var_ja, ba var_ba, int i, int i_52_, int[] is, int[] is_53_, int[] is_54_, int[] is_55_, short[] is_56_, int i_57_, short[] is_58_, short[] is_59_, short[] is_60_, byte[] is_61_, byte[] is_62_, byte[] is_63_, short[] aByteArray635, short[] is_65_, short[] is_66_, int[] is_67_, byte i_68_, short[] is_69_, int i_70_, byte[] is_71_, short[] is_72_, short[] is_73_, short[] is_74_, int[] is_75_, int[] is_76_, int[] is_77_, byte[] is_78_, byte[] is_79_, int[] is_80_, int[] is_81_, int[] is_82_, int[] is_83_, int i_84_, int i_85_, int i_86_, int i_87_, int i_88_, int i_89_, int[] is_90_);
public Class387 method4748(byte i, int i_91_, boolean bool) {
return ((h) this).aJa6674.method5571().method276(this, i, i_91_, bool);
}
public Class387 method4770(byte i, int i_92_, boolean bool) {
return ((h) this).aJa6674.method5571().method276(this, i, i_92_, bool);
}
public Class387 method4749(byte i, int i_93_, boolean bool) {
return ((h) this).aJa6674.method5571().method276(this, i, i_93_, bool);
}
public native boolean i();
public native int an();
public native void au(int i);
public native void ar(int i);
public native void ac(int i);
public void method4752() {
/* empty */
}
public void method4764() {
/* empty */
}
public native void bf(int i);
public native void be(int i);
native void cl(int i, int[] is, int i_94_, int i_95_, int i_96_, boolean bool, int i_97_, int[] is_98_);
public native void bm(int i);
public native void W(short i, short i_99_);
public native void bx(int i);
public native void bo(int i);
public native void df(short i, short i_100_);
public void method4740(Class222 class222, Class302_Sub1 class302_sub1, int i) {
if (class302_sub1 == null)
((h) this).aJa6674.method5571().method279(this, class222, null, i);
else {
ja.anIntArray6704[5] = 0;
((h) this).aJa6674.method5571().method279(this, class222, ja.anIntArray6704, i);
class302_sub1.anInt7641 = ja.anIntArray6704[0];
class302_sub1.anInt7642 = ja.anIntArray6704[1];
class302_sub1.anInt7643 = ja.anIntArray6704[2];
class302_sub1.anInt7640 = ja.anIntArray6704[3];
class302_sub1.anInt7645 = ja.anIntArray6704[4];
class302_sub1.aBoolean7644 = ja.anIntArray6704[5] != 0;
}
}
public native void bw(int i, int i_101_, int i_102_);
public native void bk(int i, int i_103_, int i_104_);
public native void bq(int i, int i_105_, int i_106_);
public native void bg(int i, int i_107_, Class_xa class_xa, Class_xa class_xa_108_, int i_109_, int i_110_, int i_111_);
public native int RA();
public native void bp(int i, int i_112_, Class_xa class_xa, Class_xa class_xa_113_, int i_114_, int i_115_, int i_116_);
void method4754() {
if (((ja) ((h) this).aJa6674).anInt6692 > 1) {
synchronized (this) {
while (aBoolean4148) {
try {
this.wait();
} catch (InterruptedException interruptedexception) {
/* empty */
}
}
aBoolean4148 = true;
}
}
}
public void method4747(Class387 class387, int i, int i_117_, int i_118_, boolean bool) {
((h) this).aJa6674.method5571().method285(this, class387, i, i_117_, i_118_, bool);
}
public void method4739(Class222 class222, Class302_Sub1 class302_sub1, int i) {
if (class302_sub1 == null)
((h) this).aJa6674.method5571().method279(this, class222, null, i);
else {
ja.anIntArray6704[5] = 0;
((h) this).aJa6674.method5571().method279(this, class222, ja.anIntArray6704, i);
class302_sub1.anInt7641 = ja.anIntArray6704[0];
class302_sub1.anInt7642 = ja.anIntArray6704[1];
class302_sub1.anInt7643 = ja.anIntArray6704[2];
class302_sub1.anInt7640 = ja.anIntArray6704[3];
class302_sub1.anInt7645 = ja.anIntArray6704[4];
class302_sub1.aBoolean7644 = ja.anIntArray6704[5] != 0;
}
}
void method4758() {
if (((ja) ((h) this).aJa6674).anInt6692 > 1) {
synchronized (this) {
aBoolean4148 = false;
this.notifyAll();
}
}
}
native boolean bt();
native boolean bj();
native void br();
native void bz();
native void cm();
native void cd();
final void method4760(int i, int[] is, int i_119_, int i_120_, int i_121_, int i_122_, boolean bool) {
J(((h) this).nativeid, i, is, i_119_, i_120_, i_121_, i_122_, bool);
}
native void fe(ja var_ja);
void method4756() {
if (((ja) ((h) this).aJa6674).anInt6692 > 1) {
synchronized (this) {
while (aBoolean4148) {
try {
this.wait();
} catch (InterruptedException interruptedexception) {
/* empty */
}
}
aBoolean4148 = true;
}
}
}
native void gc(float[] fs, int i, boolean bool);
native void co(int i, int[] is, int i_123_, int i_124_, int i_125_, boolean bool, int i_126_, int[] is_127_);
native void J(long l, int i, int[] is, int i_128_, int i_129_, int i_130_, int i_131_, boolean bool);
native void cv(int i, int i_132_, int i_133_, int i_134_);
public void method4776(Class222 class222, int i, boolean bool) {
Class233 class233 = ((a) ((h) this).aJa6674.method5571()).aClass233_6673;
class233.method2145(class222);
aa(class233.aFloatArray2594, i, bool);
}
public void method4762(Class222 class222, int i, boolean bool) {
Class233 class233 = ((a) ((h) this).aJa6674.method5571()).aClass233_6673;
class233.method2145(class222);
aa(class233.aFloatArray2594, i, bool);
}
public void method4759(Class222 class222, Class302_Sub1 class302_sub1, int i) {
if (class302_sub1 == null)
((h) this).aJa6674.method5571().method279(this, class222, null, i);
else {
ja.anIntArray6704[5] = 0;
((h) this).aJa6674.method5571().method279(this, class222, ja.anIntArray6704, i);
class302_sub1.anInt7641 = ja.anIntArray6704[0];
class302_sub1.anInt7642 = ja.anIntArray6704[1];
class302_sub1.anInt7643 = ja.anIntArray6704[2];
class302_sub1.anInt7640 = ja.anIntArray6704[3];
class302_sub1.anInt7645 = ja.anIntArray6704[4];
class302_sub1.aBoolean7644 = ja.anIntArray6704[5] != 0;
}
}
native void gn(byte i, byte[] is);
h(ja var_ja, ba var_ba, Model class64, int i, int i_135_, int i_136_, int i_137_) {
((h) this).aJa6674 = var_ja;
((h) this).aBa6675 = var_ba;
((h) this).aClass85Array6677 = class64.aClass85Array647;
((h) this).aClass68Array6676 = class64.aClass68Array613;
int i_138_ = (class64.aClass85Array647 == null ? 0 : class64.aClass85Array647.length);
int i_139_ = (class64.aClass68Array613 == null ? 0 : class64.aClass68Array613.length);
int i_140_ = 0;
int[] is = new int[i_138_ * 3 + i_139_];
for (int i_141_ = 0; i_141_ < i_138_; i_141_++) {
is[i_140_++] = ((h) this).aClass85Array6677[i_141_].anInt773 * -710317103;
is[i_140_++] = ((h) this).aClass85Array6677[i_141_].anInt774 * 1705862021;
is[i_140_++] = ((h) this).aClass85Array6677[i_141_].anInt775 * 1636170731;
}
for (int i_142_ = 0; i_142_ < i_139_; i_142_++)
is[i_140_++] = ((h) this).aClass68Array6676[i_142_].anInt674 * -180596249;
int i_143_ = (class64.aClass84Array649 == null ? 0 : class64.aClass84Array649.length);
int[] is_144_ = new int[i_143_ * 8];
int i_145_ = 0;
for (int i_146_ = 0; i_146_ < i_143_; i_146_++) {
Class84 class84 = class64.aClass84Array649[i_146_];
Class173 class173 = Class298.method2844(class84.anInt768 * 1834782277, -67897652);
is_144_[i_145_++] = class84.anInt767 * 1512514121;
is_144_[i_145_++] = class173.anInt1755 * 1951943953;
is_144_[i_145_++] = class173.anInt1753 * 893949695;
is_144_[i_145_++] = class173.anInt1751 * 39181267;
is_144_[i_145_++] = class173.anInt1752 * -310074719;
is_144_[i_145_++] = class173.anInt1754 * 1092922159;
is_144_[i_145_++] = class173.aBoolean1757 ? -1 : 0;
}
for (int i_147_ = 0; i_147_ < i_143_; i_147_++) {
Class84 class84 = class64.aClass84Array649[i_147_];
is_144_[i_145_++] = class84.anInt766 * -1606786303;
}
U(((h) this).aJa6674, ((h) this).aBa6675, class64.anInt614, class64.anInt626, class64.anIntArray616, class64.anIntArray642, class64.anIntArray618, class64.anIntArray619, class64.aShortArray620, class64.anInt621, class64.aShortArray644, class64.aShortArray646, class64.aShortArray624, class64.aByteArray625, class64.aByteArray633, class64.aByteArray627, class64.aByteArray635, class64.aShortArray629, class64.aShortArray617, class64.anIntArray631, class64.aByte632, class64.aShortArray615, class64.anInt634, class64.aByteArray622, class64.aShortArray623, class64.aShortArray636, class64.aShortArray638, class64.anIntArray639, class64.anIntArray640, class64.anIntArray641, class64.aByteArray645, class64.aByteArray628, class64.anIntArray637, class64.anIntArray643, class64.anIntArray648, is, i_138_, i_139_, i, i_135_, i_136_, i_137_, is_144_);
}
public boolean method4746(int i, int i_148_, Class222 class222, boolean bool, int i_149_) {
return ((h) this).aJa6674.method5571().method284(this, i, i_148_, class222, bool);
}
public boolean method4778() {
return true;
}
public native void KA(int i);
public native int ca();
public native int ci();
public native int ce();
public native int cq();
public native int cr();
native void w(int i, int i_150_, int i_151_, int i_152_);
public native int cp();
public native void bb(int i);
public native int cf();
public native int dh();
final void method4761(int i, int[] is, int i_153_, int i_154_, int i_155_, int i_156_, boolean bool) {
J(((h) this).nativeid, i, is, i_153_, i_154_, i_155_, i_156_, bool);
}
native void fk(ja var_ja);
public Class85[] method4771() {
return ((h) this).aClass85Array6677;
}
public native int ds();
public native Class_na cc(Class_na class_na);
public native void dd(int i);
public native void dx(int i);
native void fx(long l, int i, int[] is, int i_157_, int i_158_, int i_159_, int i_160_, boolean bool);
public native int dk();
public native int db();
public native int dn();
public native void oa(int i, int i_161_, int i_162_);
public void method4768(byte i, byte[] is) {
IA(i, is);
}
public void method4769(byte i, byte[] is) {
IA(i, is);
}
public native void du(short i, short i_163_);
public boolean method4788() {
return true;
}
public native void di(short i, short i_164_);
public void method4742(byte i, byte[] is) {
IA(i, is);
}
public Class68[] method4753() {
return ((h) this).aClass68Array6676;
}
public native void dt(int i, int i_165_, int i_166_, int i_167_);
public native Class_na ga(Class_na class_na);
void method4733() {
if (((ja) ((h) this).aJa6674).anInt6692 > 1) {
synchronized (this) {
while (aBoolean4148) {
try {
this.wait();
} catch (InterruptedException interruptedexception) {
/* empty */
}
}
aBoolean4148 = true;
}
}
}
public native void dv(short i, short i_168_);
public native int AA();
public Class68[] method4773() {
return ((h) this).aClass68Array6676;
}
public native byte[] method_do();
public native void dj(int i, int i_169_, int i_170_, int i_171_);
public native int dl();
public native void bu(int i, int i_172_, int i_173_);
public boolean method4777() {
return true;
}
public Class68[] method4775() {
return ((h) this).aClass68Array6676;
}
public native boolean ev();
public native boolean eg();
public native boolean ex();
public native boolean ek();
public native int cb();
public native void em();
public native int ec();
public native void eb(short i, short i_174_);
public native int dq();
public void method4751(Class222 class222) {
method4852(ja.anIntArray6681, class222);
int i = 0;
if (((h) this).aClass85Array6677 != null) {
for (int i_175_ = 0; i_175_ < ((h) this).aClass85Array6677.length; i_175_++) {
Class85 class85 = ((h) this).aClass85Array6677[i_175_];
class85.anInt777 = ja.anIntArray6681[i++] * -1879868075;
class85.anInt783 = ja.anIntArray6681[i++] * -2041556771;
class85.anInt779 = ja.anIntArray6681[i++] * -1434499227;
class85.anInt772 = ja.anIntArray6681[i++] * 1070341177;
class85.anInt781 = ja.anIntArray6681[i++] * 1802851857;
class85.anInt782 = ja.anIntArray6681[i++] * 103846281;
class85.anInt771 = ja.anIntArray6681[i++] * -2103324039;
class85.anInt784 = ja.anIntArray6681[i++] * -526039059;
class85.anInt785 = ja.anIntArray6681[i++] * 491030489;
}
}
if (((h) this).aClass68Array6676 != null) {
for (int i_176_ = 0; i_176_ < ((h) this).aClass68Array6676.length; i_176_++) {
Class68 class68 = ((h) this).aClass68Array6676[i_176_];
Class68 class68_177_ = class68;
if (class68.aClass68_672 != null)
class68_177_ = class68.aClass68_672;
if (class68.aClass233_677 == null)
class68.aClass233_677 = new Class233();
class68.aClass233_677.method2145(class222);
class68_177_.anInt671 = ja.anIntArray6681[i++] * -1436341053;
class68_177_.anInt675 = ja.anIntArray6681[i++] * 449866009;
class68_177_.anInt676 = ja.anIntArray6681[i++] * 1336328763;
}
}
}
public void method4782(Class222 class222) {
method4852(ja.anIntArray6681, class222);
int i = 0;
if (((h) this).aClass85Array6677 != null) {
for (int i_178_ = 0; i_178_ < ((h) this).aClass85Array6677.length; i_178_++) {
Class85 class85 = ((h) this).aClass85Array6677[i_178_];
class85.anInt777 = ja.anIntArray6681[i++] * -1879868075;
class85.anInt783 = ja.anIntArray6681[i++] * -2041556771;
class85.anInt779 = ja.anIntArray6681[i++] * -1434499227;
class85.anInt772 = ja.anIntArray6681[i++] * 1070341177;
class85.anInt781 = ja.anIntArray6681[i++] * 1802851857;
class85.anInt782 = ja.anIntArray6681[i++] * 103846281;
class85.anInt771 = ja.anIntArray6681[i++] * -2103324039;
class85.anInt784 = ja.anIntArray6681[i++] * -526039059;
class85.anInt785 = ja.anIntArray6681[i++] * 491030489;
}
}
if (((h) this).aClass68Array6676 != null) {
for (int i_179_ = 0; i_179_ < ((h) this).aClass68Array6676.length; i_179_++) {
Class68 class68 = ((h) this).aClass68Array6676[i_179_];
Class68 class68_180_ = class68;
if (class68.aClass68_672 != null)
class68_180_ = class68.aClass68_672;
if (class68.aClass233_677 == null)
class68.aClass233_677 = new Class233();
class68.aClass233_677.method2145(class222);
class68_180_.anInt671 = ja.anIntArray6681[i++] * -1436341053;
class68_180_.anInt675 = ja.anIntArray6681[i++] * 449866009;
class68_180_.anInt676 = ja.anIntArray6681[i++] * 1336328763;
}
}
}
public void method4783(Class222 class222) {
method4852(ja.anIntArray6681, class222);
int i = 0;
if (((h) this).aClass85Array6677 != null) {
for (int i_181_ = 0; i_181_ < ((h) this).aClass85Array6677.length; i_181_++) {
Class85 class85 = ((h) this).aClass85Array6677[i_181_];
class85.anInt777 = ja.anIntArray6681[i++] * -1879868075;
class85.anInt783 = ja.anIntArray6681[i++] * -2041556771;
class85.anInt779 = ja.anIntArray6681[i++] * -1434499227;
class85.anInt772 = ja.anIntArray6681[i++] * 1070341177;
class85.anInt781 = ja.anIntArray6681[i++] * 1802851857;
class85.anInt782 = ja.anIntArray6681[i++] * 103846281;
class85.anInt771 = ja.anIntArray6681[i++] * -2103324039;
class85.anInt784 = ja.anIntArray6681[i++] * -526039059;
class85.anInt785 = ja.anIntArray6681[i++] * 491030489;
}
}
if (((h) this).aClass68Array6676 != null) {
for (int i_182_ = 0; i_182_ < ((h) this).aClass68Array6676.length; i_182_++) {
Class68 class68 = ((h) this).aClass68Array6676[i_182_];
Class68 class68_183_ = class68;
if (class68.aClass68_672 != null)
class68_183_ = class68.aClass68_672;
if (class68.aClass233_677 == null)
class68.aClass233_677 = new Class233();
class68.aClass233_677.method2145(class222);
class68_183_.anInt671 = ja.anIntArray6681[i++] * -1436341053;
class68_183_.anInt675 = ja.anIntArray6681[i++] * 449866009;
class68_183_.anInt676 = ja.anIntArray6681[i++] * 1336328763;
}
}
}
native void cj(int i, int[] is, int i_184_, int i_185_, int i_186_, boolean bool, int i_187_, int[] is_188_);
native void fc(ja var_ja, ba var_ba, int i, int i_189_, int[] is, int[] is_190_, int[] is_191_, int[] is_192_, short[] is_193_, int i_194_, short[] is_195_, short[] is_196_, short[] is_197_, byte[] is_198_, byte[] is_199_, byte[] is_200_, byte[] is_201_, short[] is_202_, short[] is_203_, int[] is_204_, byte i_205_, short[] is_206_, int i_207_, byte[] is_208_, short[] is_209_, short[] is_210_, short[] is_211_, int[] is_212_, int[] is_213_, int[] is_214_, byte[] is_215_, byte[] is_216_, int[] is_217_, int[] is_218_, int[] is_219_, int[] is_220_, int i_221_, int i_222_, int i_223_, int i_224_, int i_225_, int i_226_, int[] is_227_);
native void fw(ja var_ja);
public native void z(boolean bool);
public native boolean u();
public native void dr(int i, int i_228_, int i_229_, int i_230_);
public native int Z();
public boolean method4763(int i, int i_231_, Class222 class222, boolean bool, int i_232_) {
return ((h) this).aJa6674.method5571().method284(this, i, i_231_, class222, bool);
}
native void gt(float[] fs, int i, boolean bool);
public native int dg();
native void gl(float[] fs, int i, boolean bool);
native void gq(float[] fs, int i, boolean bool);
native void gp(byte i, byte[] is);
public Class387 method4750(byte i, int i_233_, boolean bool) {
return ((h) this).aJa6674.method5571().method276(this, i, i_233_, bool);
}
native void ge(byte i, byte[] is);
}
| Rune-Status/dginovker-RS-2009 | Tools/!Some Options Do NOT Work! FrostyCacheEditor/h.java |
1,005 | package frc.robot;
import edu.wpi.first.wpilibj.GenericHID.RumbleType;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.buttons.JoystickButton;
public class OI
{
//constants
//Main xbox controller
public static final int LEFT_X =0;
public static final int LEFT_Y =1;
public static final int LEFT_TRIGGER =2;
public static final int RIGHT_TRIGGER =3;
public static final int RIGHT_X = 4;
public static final int RIGHT_Y =5;
public static final int A_NUM =1;
public static final int B_NUM =2;
public static final int X_NUM =3;
public static final int Y_NUM =4;
public static final int BACK = 7;
public static final int START =8;
public static final int LEFT_JOYSTICK = 9;
public static final int RIGHT_JOYSTICK =10;
public static final int LB_NUM = 5;
public static final int RB_NUM =6;
//Manipulator Button Case
public static final int M_1 = 1;
public static final int M_2 = 2;
public static final int M_3 = 3;
public static final int M_4 = 4;
public static final int M_5 = 11;
public static final int M_6 = 6;
public static final int M_7 = 7;
public static final int M_8 = 8;
public static final int M_9 = 9;
public static final int M_10 = 10;
//Buffalo Secondary Controller
public static final int B_XAXIS = 0;
public static final int B_YAXIS = 1;
public static final int B_A = 0;
public static final int B_B = 1;
public static final int B_X = 2;
public static final int B_Y = 3;
public static final int B_LTRIGGER = 4;
public static final int B_RTRIGGER = 5;
public static final int B_SELECT = 6;
public static final int B_START = 7;
JoystickButton dX, dA, dB, dY, dLB, dRB, dBack, dStart, dLeftJoystick, dRightJoystick, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, bXAxis,
bYAxis, bA, bB, bX, bY, bLTrigger, bRTrigger, bSelect, bStart;
Joystick drive, manipulator, buffalo;
Joystick saitek;
JoystickButton D1, D2, D3, D4, D5, D6, Dback, Dstart, DleftJoystick, DrightJoystick;
public OI()
{
drive = new Joystick(0);
dA = new JoystickButton(drive, A_NUM);
dB = new JoystickButton(drive, B_NUM);
dY = new JoystickButton(drive, Y_NUM);
dX = new JoystickButton(drive, X_NUM);
dLB = new JoystickButton(drive, LB_NUM);
dRB = new JoystickButton(drive, RB_NUM);
dBack = new JoystickButton(drive, BACK);
dStart = new JoystickButton(drive, START);
dLeftJoystick = new JoystickButton(drive, LEFT_JOYSTICK);
dRightJoystick = new JoystickButton(drive, RIGHT_JOYSTICK);
saitek = new Joystick(4);
D1 = new JoystickButton(saitek, A_NUM);
D2 = new JoystickButton(saitek, B_NUM);
D3 = new JoystickButton(saitek, X_NUM);
D4 = new JoystickButton(saitek, Y_NUM); //Does not work
D5 = new JoystickButton(saitek, LB_NUM);
D6 = new JoystickButton(saitek, RB_NUM);
Dback = new JoystickButton(saitek, BACK);
Dstart = new JoystickButton(saitek, START);
DleftJoystick = new JoystickButton(saitek, LEFT_JOYSTICK);
manipulator = new Joystick(1);
m1 = new JoystickButton(manipulator, M_1);
m2 = new JoystickButton(manipulator, M_2);
m3 = new JoystickButton(manipulator, M_3);
m4 = new JoystickButton(manipulator, M_4);
m5 = new JoystickButton(manipulator, M_5);
m6 = new JoystickButton(manipulator, M_6);
m7 = new JoystickButton(manipulator, M_7);
m8 = new JoystickButton(manipulator, M_8);
m9 = new JoystickButton(manipulator, M_9);
m10 = new JoystickButton(manipulator, M_10);
buffalo = new Joystick(2);
bXAxis = new JoystickButton(buffalo, B_XAXIS);
bYAxis = new JoystickButton(buffalo, B_YAXIS);
bA = new JoystickButton(buffalo, B_A);
bB = new JoystickButton(buffalo, B_B);
bX = new JoystickButton(buffalo, B_X);
bY = new JoystickButton(buffalo, B_Y);
bLTrigger = new JoystickButton(buffalo, B_LTRIGGER);
bRTrigger = new JoystickButton(buffalo, B_RTRIGGER);
bSelect = new JoystickButton(buffalo, B_SELECT);
bStart = new JoystickButton(buffalo, B_START);
}
//Return Methods for driving
public double getDriveLeftY()
{
if(Math.abs(drive.getRawAxis(LEFT_Y))< 0.2)
return 0;
return drive.getRawAxis(LEFT_Y);
}
public double getDriveLeftX()
{
if(Math.abs(drive.getRawAxis(LEFT_X))< 0.2)
return 0;
return drive.getRawAxis(LEFT_X);
}
public double getDriveRightX()
{
if(Math.abs(drive.getRawAxis(RIGHT_X))< 0.2)
return 0;
return drive.getRawAxis(RIGHT_X);
}
public double getDriveRightY()
{
if(Math.abs(drive.getRawAxis(RIGHT_Y))< 0.2)
return 0;
return drive.getRawAxis(RIGHT_Y);
}
public double getDriveLeftTrigger()
{
return drive.getRawAxis(LEFT_TRIGGER);
}
public double getDriveRightTrigger()
{
return drive.getRawAxis(RIGHT_TRIGGER);
}
public boolean getA() {
return drive.getRawButton(A_NUM);
}
public boolean getB() {
return drive.getRawButton(B_NUM);
}
public boolean getX() {
return drive.getRawButton(X_NUM);
}
public boolean getY() {
return drive.getRawButton(Y_NUM);
}
public boolean getBoxA() {
return manipulator.getRawButton(M_1);
}
public boolean getBoxB() {
return manipulator.getRawButton(M_2);
}
public boolean getBoxC() {
return manipulator.getRawButton(M_3);
}
public boolean getBoxD() {
return manipulator.getRawButton(M_4);
}
public boolean getBoxE() {
return manipulator.getRawButton(M_5);
}
public boolean getBoxF() {
return manipulator.getRawButton(M_6);
}
public boolean getBoxG() {
return manipulator.getRawButton(M_7);
}
public boolean getBoxH() {
return manipulator.getRawButton(M_8);
}
public boolean getBoxI() {
return manipulator.getRawButton(M_9);
}
public boolean getBoxJ() {
return manipulator.getRawButton(M_10);
}
public boolean getBuffaloA() {
return buffalo.getRawButton(B_A);
}
public boolean getBuffaloB() {
return buffalo.getRawButton(B_B);
}
public boolean getBuffaloX() {
return buffalo.getRawButton(B_X);
}
public boolean getBuffaloY() {
return buffalo.getRawButton(B_Y);
}
public boolean getBuffaloRightTrigger() {
return buffalo.getRawButton(B_RTRIGGER);
}
public boolean getBuffaloLeftTrigger() {
return buffalo.getRawButton(B_LTRIGGER);
}
public boolean getBuffaloUpArrow() {
return buffalo.getRawAxis(B_YAXIS) > .75;
}
public boolean getBuffaloDownArrow() {
return buffalo.getRawAxis(B_YAXIS) < -.75;
}
public boolean getBuffaloRightArrow() {
return buffalo.getRawAxis(B_XAXIS) > .75;
}
public boolean getBuffaloLeftArrow() {
return buffalo.getRawAxis(B_XAXIS) < -.75;
}
public double getSaitekZ()
{
if(Math.abs(saitek.getRawAxis(2))< 0.2)
return 0;
return saitek.getRawAxis(2);
}
public double getSaitekY()
{
if(Math.abs(saitek.getRawAxis(1))< 0.2)
return 0;
return saitek.getRawAxis(1);
}
public double getSaitekX()
{
if(Math.abs(saitek.getRawAxis(0))< 0.2)
return 0;
return saitek.getRawAxis(0);
}
public double getSaitekZRotate()
{
if(Math.abs(saitek.getRawAxis(3))< 0.2)
return 0;
return saitek.getRawAxis(3);
}
}
| FRC-Chain-Reaction-Robotics/2019-2020-NTX | OI.java |
1,006 | /*---
iGeo - http://igeo.jp
Copyright (c) 2002-2013 Satoru Sugihara
This file is part of iGeo.
iGeo is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, version 3.
iGeo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with iGeo. If not, see <http://www.gnu.org/licenses/>.
---*/
package igeo;
import java.awt.*;
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import igeo.gui.*;
import igeo.io.*;
/**
A main interface to background process of iGeo.
A single IG instance can be accessed through static methods although
multiple IG instance also can be contained in the static variable iglist in case
multiple object servers are needed or simultaneous execution of multiple applets.
One IG instance contains one IServer as object database and one IPanel as
display window. The member variable of IPanel can be null when no display
window is needed.
@see IServer
@see IPanel
@author Satoru Sugihara
*/
public class IG implements IServerI{
public static int majorVersion(){ return 0; }
public static int minorVersion(){ return 9; }
public static int buildVersion(){ return 3; }
public static int revisionVersion(){ return 0; }
public static Calendar versionDate(){ return new GregorianCalendar(2019, 8, 14); }
public static String version(){
return String.valueOf(majorVersion())+"."+String.valueOf(minorVersion())+"."+
String.valueOf(buildVersion())+"."+String.valueOf(revisionVersion());
}
/************************************
* static system variables
************************************/
public static final Object lock = new Object();
/** Processing Graphics using OpenGL to be put in size() method in Processing */
public static final String GL1 = "igeo.p.PIGraphicsGL1";
public static final String GL2 = "igeo.p.PIGraphicsGL2";
public static final String GL3 = "igeo.p.PIGraphicsGL3";
//public static final String GL = GL1; // switch before compile for target // for processing 1.5
//public static final String GL = GL2; // switch before compile for target // for processing 2.0
public static final String GL = GL3; // switch before compile for target // for processing 3.0
/** Processing Graphics using P3D to be put in size() method in Processing; under development. do not use yet. */
public static final String P3D = "igeo.p.PIGraphics3D";
/** alias of IG.P3D */
public static final String P3 = P3D;
/** alias of IG.P3D */
public static final String P = P3D;
/** Processing Graphics using JAVA to be put in size() method in Processing; to be implemented */
//public static final String JAVA = "igeo.p.PIGraphicsJava";
/** multiple IG instances are stored in iglist and switched by IG static methods
in case of applet execution or other occasion but handling of multiple IG
instances and switching are not really tested. */
protected static ArrayList<IG> iglist=null;
protected static int currentId = -1;
/************************************
* static geometry variables
************************************/
/** x-axis vector. do not modify the content. */
public static final IVec xaxis = IVec.xaxis;
/** y-axis vector. do not modify the content. */
public static final IVec yaxis = IVec.yaxis;
/** z-axis vector. do not modify the content. */
public static final IVec zaxis = IVec.zaxis;
/** origin vector. do not modify the content. */
public static final IVec origin = IVec.origin;
/** alias of x-axis vector */
public static final IVec x = IVec.xaxis;
/** alias of y-axis vector */
public static final IVec y = IVec.yaxis;
/** alias of z-axis vector */
public static final IVec z = IVec.zaxis;
/** alias of origin vector */
public static final IVec o = IVec.origin;
/************************************
* object variables
************************************/
/*protected*/ public IServer server;
/*protected*/ public IPanelI panel = null;
/*protected*/ public String inputFile;
/*protected*/ public String outputFile;
/** base file path for file I/O */
public String basePath = null; //".";
/** wrapping inputs in different environment. replacing basePath. */
public IInputWrapper inputWrapper=null;
/** if it's applet. online == true */
public boolean online=false;
/* *
initialize whole IG system with IServer and graphical components
instance of IG should be held by IGPane
@param
owner: if owner contains IGPane, the instance of IG is kept by it.
if not, IGPane is instantiated and the instance of IG is kept by it.
if the ownwer is null, IGPane and all other graphical components are not instantiated.
*/
/*
public static IG init(Container owner){
if(iglist==null) iglist = new ArrayList<IG>();
IG ig = null;
if(owner != null){
IGPane p = findIGPane(owner);
if(p==null) p = new IGPane(owner);
ig = new IG(p);
}
else ig = new IG();
iglist.add(ig);
currentId = iglist.size()-1;
return ig;
}
public static IGPane findIGPane(Container container){
final int defaultSearchDepth = 0;
return findIGPane(container, defaultSearchDepth);
}
public static IGPane findIGPane(Container container, int searchDepth){
Component[] components = container.getComponents();
for(Component c : components){
if(c instanceof IGPane) return (IGPane)c;
else if(searchDepth>0 && c instanceof Container){
IGPane p = findIGPane((Container)c, searchDepth-1);
if(p!=null) return p;
}
}
return null;
}
*/
/***********************************************************************
* static methods
***********************************************************************/
/**
Initialize whole IG system in non-graphic mode.
*/
public static IG init(){
if(iglist==null) iglist = new ArrayList<IG>();
IG ig = new IG();
iglist.add(ig);
currentId = iglist.size()-1;
return ig;
}
/** Initialize whole IG system in graphic mode.
Please instantiate IPanel beforehand.
*/
public static IG init(IPanelI owner){
if(iglist==null) iglist = new ArrayList<IG>();
IG ig = new IG(owner);
iglist.add(ig);
currentId = iglist.size()-1;
return ig;
}
/** alias of cur() */
public static IG current(){ return cur(); }
/** Find the IG instance which is likely to be the current. */
public static IG cur(){
if(iglist==null || currentId<0 || currentId>=iglist.size()) return null;
return iglist.get(currentId);
}
/** object to be used to lock in "synchronized" statement */
public static IG defaultThread(){ return cur(); }
/** object to be used to lock in "synchronized" statement */
public static IDynamicServer dynamicThread(){
IG ig = cur(); if(ig==null) return null; return ig.dynamicServer();
}
/** alias of dynamicThread() */
public static IDynamicServer updateThread(){ return dynamicThread(); }
public static void setCurrent(IG ig){
int idx = iglist.indexOf(ig);
if(idx>=0 && idx<iglist.size()) currentId = idx;
else{ // not in the list
// add? really?
iglist.add(ig);
currentId = iglist.size()-1;
}
// default server for geometry creator
ICurveCreator.server(ig);
ISurfaceCreator.server(ig);
IMeshCreator.server(ig);
}
public static void setCurrent(IPanelI owner){
for(int i=0; i<iglist.size(); i++){
if(iglist.get(i).panel == owner){
currentId = i;
// default server for geometry creator
ICurveCreator.server(iglist.get(i));
ISurfaceCreator.server(iglist.get(i));
return;
}
}
IOut.err("no IG instance found for "+owner);
}
/** Find IG instance linked with the specified IPanel instance. */
public static IG getIG(IPanelI owner){
for(IG ig : iglist) if(ig.panel == owner) return ig;
return null;
}
public static IObject[] open(String file){
IG ig = cur();
if(ig==null) return null;
ArrayList<IObject> objects = ig.openFile(file);
if(objects==null) return null;
return objects.toArray(new IObject[objects.size()]);
}
public static boolean save(String file){
IG ig = cur();
if(ig==null) return false;
return ig.saveFile(file);
}
// dynamics methods
/** set duration of dynamics update */
public static void duration(int dur){ IG ig=cur(); if(ig!=null) ig.setDuration(dur); }
/** get duration of dynamics update */
public static int duration(){ IG ig=cur(); return ig==null?0:ig.getDuration(); }
/** set current time count of dynamics update. recommeded not to chage time. */
public static void time(int tm){ IG ig=cur(); if(ig!=null) ig.setTime(tm); }
/** get current time count of dynamics update */
public static int time(){ IG ig=cur(); return ig==null?-1:ig.getTime(); }
/** pause dynamics update. */
public static void pause(){ IG ig=cur(); if(ig!=null) ig.pauseDynamics(); }
/** resume dynamics update. */
public static void resume(){ IG ig=cur(); if(ig!=null) ig.resumeDynamics(); }
/** check if dynamics is running */
public static boolean isRunning(){ IG ig=cur(); if(ig!=null){ return ig.isDynamicsRunning(); } return false; }
/** start dynamics update. if IConfig.autoStart is true, this should not be used. */
public static void start(){ IG ig=cur(); if(ig!=null) ig.startDynamics(); }
/** stop dynamics update. recommended not to use this because stopping should be done by setting duration. */
public static void stop(){ IG ig=cur(); if(ig!=null) ig.stopDynamics(); }
/** setting update rate time interval in second */
public static void updateRate(double second){ IConfig.updateRate=second; }
/** alias of updateRate() */
public static void updateSpeed(double second){ updateRate(second); }
/** alias of updateRate() */
public static void rate(double second){ updateRate(second); }
/** alias of updateRate() */
public static void speed(double second){ updateRate(second); }
/** getting update rate time interval in second */
public static double updateRate(){ return IConfig.updateRate; }
/** alias of updateRate() */
public static double updateSpeed(){ return updateRate(); }
/** alias of updateRate() */
public static double rate(){ return updateRate(); }
/** alias of updateRate() */
public static double speed(){ return updateRate(); }
/** getting unit of current IG server */
public static IUnit unit(){
IG ig=cur(); if(ig!=null) return ig.server().unit();
return null;
}
/** setting unit of current IG server */
public static void unit(IUnit u){
IG ig=cur(); if(ig!=null) ig.server().unit(u);
}
/** setting unit of current IG server */
public static void unit(IUnit.Type u){
IG ig=cur(); if(ig!=null) ig.server().unit(u);
}
/** setting unit of current IG server */
public static void unit(String unitName){
IG ig=cur(); if(ig!=null) ig.server().unit(unitName);
}
/** to set the name first and save later (likely by key event) */
public static void outputFile(String filename){
IG ig = cur();
if(ig!=null) ig.setOutputFile(filename);
}
public static String outputFile(){
IG ig = cur();
if(ig==null) return null;
return ig.getOutputFile();
}
public static void inputFile(String filename){
IG ig = cur();
if(ig!=null) ig.setInputFile(filename);
}
public static String inputFile(){
IG ig = cur();
if(ig==null) return null;
return ig.getInputFile();
}
/** get all points in the current server */
public static IPoint[] points(){
IG ig = cur(); return ig==null?null:ig.getPoints();
}
/** get all points in the current server; alias */
public static IPoint[] pts(){ return points(); }
/** get all curves in the current server */
public static ICurve[] curves(){
IG ig = cur(); return ig==null?null:ig.getCurves();
}
/** get all curves in the current server; alias */
public static ICurve[] crvs(){ return curves(); }
/** get all curves in the current server
Note that IPolycurve contains multiple ICurve and they show up in curves() as well.
ICurve - IPolycurve relationship is still under work. This is temporary measure.
*/
public static IPolycurve[] polycurves(){
IG ig = cur(); return ig==null?null:ig.getPolycurves();
}
/** get all curves in the current server; alias.
Note that IPolycurve contains multiple ICurve and they show up in curves() as well.
ICurve - IPolycurve relationship is still under work. This is temporary measure.
*/
//public static ICurve[] pcrvs(){ return polycurves(); }
/** get all surfaces in the current server */
public static ISurface[] surfaces(){
IG ig = cur(); return ig==null?null:ig.getSurfaces();
}
/** get all surfaces in the current server; alias */
public static ISurface[] srfs(){ return surfaces(); }
/** get all meshes in the current server */
public static IMesh[] meshes(){
IG ig = cur(); return ig==null?null:ig.getMeshes();
}
/** get all breps in the current server */
public static IBrep[] breps(){
IG ig = cur(); return ig==null?null:ig.getBreps();
}
/** get all texts in the current server */
public static IText[] texts(){
IG ig = cur(); return ig==null?null:ig.getTexts();
}
/** get all geometry objects in the current server */
public static IGeometry[] geometries(){
IG ig = cur(); return ig==null?null:ig.getGeometries();
}
/** get all geometry objects in the current server */
public static IGeometry[] geos(){ return geometries(); }
/** get all objects of the specified class in the current server */
public static IObject[] objects(Class cls){
IG ig = cur(); return ig==null?null:ig.getObjects(cls);
}
/** get all objects of the specified class in the current server; alias */
public static IObject[] objs(Class cls){ return objects(); }
/** get all objects in the current server */
public static IObject[] objects(){
IG ig = cur(); return ig==null?null:ig.getObjects();
}
/** get all objects in the current server; alias */
public static IObject[] objs(){ return objects(); }
/** get a point in the current server */
public static IPoint point(int i){
IG ig = cur(); return ig==null?null:ig.getPoint(i);
}
/** get a point in the current server; alias */
public static IPoint pt(int i){ return point(i); }
/** get a curve in the current server */
public static ICurve curve(int i){
IG ig = cur(); return ig==null?null:ig.getCurve(i);
}
/** get a curve in the current server; alias */
public static ICurve crv(int i){ return curve(i); }
/** get a polycurve in the current server
Note that IPolycurve contains multiple ICurve and they show up in curves() as well.
ICurve - IPolycurve relationship is still under work. This is temporary measure.
*/
public static IPolycurve polycurve(int i){
IG ig = cur(); return ig==null?null:ig.getPolycurve(i);
}
/** get a curve in the current server; alias.
Note that IPolycurve contains multiple ICurve and they show up in curves() as well.
ICurve - IPolycurve relationship is still under work. This is temporary measure.
*/
//public static IPolycurve pcrv(int i){ return polycurve(i); }
/** get a surface in the current server */
public static ISurface surface(int i){
IG ig = cur(); return ig==null?null:ig.getSurface(i);
}
/** get a surface in the current server; alias */
public static ISurface srf(int i){ return surface(i); }
/** get a mesh in the current server */
public static IMesh mesh(int i){
IG ig = cur(); return ig==null?null:ig.getMesh(i);
}
/** get a brep in the current server */
public static IBrep brep(int i){
IG ig = cur(); return ig==null?null:ig.getBrep(i);
}
/** get a text in the current server */
public static IText text(int i){
IG ig = cur(); return ig==null?null:ig.getText(i);
}
/** get a geometry in the current server */
public static IGeometry geometry(int i){
IG ig = cur(); return ig==null?null:ig.getGeometry(i);
}
/** get a geometry in the current server */
public static IGeometry geo(int i){ return geometry(i); }
/** get a object of the specified class in the current server */
public static IObject object(Class cls, int i){
IG ig = cur(); return ig==null?null:ig.getObject(cls,i);
}
/** get a object of the specified class in the current server; alias */
public static IObject obj(Class cls, int i){ return object(cls,i); }
/** get a object in the current server */
public static IObject object(int i){
IG ig = cur(); return ig==null?null:ig.getObject(i);
}
/** get a object in the current server; alias */
public static IObject obj(int i){ return object(i); }
/** number of points in the current server */
public static int pointNum(){
IG ig = cur(); return ig==null?0:ig.getPointNum();
}
/** number of points in the current server; alias */
public static int ptNum(){ return pointNum(); }
/** number of curves in the current server */
public static int curveNum(){
IG ig = cur(); return ig==null?0:ig.getCurveNum();
}
/** number of curves in the current server; alias */
public static int crvNum(){ return curveNum(); }
/** number of polycurves in the current server.
Note that IPolycurve contains multiple ICurve and they show up in curves() as well.
ICurve - IPolycurve relationship is still under work. This is temporary measure.
*/
public static int polycurveNum(){
IG ig = cur(); return ig==null?0:ig.getPolycurveNum();
}
/** number of polycurves in the current server; alias.
Note that IPolycurve contains multiple ICurve and they show up in curves() as well.
ICurve - IPolycurve relationship is still under work. This is temporary measure.
*/
//fpublic static int pcrvNum(){ return polycurveNum(); }
/** number of surfaces in the current server */
public static int surfaceNum(){
IG ig = cur(); return ig==null?0:ig.getSurfaceNum();
}
/** number of surfaces in the current server; alias */
public static int srfNum(){ return surfaceNum(); }
/** number of meshes in the current server */
public static int meshNum(){
IG ig = cur(); return ig==null?0:ig.getMeshNum();
}
/** number of breps in the current server */
public static int brepNum(){
IG ig = cur(); return ig==null?0:ig.getBrepNum();
}
/** number of texts in the current server */
public static int textNum(){
IG ig = cur(); return ig==null?0:ig.getTextNum();
}
/** number of geometries in the cubrrent server */
public static int geometryNum(){
IG ig = cur(); return ig==null?0:ig.getGeometryNum();
}
/** alias of geometryNum() */
public static int geoNum(){ return geometryNum(); }
/** number of objects of the specified class in the current server */
public static int objectNum(Class cls){
IG ig = cur(); return ig==null?0:ig.getObjectNum(cls);
}
/** number of objects of the specified class in the current server; alias */
public static int objNum(Class cls){ return objectNum(cls); }
/** number of objects in the current server */
public static int objectNum(){
IG ig = cur(); return ig==null?0:ig.getObjectNum();
}
/** number of objects in the current server; alias */
public static int objNum(){ return objectNum(); }
public static void del(IObject o){ o.del(); }
public static void del(IObject[] o){
for(int i=0; i<o.length; i++){ if(o[i]!=null) o[i].del(); }
}
public static void del(ArrayList<IObject> o){
for(int i=0; i<o.size(); i++){ if(o.get(i)!=null) o.get(i).del(); }
}
/* delete all objects of specified class */
public static void del(Class cls){
IObject[] o = objects(cls);
del(o);
}
/* alias of clear(): clear all not just objects but all dynamics, graphics and layers */
public static void delAll(){ clear(); }
/* clear all not just objects but all dynamics, graphics and layers */
public static void clear(){
IG ig = cur();
if(ig!=null){ ig.clearServer(); }
}
public static ILayer layer(String layerName){
IG ig = cur();
if(ig==null) return null;
return ig.getLayer(layerName);
}
public static ILayer layer(int i){
IG ig = cur();
if(ig==null) return null;
return ig.getLayer(i);
}
public static ILayer[] layers(){
IG ig = cur();
if(ig==null) return null;
return ig.getAllLayers();
}
public static void delLayer(String layerName){
IG ig = cur();
if(ig==null) return;
ig.deleteLayer(layerName);
}
public static void delLayer(ILayer layer){
IG ig = cur();
if(ig==null) return;
ig.deleteLayer(layer);
}
public static int layerNum(){
IG ig = cur();
if(ig==null) return 0;
return ig.getLayerNum();
}
public static void focus(){
IG ig = cur();
if(ig==null) return;
ig.focusView();
}
public static boolean isGL(){
IG ig = cur();
if(ig==null){
IOut.err("no IG found");
return true; // GL is default
}
if(ig.server().graphicServer()==null){
IOut.err("no graphic server found");
return true; // GL is default
}
return ig.server().graphicServer().isGL();
}
public static void graphicMode(IGraphicMode mode){
IG ig = cur(); if(ig==null) return;
ig.server().setGraphicMode(mode);
}
/** set wireframe graphic mode */
public static void wireframe(){
IGraphicMode.GraphicType gtype = IGraphicMode.GraphicType.J2D;
if(isGL()) gtype = IGraphicMode.GraphicType.GL;
graphicMode(new IGraphicMode(gtype,false,true,false));
}
/** alias of wireframe() */
public static void wire(){ wireframe(); }
/** set fill graphic mode */
public static void fill(){
IGraphicMode.GraphicType gtype = IGraphicMode.GraphicType.J2D;
if(isGL()) gtype = IGraphicMode.GraphicType.GL;
graphicMode(new IGraphicMode(gtype,true,false,false));
}
/** set fill+wireframe graphic mode */
public static void fillWithWireframe(){ wireframeFill(); }
/** set fill+wireframe graphic mode */
public static void fillWireframe(){ wireframeFill(); }
/** set fill+wireframe graphic mode */
public static void fillWire(){ wireframeFill(); }
/** set fill+wireframe graphic mode */
public static void wireframeFill(){
IGraphicMode.GraphicType gtype = IGraphicMode.GraphicType.J2D;
if(isGL()) gtype = IGraphicMode.GraphicType.GL;
graphicMode(new IGraphicMode(gtype,true,true,false));
}
/** set fill+wireframe graphic mode */
public static void wireFill(){ wireframeFill(); }
/** set transparent fill graphic mode */
public static void transparentFill(){ transparent(); }
/** set transparent fill graphic mode */
public static void transFill(){ transparent(); }
/** set transparent fill graphic mode */
public static void transparent(){
IGraphicMode.GraphicType gtype = IGraphicMode.GraphicType.J2D;
if(isGL()) gtype = IGraphicMode.GraphicType.GL;
graphicMode(new IGraphicMode(gtype,true,false,true));
}
/** alias of transparent() */
public static void trans(){ transparent(); }
/** set transparent fill+wireframe graphic mode */
public static void transparentFillWithWireframe(){ wireframeTransparent(); }
/** set transparent fill+wireframe graphic mode */
public static void transparentWireframe(){ wireframeTransparent(); }
/** set transparent fill+wireframe graphic mode */
public static void wireframeTransparent(){
IGraphicMode.GraphicType gtype = IGraphicMode.GraphicType.J2D;
if(isGL()) gtype = IGraphicMode.GraphicType.GL;
graphicMode(new IGraphicMode(gtype,true,true,true));
}
/** alias of wireframeTransparent() */
public static void wireTrans(){ wireframeTransparent(); }
/** alias of wireframeTransparent() */
public static void transWire(){ wireframeTransparent(); }
public static void noGraphic(){
IGraphicMode.GraphicType gtype = IGraphicMode.GraphicType.J2D;
if(isGL()) gtype = IGraphicMode.GraphicType.GL;
graphicMode(new IGraphicMode(gtype,false,false,false));
}
public static IView view(int paneIndex){
IG ig = cur(); if(ig==null) return null;
if(ig==null || ig.panel==null || ig.panel.paneNum()>0 ||
ig.panel.paneNum() <= paneIndex || paneIndex<0 ){ return null; }
if(ig.panel instanceof IScreenTogglePanel){
((IScreenTogglePanel)(ig.panel)).enableFullScreen(ig.panel.pane(paneIndex));
}
return ig.panel.pane(paneIndex).getView();
}
/** put the specified pane on the full screen inside the window if the panel is IGridPanel with 2x2 grid */
public static IPane gridPane(int xindex, int yindex){
IG ig = cur(); if(ig==null) return null;
if(ig.panel!=null && ig.panel instanceof IGridPanel){
IGridPanel gpanel = (IGridPanel)ig.panel;
if(xindex>=0 && xindex < gpanel.gridPanes.length &&
yindex>=0 && yindex < gpanel.gridPanes[xindex].length ){
IPane pane = gpanel.gridPanes[xindex][yindex];
gpanel.enableFullScreen(pane);
return pane;
}
else if(gpanel.gridPanes.length>0 &&
gpanel.gridPanes[0].length>0 ){
IPane pane = gpanel.gridPanes[0][0];
gpanel.enableFullScreen(0);
return pane;
}
}
return null;
}
/** put the specified pane on the full screen inside the window if the panel is IGridPanel with 2x2 grid */
public static void disableFullScreen(){
IG ig = cur(); if(ig==null) return;
if(ig.panel!=null && ig.panel instanceof IGridPanel){
IGridPanel gpanel = (IGridPanel)ig.panel;
gpanel.disableFullScreen();
}
}
/** put top pane on the full screen inside the window if the panel is IGridPanel */
public static IPane topPane(){ return gridPane(0,0); }
/** bottom pane is identical with top pane in IGridPanel */
public static IPane bottomPane(){ return topPane(); }
/** put perspective pane on the full screen inside the window if the panel is IGridPanel */
public static IPane perspectivePane(){ return gridPane(1,0); }
/** axonometric pane is identical with perspective pane in IGridPanel */
public static IPane axonometricPane(){ return perspectivePane(); }
/** put front pane on the full screen inside the window if the panel is IGridPanel */
public static IPane frontPane(){ return gridPane(0,1); }
/** back pane is identical with front pane in IGridPanel */
public static IPane backPane(){ return frontPane(); }
/** put right pane on the full screen inside the window if the panel is IGridPanel */
public static IPane rightPane(){ return gridPane(1,1); }
/** left pane is identical with front pane in IGridPanel */
public static IPane leftPane(){ return rightPane(); }
/** put top view on the full screen inside the window */
public static void top(){
IPane pane = topPane();
if(pane!=null){
pane.getView().setTop();
pane.focus(); // added 20120615
}
}
public static void top(double x, double y){
IPane pane = topPane();
if(pane!=null){ pane.getView().setTop(x,y); }
}
public static void top(double x, double y, double z){
IPane pane = topPane();
if(pane!=null){ pane.getView().setTop(x,y,z); }
}
public static void top(double x, double y, double z, double axonRatio){
IPane pane = topPane();
if(pane!=null){ pane.getView().setTop(x,y,z,axonRatio); }
}
public static void topView(){ top(); }
public static void topView(double x, double y){ top(x,y); }
public static void topView(double x, double y, double z){ top(x,y,z); }
public static void topView(double x, double y, double z, double axonRatio){
top(x,y,z,axonRatio);
}
/** get camera position in top view pane */
public static IVec topPos(){ return getViewPos(topPane()); }
/** get camera direction vector in top view pane */
public static IVec topDir(){ return getViewDir(topPane()); }
/** get camera target position in top view pane */
public static IVec topTarget(){ return getViewTarget(topPane()); }
/** get camera direction yaw angle in top view pane */
public static double topYaw(){ return getViewYaw(topPane()); }
/** get camera direction pitch angle in top view pane */
public static double topPitch(){ return getViewPitch(topPane()); }
/** get camera direction roll angle in top view pane */
public static double topRoll(){ return getViewPitch(topPane()); }
/** put bottom view on the full screen inside the window */
public static void bottom(){
IPane pane = bottomPane();
if(pane!=null){
pane.getView().setBottom();
pane.focus(); // added 20120615
}
}
public static void bottom(double x, double y){
IPane pane = bottomPane();
if(pane!=null){ pane.getView().setBottom(x,y); }
}
public static void bottom(double x, double y, double z){
IPane pane = bottomPane();
if(pane!=null){ pane.getView().setBottom(x,y,z); }
}
public static void bottom(double x, double y, double z, double axonRatio){
IPane pane = bottomPane();
if(pane!=null){ pane.getView().setBottom(x,y,z,axonRatio); }
}
public static void bottomView(){ bottom(); }
public static void bottomView(double x, double y){ bottom(x,y); }
public static void bottomView(double x, double y, double z){ bottom(x,y,z); }
public static void bottomView(double x, double y, double z, double axonRatio){ bottom(x,y,z,axonRatio); }
/** get camera position in bottom view pane */
public static IVec bottomPos(){ return getViewPos(bottomPane()); }
/** get camera direction vector in bottom view pane */
public static IVec bottomDir(){ return getViewDir(bottomPane()); }
/** get camera target position in bottom view pane */
public static IVec bottomTarget(){ return getViewTarget(bottomPane()); }
/** get camera direction yaw angle in bottom view pane */
public static double bottomYaw(){ return getViewYaw(bottomPane()); }
/** get camera direction pitch angle in bottom view pane */
public static double bottomPitch(){ return getViewPitch(bottomPane()); }
/** get camera direction roll angle in bottom view pane */
public static double bottomRoll(){ return getViewPitch(bottomPane()); }
/** put perspective view on the full screen inside the window */
public static void perspective(){
IPane pane = perspectivePane();
if(pane!=null){
pane.getView().setPerspective();
pane.focus(); // added 20120615
}
}
public static void perspective(double x, double y, double z){
IPane pane = perspectivePane();
if(pane!=null){ pane.getView().setPerspective(x,y,z); }
}
public static void perspective(double x, double y, double z,
double yaw, double pitch){
IPane pane = perspectivePane();
if(pane!=null){ pane.getView().setPerspective(x,y,z,yaw,pitch); }
}
public static void perspective(IVecI pos, IVecI dir){
IPane pane = perspectivePane();
if(pane!=null){ pane.getView().setPerspective(pos,dir); }
}
public static void perspectiveView(){ perspective(); }
public static void perspectiveView(double x, double y, double z){ perspective(x,y,z); }
public static void perspectiveView(double x, double y, double z,
double yaw, double pitch){ perspective(x,y,z,yaw,pitch); }
public static void perspectiveView(IVecI pos, IVecI dir){ perspective(pos,dir); }
public static void pers(){ perspective(); }
public static void pers(double x, double y, double z){ perspective(x,y,z); }
public static void pers(double x, double y, double z, double yaw, double pitch){ perspective(x,y,z,yaw,pitch); }
public static void pers(IVecI pos, IVecI dir){ perspective(pos,dir); }
/** put perspective view on the full screen inside the window */
public static void perspective(double perspectiveAngle){
IPane pane = perspectivePane();
if(pane!=null){
pane.getView().setPerspective(perspectiveAngle);
}
}
public static void perspective(double x, double y, double z,
double perspectiveAngle){
IPane pane = perspectivePane();
if(pane!=null){
pane.getView().setPerspective(x,y,z,perspectiveAngle);
}
}
public static void perspective(double x, double y, double z,
double yaw, double pitch,
double perspectiveAngle){
IPane pane = perspectivePane();
if(pane!=null){
pane.getView().setPerspective(x,y,z,yaw,pitch,perspectiveAngle);
}
}
public static void perspective(IVecI pos, IVecI dir, double perspectiveAngle){
IPane pane = perspectivePane();
if(pane!=null){
pane.getView().setPerspective(pos,dir,perspectiveAngle);
}
}
public static void perspectiveView(double perspectiveAngle){ perspective(perspectiveAngle); }
public static void perspectiveView(double x, double y, double z,
double perspectiveAngle){
perspective(x,y,z,perspectiveAngle);
}
public static void perspectiveView(double x, double y, double z,
double yaw, double pitch,
double perspectiveAngle){
perspective(x,y,z,yaw,pitch,perspectiveAngle);
}
public static void perspectiveView(IVecI pos, IVecI dir, double perspectiveAngle){
perspective(pos,dir,perspectiveAngle);
}
public static void pers(double perspectiveAngle){ perspective(perspectiveAngle); }
public static void pers(double x, double y, double z, double perspectiveAngle){
perspective(x,y,z,perspectiveAngle);
}
public static void pers(double x, double y, double z, double yaw, double pitch, double perspectiveAngle){
perspective(x,y,z,yaw,pitch,perspectiveAngle);
}
public static void pers(IVecI pos, IVecI dir, double perspectiveAngle){
perspective(pos,dir,perspectiveAngle);
}
/** get camera position out of pane */
public static IVec getViewPos(IPane pane){
if(pane==null){ IG.err("no pane found"); return new IVec(); }
IView view = pane.getView();
if(view==null){ IG.err("no view found"); return new IVec(); }
return view.location();
}
/** get camera direction out of pane */
public static IVec getViewDir(IPane pane){
if(pane==null){ IG.err("no pane found"); return new IVec(); }
IView view = pane.getView();
if(view==null){ IG.err("no view found"); return new IVec(); }
return view.frontDirection();
}
/** get camera target position out of pane */
public static IVec getViewTarget(IPane pane){
if(pane==null){ IG.err("no pane found"); return new IVec(); }
IView view = pane.getView();
if(view==null){ IG.err("no view found"); return new IVec(); }
return view.target();
}
/** get camera directio yaw angle out of pane */
public static double getViewYaw(IPane pane){
if(pane==null){ IG.err("no pane found"); return 0; }
IView view = pane.getView();
if(view==null){ IG.err("no view found"); return 0; }
return view.getYaw();
}
/** get camera directio pitch angle out of pane */
public static double getViewPitch(IPane pane){
if(pane==null){ IG.err("no pane found"); return 0; }
IView view = pane.getView();
if(view==null){ IG.err("no view found"); return 0; }
return view.getPitch();
}
/** get camera directio roll angle out of pane */
public static double getViewRoll(IPane pane){
if(pane==null){ IG.err("no pane found"); return 0; }
IView view = pane.getView();
if(view==null){ IG.err("no view found"); return 0; }
return view.getRoll();
}
/** get camera position in perspective view pane */
public static IVec persPos(){ return getViewPos(perspectivePane()); }
/** get camera direction vector in perspective view pane */
public static IVec persDir(){ return getViewDir(perspectivePane()); }
/** get camera target position in perspective view pane */
public static IVec persTarget(){ return getViewTarget(perspectivePane()); }
/** get camera direction yaw angle in perspective view pane */
public static double persYaw(){ return getViewYaw(perspectivePane()); }
/** get camera direction pitch angle in perspective view pane */
public static double persPitch(){ return getViewPitch(perspectivePane()); }
/** get camera direction roll angle in perspective view pane */
public static double persRoll(){ return getViewPitch(perspectivePane()); }
/** put axonometric view on the full screen inside the window */
public static void axonometric(){
IPane pane = axonometricPane();
if(pane!=null){
pane.getView().setAxonometric();
pane.focus(); // added 20120615
}
}
public static void axonometric(double x, double y, double z){
IPane pane = axonometricPane();
if(pane!=null){ pane.getView().setAxonometric(x,y,z); }
}
public static void axonometric(double x, double y, double z, double axonRatio){
IPane pane = axonometricPane();
if(pane!=null){ pane.getView().setAxonometric(x,y,z,axonRatio); }
}
public static void axonometric(double x, double y, double z, double yaw, double pitch){
IPane pane = axonometricPane();
if(pane!=null){ pane.getView().setAxonometric(x,y,z,yaw,pitch); }
}
public static void axonometric(double x, double y, double z, double yaw, double pitch, double axonRatio){
IPane pane = axonometricPane();
if(pane!=null){ pane.getView().setAxonometric(x,y,z,yaw,pitch,axonRatio); }
}
public static void axonometric(IVecI pos, IVecI dir){
IPane pane = axonometricPane();
if(pane!=null){ pane.getView().setAxonometric(pos,dir); }
}
public static void axonometric(IVecI pos, IVecI dir, double axonRatio){
IPane pane = axonometricPane();
if(pane!=null){ pane.getView().setAxonometric(pos,dir,axonRatio); }
}
public static void axonometricView(){ axonometric(); }
public static void axonometricView(double x, double y, double z){
axonometric(x,y,z);
}
public static void axonometricView(double x, double y, double z, double axonRatio){
axonometric(x,y,z,axonRatio);
}
public static void axonometricView(double x, double y, double z,
double yaw, double pitch){
axonometric(x,y,z,yaw,pitch);
}
public static void axonometricView(double x, double y, double z,
double yaw, double pitch, double axonRatio){
axonometric(x,y,z,yaw,pitch,axonRatio);
}
public static void axonometricView(IVecI pos, IVecI dir){
axonometric(pos,dir);
}
public static void axonometricView(IVecI pos, IVecI dir, double axonRatio){
axonometric(pos,dir,axonRatio);
}
public static void axon(){ axonometric(); }
public static void axon(double x, double y, double z){
axonometric(x,y,z);
}
public static void axon(double x, double y, double z, double axonRatio){
axonometric(x,y,z,axonRatio);
}
public static void axon(double x, double y, double z, double yaw, double pitch){
axonometric(x,y,z,yaw,pitch);
}
public static void axon(double x, double y, double z, double yaw, double pitch, double axonRatio){
axonometric(x,y,z,yaw,pitch,axonRatio);
}
public static void axon(IVecI pos, IVecI dir){
axonometric(pos,dir);
}
public static void axon(IVecI pos, IVecI dir, double axonRatio){
axonometric(pos,dir,axonRatio);
}
/** get camera position in axonometric view pane (same pane with perspective pane) */
public static IVec axonPos(){ return getViewPos(axonometricPane()); }
/** get camera direction vector in axonometric view pane (same pane with perspective pane) */
public static IVec axonDir(){ return getViewDir(axonometricPane()); }
/** get camera target position in axonometric view pane (same pane with perspective pane) */
public static IVec axonTarget(){ return getViewTarget(axonometricPane()); }
/** get camera direction yaw angle in axonometric view pane (same pane with perspective pane) */
public static double axonYaw(){ return getViewYaw(axonometricPane()); }
/** get camera direction pitch angle in axonometric view pane (same pane with perspective pane) */
public static double axonPitch(){ return getViewPitch(axonometricPane()); }
/** get camera direction roll angle in axonometric view pane (same pane with perspective pane) */
public static double axonRoll(){ return getViewPitch(axonometricPane()); }
/** put front view on the full screen inside the window */
public static void front(){
IPane pane = frontPane();
if(pane!=null){
pane.getView().setFront();
pane.focus(); // added 20120615
}
}
public static void front(double x, double z){
IPane pane = frontPane();
if(pane!=null){ pane.getView().setFront(x,z); }
}
public static void front(double x, double y, double z){
IPane pane = frontPane();
if(pane!=null){ pane.getView().setFront(x,y,z); }
}
public static void front(double x, double y, double z, double axonRatio){
IPane pane = frontPane();
if(pane!=null){ pane.getView().setFront(x,y,z,axonRatio); }
}
public static void frontView(){ front(); }
public static void frontView(double x, double z){ front(x,z); }
public static void frontView(double x, double y, double z){ front(x,y,z); }
public static void frontView(double x, double y, double z, double axonRatio){ front(x,y,z,axonRatio); }
/** get camera position in front view pane */
public static IVec frontPos(){ return getViewPos(frontPane()); }
/** get camera direction vector in front view pane */
public static IVec frontDir(){ return getViewDir(frontPane()); }
/** get camera target position in front view pane */
public static IVec frontTarget(){ return getViewTarget(frontPane()); }
/** get camera direction yaw angle in front view pane */
public static double frontYaw(){ return getViewYaw(frontPane()); }
/** get camera direction pitch angle in front view pane */
public static double frontPitch(){ return getViewPitch(frontPane()); }
/** get camera direction roll angle in front view pane */
public static double frontRoll(){ return getViewPitch(frontPane()); }
/** put back view on the full screen inside the window */
public static void back(){
IPane pane = backPane();
if(pane!=null){
pane.getView().setBack();
pane.focus(); // added 20120615
}
}
public static void back(double x, double z){
IPane pane = backPane();
if(pane!=null){ pane.getView().setBack(x,z); }
}
public static void back(double x, double y, double z){
IPane pane = backPane();
if(pane!=null){ pane.getView().setBack(x,y,z); }
}
public static void back(double x, double y, double z, double axonRatio){
IPane pane = backPane();
if(pane!=null){ pane.getView().setBack(x,y,z,axonRatio); }
}
public static void backView(){ back(); }
public static void backView(double x, double z){ back(x,z); }
public static void backView(double x, double y, double z){ back(x,y,z); }
public static void backView(double x, double y, double z, double axonRatio){ back(x,y,z,axonRatio); }
/** get camera position in back view pane */
public static IVec backPos(){ return getViewPos(backPane()); }
/** get camera direction vector in back view pane */
public static IVec backDir(){ return getViewDir(backPane()); }
/** get camera target position in back view pane */
public static IVec backTarget(){ return getViewTarget(backPane()); }
/** get camera direction yaw angle in back view pane */
public static double backYaw(){ return getViewYaw(backPane()); }
/** get camera direction pitch angle in back view pane */
public static double backPitch(){ return getViewPitch(backPane()); }
/** get camera direction roll angle in back view pane */
public static double backRoll(){ return getViewPitch(backPane()); }
/** put right view on the full screen inside the window */
public static void right(){
IPane pane = rightPane();
if(pane!=null){
pane.getView().setRight();
pane.focus(); // added 20120615
}
}
public static void right(double y, double z){
IPane pane = rightPane();
if(pane!=null){ pane.getView().setRight(y, z); }
}
public static void right(double x, double y, double z){
IPane pane = rightPane();
if(pane!=null){ pane.getView().setRight(x, y, z); }
}
public static void right(double x, double y, double z, double axonRatio){
IPane pane = rightPane();
if(pane!=null){ pane.getView().setRight(x, y, z, axonRatio); }
}
public static void rightView(){ right(); }
public static void rightView(double y, double z){ right(y,z); }
public static void rightView(double x, double y, double z){ right(x,y,z); }
public static void rightView(double x, double y, double z, double axonRatio){ right(x,y,z,axonRatio); }
/** get camera position in right view pane */
public static IVec rightPos(){ return getViewPos(rightPane()); }
/** get camera direction vector in right view pane */
public static IVec rightDir(){ return getViewDir(rightPane()); }
/** get camera target position in right view pane */
public static IVec rightTarget(){ return getViewTarget(rightPane()); }
/** get camera direction yaw angle in right view pane */
public static double rightYaw(){ return getViewYaw(rightPane()); }
/** get camera direction pitch angle in right view pane */
public static double rightPitch(){ return getViewPitch(rightPane()); }
/** get camera direction roll angle in right view pane */
public static double rightRoll(){ return getViewPitch(rightPane()); }
/** put left view on the full screen inside the window */
public static void left(){
IPane pane = leftPane();
if(pane!=null){
pane.getView().setLeft();
pane.focus(); // added 20120615
}
}
public static void left(double y, double z){
IPane pane = leftPane();
if(pane!=null){ pane.getView().setLeft(y,z); }
}
public static void left(double x, double y, double z){
IPane pane = leftPane();
if(pane!=null){ pane.getView().setLeft(x,y,z); }
}
public static void left(double x, double y, double z, double axonRatio){
IPane pane = leftPane();
if(pane!=null){ pane.getView().setLeft(x,y,z,axonRatio); }
}
public static void leftView(){ left(); }
public static void leftView(double y, double z){ left(y,z); }
public static void leftView(double x, double y, double z){ left(x,y,z); }
public static void leftView(double x, double y, double z, double axonRatio){ left(x,y,z,axonRatio); }
/** get camera position in left view pane */
public static IVec leftPos(){ return getViewPos(leftPane()); }
/** get camera direction vector in left view pane */
public static IVec leftDir(){ return getViewDir(leftPane()); }
/** get camera target position in left view pane */
public static IVec leftTarget(){ return getViewTarget(leftPane()); }
/** get camera direction yaw angle in left view pane */
public static double leftYaw(){ return getViewYaw(leftPane()); }
/** get camera direction pitch angle in left view pane */
public static double leftPitch(){ return getViewPitch(leftPane()); }
/** get camera direction roll angle in left view pane */
public static double leftRoll(){ return getViewPitch(leftPane()); }
/****************************
* background color
***************************/
//public static void setBG(Color c){}
//public static void setBG(Color c1, Color c2){}
//public static void setBG(Color c1, Color c2, Color c3, Color c4){}
//public static void setBG(Image img){}
public static void bg(IColor c1, IColor c2, IColor c3, IColor c4){
IG ig = cur(); if(ig==null) return;
ig.server().bg(c1,c2,c3,c4);
}
public static void background(IColor c1, IColor c2, IColor c3, IColor c4){ bg(c1,c2,c3,c4); }
public static void bg(Color c1, Color c2, Color c3, Color c4){
bg(new IColor(c1),new IColor(c2),new IColor(c3),new IColor(c4));
}
public static void background(Color c1, Color c2, Color c3, Color c4){ bg(c1,c2,c3,c4); }
public static void bg(Color c){ bg(c,c,c,c); }
public static void background(Color c){ bg(c); }
/*
public static void bg(Image img){
IG ig = cur(); if(ig==null) return;
ig.server().bg(img);
}
public static void background(Image img){ bg(img); }
public static void bg(String filename){
IG ig = cur(); if(ig==null) return;
ig.server().bg(IImageLoader.getImage(filename));
}
public static void background(String filename){ bg(filename); }
*/
public static void bg(String imageFilename){
IG ig = cur(); if(ig==null) return;
ig.server().bg(imageFilename);
}
public static void background(String imageFilename){ bg(imageFilename); }
public static void defaultBG(){ blueBG(); }
public static void blueBG(){ bg(IConfig.bgColor1,IConfig.bgColor2,IConfig.bgColor3,IConfig.bgColor4); } // added 2012/09/02
public static void lightBG(){ bg(1.0, 1.0, 0.9, 0.8); } // added 2012/09/02
public static void darkBG(){ bg(0.15, 0.15, 0.05, 0.0); } // added 2012/09/02
public static void whiteBG(){ bg(1.0); } // added 2012/09/02
public static void blackBG(){ bg(0.0); } // added 2012/09/02
public static void bg(int r1, int g1, int b1,
int r2, int g2, int b2,
int r3, int g3, int b3,
int r4, int g4, int b4){
bg(IGraphicObject.getColor(r1,g1,b1), IGraphicObject.getColor(r2,g2,b2),
IGraphicObject.getColor(r3,g3,b3), IGraphicObject.getColor(r4,g4,b4));
}
public static void background(int r1, int g1, int b1,
int r2, int g2, int b2,
int r3, int g3, int b3,
int r4, int g4, int b4){
bg(r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,b4,g4);
}
public static void bg(int r, int g, int b){
bg(IGraphicObject.getColor(r,g,b));
}
public static void background(int r, int g, int b){ bg(r,g,b); }
public static void bg(int gray1, int gray2, int gray3, int gray4){
bg(IGraphicObject.getColor(gray1), IGraphicObject.getColor(gray2),
IGraphicObject.getColor(gray3), IGraphicObject.getColor(gray4));
}
public static void background(int gray1, int gray2, int gray3, int gray4){
bg(gray1,gray2,gray3,gray4);
}
public static void bg(int gray){ bg(IGraphicObject.getColor(gray)); }
public static void background(int gray){ bg(gray); }
public static void bg(float r1, float g1, float b1,
float r2, float g2, float b2,
float r3, float g3, float b3,
float r4, float g4, float b4){
bg(IGraphicObject.getColor(r1,g1,b1), IGraphicObject.getColor(r2,g2,b2),
IGraphicObject.getColor(r3,g3,b3), IGraphicObject.getColor(r4,g4,b4));
}
public static void background(float r1, float g1, float b1,
float r2, float g2, float b2,
float r3, float g3, float b3,
float r4, float g4, float b4){
bg(r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,b4,g4);
}
public static void bg(float r, float g, float b){
bg(IGraphicObject.getColor(r,g,b));
}
public static void background(float r, float g, float b){ bg(r,g,b); }
public static void bg(float gray1, float gray2, float gray3, float gray4){
bg(IGraphicObject.getColor(gray1), IGraphicObject.getColor(gray2),
IGraphicObject.getColor(gray3), IGraphicObject.getColor(gray4));
}
public static void background(float gray1, float gray2, float gray3, float gray4){
bg(gray1,gray2,gray3,gray4);
}
public static void bg(float gray){ bg(IGraphicObject.getColor(gray)); }
public static void background(float gray){ bg(gray); }
public static void bg(double r1, double g1, double b1,
double r2, double g2, double b2,
double r3, double g3, double b3,
double r4, double g4, double b4){
bg(IGraphicObject.getColor((float)r1,(float)g1,(float)b1),
IGraphicObject.getColor((float)r2,(float)g2,(float)b2),
IGraphicObject.getColor((float)r3,(float)g3,(float)b3),
IGraphicObject.getColor((float)r4,(float)g4,(float)b4));
}
public static void background(double r1, double g1, double b1,
double r2, double g2, double b2,
double r3, double g3, double b3,
double r4, double g4, double b4){
bg(r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,b4,g4);
}
public static void bg(double r, double g, double b){
bg(IGraphicObject.getColor((float)r,(float)g,(float)b));
}
public static void background(double r, double g, double b){ bg(r,g,b); }
public static void bg(double gray1, double gray2, double gray3, double gray4){
bg(IGraphicObject.getColor((float)gray1), IGraphicObject.getColor((float)gray2),
IGraphicObject.getColor((float)gray3), IGraphicObject.getColor((float)gray4));
}
public static void background(double gray1, double gray2, double gray3, double gray4){
bg(gray1,gray2,gray3,gray4);
}
public static void bg(double gray){ bg(IGraphicObject.getColor((float)gray)); }
public static void background(double gray){ bg(gray); }
/** Print method with header and new line.
This is a wrapper of IOut.p(), which is
also a wrapper of System.out.println().
*/
public static void p(Object obj){ IOut.printlnWithOffset(obj,1); }
/** Print method only with header and new line. */
public static void p(){ IOut.printlnWithOffset(1); }
/** Print method without header nor new line
This is a wrapper of IOut.p(), which is
also a wrapper of System.out.print().
*/
public static void print(Object obj){ IOut.print(obj); }
/** enable print prefix (executing method name)*/
public static void enabePrintPrefix(){ IOut.enablePrefix(); }
/** disble print prefix (executing method name)*/
public static void disablePrintPrefix(){ IOut.disablePrefix(); }
/** Error print method with header and new line.
This is a wrapper of IOut.err() */
public static void err(Object obj){ IOut.errWithOffset(obj,1); }
/** Error print method only with header and new line. */
public static void err(){ IOut.errWithOffset(1); }
/** Error print method without header nor new line. */
public static void error(Object obj){ IOut.error(obj); }
/** enable error print prefix (executing method name)*/
public static void enabeErrorPrefix(){ IOut.enablePrefix(); }
/** disable error print prefix (executing method name)*/
public static void disableErrorPrefix(){ IOut.disablePrefix(); }
/** change the debug level of IOut */
public static void debugLevel(int level){ IOut.debugLevel(level); }
/** alias of debugLevel */
public static void debug(int level){ debugLevel(level); }
/** turns on all debug output */
public static void debug(){ debugLevel(-1); }
/** returns the current debugLevel */
public static int debugLevel(){ return IOut.debugLevel(); }
/** enable printing time to console */
public static void showTime(){ showTime(true); }
/** enable/disable printing time to console */
public static void showTime(boolean flag){
IG ig = cur(); if(ig==null) return;
if(ig.dynamicServer()==null) return;
ig.dynamicServer().showTime(flag);
}
/** redirect print to print wrapper */
public static void setPrint(IPrintWrapper pw){ IOut.setPrint(pw); }
/** redirect print to print wrapper */
public static void setPrint(IPrintWrapper pw, IPrintWrapper errpw){ IOut.setPrint(pw, errpw); }
/** redirect print to print wrapper */
public static void setPrint(IPrintWrapper pw, IPrintWrapper errpw, IPrintWrapper debugpw){
IOut.setPrint(pw, errpw, debugpw);
}
/** redirect print to print stream */
public static void setPrintStream(PrintStream ps){
IOut.ps = ps;
IOut.err = ps;
IOut.debug = ps;
}
/** redirect print to print stream */
public static void setPrintStream(PrintStream ps, PrintStream errps){
IOut.ps = ps;
IOut.err = errps;
IOut.debug = ps;
}
/** redirect print to print stream */
public static void setPrintStream(PrintStream ps, PrintStream errps, PrintStream debugps){
IOut.ps = ps;
IOut.err = errps;
IOut.debug = debugps;
}
/*************************************************************************
* object methods
*************************************************************************/
// anybody would want this in public?
//protected
public IG(){ server = new IServer(this); }
//protected
public IG(IPanelI p){
server = new IServer(this, p);
panel = p; //
p.setIG(this);
}
public ArrayList<IObject> openFile(String file){
//boolean retval = false;
ArrayList<IObject> objects=null;
if(inputWrapper!=null){ objects= IIO.open(file,this,inputWrapper); }
else{
File f = new File(file);
if(!f.isAbsolute() && basePath!=null){ file = basePath + File.separator + file; }
objects = IIO.open(file,this);
}
server.updateState(); // update server status
inputFile = file;
//focusView(); // instead of here, focused at the end of setup if IConfig.autoFocusAtStart is true
return objects;
}
public String formatOutputFilePath(String file){
File f = new File(file);
if(!f.isAbsolute() && basePath!=null){
file = basePath + File.separator + file;
File baseDir = new File(basePath);
if(!baseDir.isDirectory()){
IOut.debug(20, "creating directory"+baseDir.toString());
if(!baseDir.mkdir()){
IOut.err("failed to create directory: "+baseDir.toString());
}
}
}
return file;
}
public boolean saveFile(String file){
file = formatOutputFilePath(file);
/*
File f = new File(file);
if(!f.isAbsolute() && basePath!=null){
file = basePath + File.separator + file;
File baseDir = new File(basePath);
if(!baseDir.isDirectory()){
IOut.debug(20, "creating directory"+baseDir.toString());
if(!baseDir.mkdir()){
IOut.err("failed to create directory: "+baseDir.toString());
}
}
}
*/
return IIO.save(file,this);
}
public boolean save(){
if(outputFile==null){
IOut.err("output filename is not set. not saved");
return false;
}
return saveFile(outputFile);
}
public void setInputFile(String filename){ inputFile=filename; }
public void setOutputFile(String filename){ outputFile=filename; }
public String getInputFile(){ return inputFile; }
public String getOutputFile(){ return outputFile; }
public String getBasePath(){ return basePath; }
public String setBasePath(String path){ return basePath=path; }
public void setOnline(boolean f){ online=f; }
public boolean isOnline(){ return online; }
public void setInputWrapper(IInputWrapper wrapper){ inputWrapper = wrapper; }
public ILayer getLayer(String layerName){ return server.getLayer(layerName); }
public ILayer getLayer(int i){ return server.getLayer(i); }
public ILayer[] getAllLayers(){ return server.getAllLayers(); }
public void deleteLayer(String layerName){ server.deleteLayer(layerName); }
public void deleteLayer(ILayer layer){ server.deleteLayer(layer); }
public int getLayerNum(){ return server.layerNum(); }
public IPoint[] getPoints(){ return server.points(); }
public ICurve[] getCurves(){ return server.curves(); }
public IPolycurve[] getPolycurves(){ return server.polycurves(); }
public ISurface[] getSurfaces(){ return server.surfaces(); }
public IMesh[] getMeshes(){ return server.meshes(); }
public IBrep[] getBreps(){ return server.breps(); }
public IText[] getTexts(){ return server.texts(); }
public IGeometry[] getGeometries(){ return server.geometries(); }
public IObject[] getObjects(Class cls){ return server.objects(cls); }
public IObject[] getObjects(){ return server.objects(); }
public IPoint getPoint(int i){ return server.point(i); }
public ICurve getCurve(int i){ return server.curve(i); }
public IPolycurve getPolycurve(int i){ return server.polycurve(i); }
public ISurface getSurface(int i){ return server.surface(i); }
public IMesh getMesh(int i){ return server.mesh(i); }
public IBrep getBrep(int i){ return server.brep(i); }
public IText getText(int i){ return server.text(i); }
public IGeometry getGeometry(int i){ return server.geometry(i); }
public IObject getObject(Class cls,int i){ return server.object(cls,i); }
public IObject getObject(int i){ return server.object(i); }
public int getPointNum(){ return server.pointNum(); }
public int getCurveNum(){ return server.curveNum(); }
public int getPolycurveNum(){ return server.polycurveNum(); }
public int getSurfaceNum(){ return server.surfaceNum(); }
public int getMeshNum(){ return server.meshNum(); }
public int getBrepNum(){ return server.brepNum(); }
public int getTextNum(){ return server.textNum(); }
public int getGeometryNum(){ return server.geometryNum(); }
public int getObjectNum(Class cls){ return server.objectNum(cls); }
public int getObjectNum(){ return server.objectNum(); }
public void focusView(){
if(panel!=null) panel.focus(); // focus on all pane
}
public IServer server(){ return server; }
public IDynamicServer dynamicServer(){ return server.dynamicServer(); }
// dynamics
public void setDuration(int dur){ server.duration(dur); }
public int getDuration(){ return server.duration(); }
public void setTime(int tm){ server.time(tm); }
public int getTime(){ return server.time(); }
public void pauseDynamics(){ server.pause(); }
public void resumeDynamics(){ server.resume(); }
/** check if dynamics is running */
public boolean isDynamicsRunning(){ return server.isRunning(); }
public void startDynamics(){ server.start(); }
public void stopDynamics(){ server.stop(); }
//public void draw(IGraphics g){ server.draw(g); }
//public IGPane pane(){ return pane; }
//public IPanelI panel(){ return panel; }
//public void delete(){
/* name is changed from clear() to clearServer(). delete objects, graphic objects, dynamics and layers */
public void clearServer(){ server.clear(); }
/*********************************************************************
* Static Geometry Operations
********************************************************************/
/** point creation */
public static IPoint point(IVecI v){ return pt(v); }
public static IPoint point(IVec v){ return pt(v); }
public static IPoint point(double x, double y, double z){ return pt(x,y,z); }
public static IPoint point(double x, double y){ return pt(x,y); }
/** point creation shorter name */
public static IPoint pt(IVecI v){ return new IPoint(v); }
public static IPoint pt(IVec v){ return new IPoint(v); }
public static IPoint pt(double x, double y, double z){ return new IPoint(x,y,z); }
public static IPoint pt(double x, double y){ return new IPoint(x,y); }
public static ICurve curve(IVecI[] cpts, int degree, double[] knots, double ustart, double uend){
return ICurveCreator.curve(cpts,degree,knots,ustart,uend);
}
public static ICurve curve(IVecI[] cpts, int degree, double[] knots){
return ICurveCreator.curve(cpts,degree,knots);
}
public static ICurve curve(IVecI[] cpts, int degree){
return ICurveCreator.curve(cpts,degree);
}
public static ICurve curve(IVecI[] cpts){
return ICurveCreator.curve(cpts);
}
public static ICurve curve(IVecI[] cpts, int degree, boolean close){
return ICurveCreator.curve(cpts,degree,close);
}
public static ICurve curve(IVecI[] cpts, boolean close){
return ICurveCreator.curve(cpts,close);
}
public static ICurve curve(IVecI pt1, IVecI pt2){
return ICurveCreator.curve(pt1,pt2);
}
/** this creates a line between a same point */
public static ICurve curve(IVecI pt){ return ICurveCreator.curve(pt); }
public static ICurve curve(double x1, double y1, double z1, double x2, double y2, double z2){
return ICurveCreator.curve(x1,y1,z1,x2,y2,z2);
}
public static ICurve curve(double[][] xyzValues){
return ICurveCreator.curve(xyzValues);
}
public static ICurve curve(double[][] xyzValues, int degree){
return ICurveCreator.curve(xyzValues,degree);
}
public static ICurve curve(double[][] xyzValues, boolean close){
return ICurveCreator.curve(xyzValues,close);
}
public static ICurve curve(double[][] xyzValues, int degree, boolean close){
return ICurveCreator.curve(xyzValues,degree,close);
}
public static ICurve curve(ICurveI crv){
return ICurveCreator.curve(crv);
}
/***********
* curve short name : crv
**********/
public static ICurve crv(IVecI[] cpts, int degree, double[] knots, double ustart, double uend){
return curve(cpts,degree,knots,ustart,uend);
}
public static ICurve crv(IVecI[] cpts, int degree, double[] knots){
return curve(cpts,degree,knots);
}
public static ICurve crv(IVecI[] cpts, int degree){
return curve(cpts,degree);
}
public static ICurve crv(IVecI[] cpts){ return curve(cpts); }
public static ICurve crv(IVecI[] cpts, int degree, boolean close){
return curve(cpts,degree,close);
}
public static ICurve crv(IVecI[] cpts, boolean close){
return curve(cpts,close);
}
public static ICurve crv(IVecI pt1, IVecI pt2){ return curve(pt1,pt2); }
/** this creates a line between a same point */
public static ICurve crv(IVecI pt){ return curve(pt); }
public static ICurve crv(double x1, double y1, double z1, double x2, double y2, double z2){
return curve(x1,y1,z1,x2,y2,z2);
}
public static ICurve crv(double[][] xyzValues){ return curve(xyzValues); }
public static ICurve crv(double[][] xyzValues, int degree){
return curve(xyzValues,degree);
}
public static ICurve crv(double[][] xyzValues, boolean close){
return curve(xyzValues,close);
}
public static ICurve crv(double[][] xyzValues, int degree, boolean close){
return curve(xyzValues,degree,close);
}
public static ICurve crv(ICurveI crv){ return curve(crv); }
/***********
* line : type of curve.
**********/
public static ICurve line(IVecI pt1, IVecI pt2){ return curve(pt1,pt2); }
/** this creates a line between a same point */
public static ICurve line(IVecI pt){ return curve(pt); }
public static ICurve line(double x1, double y1, double z1, double x2, double y2, double z2){
return curve(x1,y1,z1,x2,y2,z2);
}
/************
* rectangle
***********/
public static ICurve rect(IVecI corner, double xwidth, double yheight){
return ICurveCreator.rect(corner,xwidth,yheight);
}
public static ICurve rect(IVecI corner, IVecI width, IVecI height){
return ICurveCreator.rect(corner,width,height);
}
public static ICurve rect(double x, double y, double z, double xwidth, double yheight){
return ICurveCreator.rect(x,y,z,xwidth,yheight);
}
/************
* circle
***********/
public static ICircle circle(IVecI center, IVecI normal, IDoubleI radius){
return ICurveCreator.circle(center,normal,radius);
}
public static ICircle circle(IVecI center, IVecI normal, double radius){
return ICurveCreator.circle(center,normal,radius);
}
public static ICircle circle(IVecI center, IDoubleI radius){
return ICurveCreator.circle(center,radius);
}
public static ICircle circle(IVecI center, double radius){
return ICurveCreator.circle(center,radius);
}
public static ICircle circle(double x, double y, double z, double radius){
return ICurveCreator.circle(x,y,z,radius);
}
public static ICircle circle(IVecI center, IVecI normal, IDoubleI xradius, IDoubleI yradius){
return ICurveCreator.circle(center,normal,xradius,yradius);
}
public static ICircle circle(IVecI center, IVecI normal, double xradius, double yradius){
return ICurveCreator.circle(center,normal,xradius,yradius);
}
public static ICircle circle(IVecI center, IDoubleI xradius, IDoubleI yradius){
return ICurveCreator.circle(center,xradius,yradius);
}
public static ICircle circle(IVecI center, double xradius, double yradius){
return ICurveCreator.circle(center,xradius,yradius);
}
public static ICircle circle(double x, double y, double z, double xradius, double yradius){
return ICurveCreator.circle(x,y,z,xradius,yradius);
}
public static ICircle circle(IVecI center, IVecI normal, IVecI rollDir, double radius){
return ICurveCreator.circle(center,normal,rollDir,radius);
}
public static ICircle circle(IVecI center, IVecI normal, IVecI rollDir, IDoubleI radius){
return ICurveCreator.circle(center,normal,rollDir,radius);
}
public static ICircle circle(IVecI center, IVecI normal, IVecI rollDir, double xradius, double yradius){
return ICurveCreator.circle(center,normal,rollDir,xradius,yradius);
}
public static ICircle circle(IVecI center, IVecI normal, IVecI rollDir, IDoubleI xradius, IDoubleI yradius){
return ICurveCreator.circle(center,normal,rollDir,xradius,yradius);
}
public static ICircle circle(IVecI center, IVecI xradiusVec, IVecI yradiusVec){
return ICurveCreator.circle(center,xradiusVec,yradiusVec);
}
public static ICircle circle(IVecI center, IVecI normal, IDoubleI radius, boolean approx){
return ICurveCreator.circle(center,normal,radius,approx);
}
public static ICircle circle(IVecI center, IVecI normal, double radius, boolean approx){
return ICurveCreator.circle(center,normal,radius,approx);
}
public static ICircle circle(IVecI center, IDoubleI radius, boolean approx){
return ICurveCreator.circle(center,radius,approx);
}
public static ICircle circle(IVecI center, double radius, boolean approx){
return ICurveCreator.circle(center,radius,approx);
}
public static ICircle circle(double x, double y, double z, double radius, boolean approx){
return ICurveCreator.circle(x,y,z,radius,approx);
}
public static ICircle circle(IVecI center, IVecI normal, double xradius, double yradius, boolean approx){
return ICurveCreator.circle(center,normal,xradius,yradius,approx);
}
public static ICircle circle(IVecI center, IVecI normal, IDoubleI xradius, IDoubleI yradius, boolean approx){
return ICurveCreator.circle(center,normal,xradius,yradius,approx);
}
public static ICircle circle(IVecI center, double xradius, double yradius, boolean approx){
return ICurveCreator.circle(center,xradius,yradius,approx);
}
public static ICircle circle(IVecI center, IDoubleI xradius, IDoubleI yradius, boolean approx){
return ICurveCreator.circle(center,xradius,yradius,approx);
}
public static ICircle circle(double x, double y, double z, double xradius, double yradius, boolean approx){
return ICurveCreator.circle(x,y,z,xradius,yradius,approx);
}
public static ICircle circle(IVecI center, IVecI normal, IVecI rollDir, double radius, boolean approx){
return ICurveCreator.circle(center,normal,rollDir,radius,approx);
}
public static ICircle circle(IVecI center, IVecI normal, IVecI rollDir, IDoubleI radius, boolean approx){
return ICurveCreator.circle(center,normal,rollDir,radius,approx);
}
public static ICircle circle(IVecI center, IVecI normal, IVecI rollDir, double xradius, double yradius, boolean approx){
return ICurveCreator.circle(center,normal,rollDir,xradius,yradius,approx);
}
public static ICircle circle(IVecI center, IVecI normal, IVecI rollDir, IDoubleI xradius, IDoubleI yradius, boolean approx){
return ICurveCreator.circle(center,normal,rollDir,xradius,yradius,approx);
}
public static ICircle circle(IVecI center, IVecI xradiusVec, IVecI yradiusVec, boolean approx){
return ICurveCreator.circle(center,xradiusVec,yradiusVec,approx);
}
/************
* ellipse (alias of some of circle)
***********/
public static ICircle ellipse(IVecI center, IVecI xradiusVec, IVecI yradiusVec){
return ICurveCreator.ellipse(center,xradiusVec,yradiusVec);
}
public static ICircle ellipse(IVecI center, IDoubleI xradius, IDoubleI yradius){
return ICurveCreator.ellipse(center,xradius,yradius);
}
public static ICircle ellipse(IVecI center, double xradius, double yradius){
return ICurveCreator.ellipse(center,xradius,yradius);
}
public static ICircle ellipse(double x, double y, double z, double xradius, double yradius){
return ICurveCreator.ellipse(x,y,z,xradius,yradius);
}
/************
* arc
***********/
public static IArc arc(IVecI center, IVecI normal, IVecI startPt, double angle){
return ICurveCreator.arc(center,normal,startPt,angle);
}
public static IArc arc(IVecI center, IVecI normal, IVecI startPt, IDoubleI angle){
return ICurveCreator.arc(center,normal,startPt,angle);
}
public static IArc arc(IVecI center, IVecI startPt, double angle){
return ICurveCreator.arc(center,startPt,angle);
}
public static IArc arc(IVecI center, IVecI startPt, IDoubleI angle){
return ICurveCreator.arc(center,startPt,angle);
}
public static IArc arc(double x, double y, double z, double startX, double startY, double startZ, double angle){
return ICurveCreator.arc(x,y,z,startX,startY,startZ,angle);
}
public static IArc arc(IVecI center, IVecI startPt, IVecI endPt, IBoolI flipArcSide){
return ICurveCreator.arc(center,startPt,endPt,flipArcSide);
}
public static IArc arc(IVecI center, IVecI startPt, IVecI endPt, boolean flipArcSide){
return ICurveCreator.arc(center,startPt,endPt,flipArcSide);
}
public static IArc arc(IVecI center, IVecI startPt, IVecI midPt, IVecI endPt, IVecI normal){
return ICurveCreator.arc(center,startPt,midPt,endPt,normal);
}
/************
* offset curve
***********/
public static ICurve offset(ICurveI curve, double width, IVecI planeNormal){
return ICurveCreator.offset(curve,width,planeNormal);
}
public static ICurve offset(ICurveI curve, IDoubleI width, IVecI planeNormal){
return ICurveCreator.offset(curve,width,planeNormal);
}
public static ICurve offset(ICurveI curve, double width){
return ICurveCreator.offset(curve,width);
}
public static ICurve offset(ICurveI curve, IDoubleI width){
return ICurveCreator.offset(curve,width);
}
/**
offset points. normal direction is automatically detected.
*/
public static IVec[] offset(IVec[] pts, double width){
return IVec.offset(pts,width);
}
public static IVec[] offset(IVec[] pts, double width, boolean close){
return IVec.offset(pts,width,close);
}
public static IVecI[] offset(IVecI[] pts, double width){
return IVec.offset(pts,width);
}
public static IVecI[] offset(IVecI[] pts, double width, boolean close){
return IVec.offset(pts,width,close);
}
public static IVecI[] offset(IVecI[] pts, IDoubleI width){
return IVec.offset(pts,width);
}
public static IVecI[] offset(IVecI[] pts, IDoubleI width, boolean close){
return IVec.offset(pts,width,close);
}
/**
offset points with specific normal direction
*/
public static IVec[] offset(IVec[] pts, double width, IVecI planeNormal){
return IVec.offset(pts,width,planeNormal);
}
public static IVec[] offset(IVec[] pts, double width, IVecI planeNormal, boolean close){
return IVec.offset(pts,width,planeNormal,close);
}
public static IVecI[] offset(IVecI[] pts, double width, IVecI planeNormal){
return IVec.offset(pts,width,planeNormal);
}
public static IVecI[] offset(IVecI[] pts, double width, IVecI planeNormal, boolean close){
return IVec.offset(pts,width,planeNormal,close);
}
public static IVecI[] offset(IVecI[] pts, IDoubleI width, IVecI planeNormal){
return IVec.offset(pts,width,planeNormal);
}
public static IVecI[] offset(IVecI[] pts, IDoubleI width, IVecI planeNormal, boolean close){
return IVec.offset(pts,width,planeNormal,close);
}
/**
offset points with specific normal vector for each point
*/
public static IVec[] offset(IVec[] pts, double width, IVecI[] normals){
return IVec.offset(pts,width,normals);
}
public static IVec[] offset(IVec[] pts, double width, IVecI[] normals, boolean close){
return IVec.offset(pts,width,normals,close);
}
public static IVecI[] offset(IVecI[] pts, double width, IVecI[] normals){
return IVec.offset(pts,width,normals);
}
public static IVecI[] offset(IVecI[] pts, double width, IVecI[] normals, boolean close){
return IVec.offset(pts,width,normals,close);
}
public static IVecI[] offset(IVecI[] pts, IDoubleI width, IVecI[] normals){
return IVec.offset(pts, width, normals);
}
public static IVecI[] offset(IVecI[] pts, IDoubleI width, IVecI[] normals, boolean close){
return IVec.offset(pts, width, normals, close);
}
/*****************************************************************
* surfaces
*****************************************************************/
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
double[] uknots, double[] vknots,
double ustart, double uend, double vstart, double vend){
return ISurfaceCreator.surface(cpts,udegree,vdegree,uknots,vknots,
ustart,uend,vstart,vend);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
double[] uknots, double[] vknots){
return ISurfaceCreator.surface(cpts,udegree,vdegree,uknots,vknots);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree){
return ISurfaceCreator.surface(cpts,udegree,vdegree);
}
public static ISurface surface(IVecI[][] cpts){
return ISurfaceCreator.surface(cpts);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
boolean closeU, boolean closeV){
return ISurfaceCreator.surface(cpts,udegree,vdegree,closeU,closeV);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
boolean closeU, double[] vk){
return ISurfaceCreator.surface(cpts,udegree,vdegree,closeU,vk);
}
public static ISurface surface(IVecI[][] cpts, int udegree, int vdegree,
double[] uk, boolean closeV){
return ISurfaceCreator.surface(cpts,udegree,vdegree,uk,closeV);
}
public static ISurface surface(IVecI[][] cpts, boolean closeU, boolean closeV){
return ISurfaceCreator.surface(cpts,closeU,closeV);
}
public static ISurface surface(IVecI pt1, IVecI pt2, IVecI pt3, IVecI pt4){
return ISurfaceCreator.surface(pt1,pt2,pt3,pt4);
}
public static ISurface surface(IVecI pt1, IVecI pt2, IVecI pt3){
return ISurfaceCreator.surface(pt1,pt2,pt3);
}
public static ISurface surface(double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3,
double x4, double y4, double z4){
return ISurfaceCreator.surface(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4);
}
public static ISurface surface(double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3){
return ISurfaceCreator.surface(x1,y1,z1,x2,y2,z2,x3,y3,z3);
}
public static ISurface surface(double[][][] xyzValues){
return ISurfaceCreator.surface(xyzValues);
}
public static ISurface surface(double[][][] xyzValues, int udeg, int vdeg){
return ISurfaceCreator.surface(xyzValues,udeg,vdeg);
}
public static ISurface surface(double[][][] xyzValues, boolean closeU, boolean closeV){
return ISurfaceCreator.surface(xyzValues,closeU,closeV);
}
public static ISurface surface(double[][][] xyzValues, int udeg, int vdeg, boolean closeU, boolean closeV){
return ISurfaceCreator.surface(xyzValues,udeg,vdeg,closeU,closeV);
}
public static ISurface surface(ISurfaceI srf){
return ISurfaceCreator.surface(srf);
}
// planar surface with trim
public static ISurface surface(ICurveI trimCurve){
return ISurfaceCreator.surface(trimCurve);
}
public static ISurface surface(ICurveI outerTrimCurve, ICurveI[] innerTrimCurves){
return ISurfaceCreator.surface(outerTrimCurve, innerTrimCurves);
}
public static ISurface surface(ICurveI outerTrimCurve, ICurveI innerTrimCurve){
return ISurfaceCreator.surface(outerTrimCurve, innerTrimCurve);
}
public static ISurface surface(ICurveI[] trimCurves){
return ISurfaceCreator.surface(trimCurves);
}
public static ISurface surface(IVecI[] trimCrvPts){
return ISurfaceCreator.surface(trimCrvPts);
}
public static ISurface surface(IVecI[] trimCrvPts, int trimCrvDeg){
return ISurfaceCreator.surface(trimCrvPts,trimCrvDeg);
}
public static ISurface surface(IVecI[] trimCrvPts, int trimCrvDeg, double[] trimCrvKnots){
return ISurfaceCreator.surface(trimCrvPts,trimCrvDeg,trimCrvKnots);
}
/*****************************************************************
* srf : short name of surfaces
*****************************************************************/
public static ISurface srf(IVecI[][] cpts, int udegree, int vdegree,
double[] uknots, double[] vknots,
double ustart, double uend, double vstart, double vend){
return surface(cpts,udegree,vdegree,uknots,vknots,ustart,uend,vstart,vend);
}
public static ISurface srf(IVecI[][] cpts, int udegree, int vdegree,
double[] uknots, double[] vknots){
return surface(cpts,udegree,vdegree,uknots,vknots);
}
public static ISurface srf(IVecI[][] cpts, int udegree, int vdegree){
return surface(cpts,udegree,vdegree);
}
public static ISurface srf(IVecI[][] cpts){ return surface(cpts); }
public static ISurface srf(IVecI[][] cpts, int udegree, int vdegree,
boolean closeU, boolean closeV){
return surface(cpts,udegree,vdegree,closeU,closeV);
}
public static ISurface srf(IVecI[][] cpts, int udegree, int vdegree,
boolean closeU, double[] vk){
return surface(cpts,udegree,vdegree,closeU,vk);
}
public static ISurface srf(IVecI[][] cpts, int udegree, int vdegree,
double[] uk, boolean closeV){
return surface(cpts,udegree,vdegree,uk,closeV);
}
public static ISurface srf(IVecI[][] cpts, boolean closeU, boolean closeV){
return surface(cpts,closeU,closeV);
}
public static ISurface srf(IVecI pt1, IVecI pt2, IVecI pt3, IVecI pt4){
return surface(pt1,pt2,pt3,pt4);
}
public static ISurface srf(IVecI pt1, IVecI pt2, IVecI pt3){
return surface(pt1,pt2,pt3);
}
public static ISurface srf(double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3,
double x4, double y4, double z4){
return surface(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4);
}
public static ISurface srf(double x1, double y1, double z1,
double x2, double y2, double z2,
double x3, double y3, double z3){
return surface(x1,y1,z1,x2,y2,z2,x3,y3,z3);
}
public static ISurface srf(double[][][] xyzValues){ return surface(xyzValues); }
public static ISurface srf(double[][][] xyzValues, int udeg, int vdeg){
return surface(xyzValues,udeg,vdeg);
}
public static ISurface srf(double[][][] xyzValues, boolean closeU, boolean closeV){
return surface(xyzValues,closeU,closeV);
}
public static ISurface srf(double[][][] xyzValues, int udeg, int vdeg, boolean closeU, boolean closeV){
return surface(xyzValues,udeg,vdeg,closeU,closeV);
}
public static ISurface srf(ISurfaceI srf){ return surface(srf); }
/** planar surface with trim */
public static ISurface srf(ICurveI trimCurve){ return surface(trimCurve); }
public static ISurface srf(ICurveI outerTrimCurve, ICurveI[] innerTrimCurves){
return surface(outerTrimCurve, innerTrimCurves);
}
public static ISurface srf(ICurveI outerTrimCurve, ICurveI innerTrimCurve){
return surface(outerTrimCurve, innerTrimCurve);
}
public static ISurface srf(ICurveI[] trimCurves){ return surface(trimCurves); }
public static ISurface srf(IVecI[] trimCrvPts){ return surface(trimCrvPts); }
public static ISurface srf(IVecI[] trimCrvPts, int trimCrvDeg){
return surface(trimCrvPts,trimCrvDeg);
}
public static ISurface srf(IVecI[] trimCrvPts, int trimCrvDeg, double[] trimCrvKnots){
return surface(trimCrvPts,trimCrvDeg,trimCrvKnots);
}
/*****************************************************************
* box
*****************************************************************/
public static IBox box(double x, double y, double z, double size){
return ISurfaceCreator.box(x,y,z,size);
}
public static IBox box(double x, double y, double z, double width, double height, double depth){
return ISurfaceCreator.box(x,y,z,width,height,depth);
}
public static IBox box(IVecI origin, double size){ return ISurfaceCreator.box(origin,size); }
public static IBox box(IVecI origin, double width, double height, double depth){
return ISurfaceCreator.box(origin,width,height,depth);
}
public static IBox box(IVecI origin, IVecI xvec, IVecI yvec, IVecI zvec){
return ISurfaceCreator.box(origin,xvec,yvec,zvec);
}
public static IBox box(IVecI pt1, IVecI pt2, IVecI pt3, IVecI pt4,
IVecI pt5, IVecI pt6, IVecI pt7, IVecI pt8 ){
return ISurfaceCreator.box(pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8);
}
public static IBox box(IVecI[][][] corners){ return ISurfaceCreator.box(corners); }
/*****************************************************************
* sphere
*****************************************************************/
public static ISphere sphere(double x, double y, double z, double radius){
return ISurfaceCreator.sphere(x,y,z,radius);
}
public static ISphere sphere(IVecI center, double radius){
return ISurfaceCreator.sphere(center,radius);
}
public static ISphere sphere(IVecI center, IDoubleI radius){
return ISurfaceCreator.sphere(center,radius);
}
public static ICylinder cylinder(IVecI pt1, IVecI pt2, double radius){
return ISurfaceCreator.cylinder(pt1,pt2,radius);
}
public static ICylinder cylinder(IVecI pt1, IVecI pt2, IDoubleI radius){
return ISurfaceCreator.cylinder(pt1,pt2,radius);
}
public static ICylinder cylinder(IVecI pt1, IVecI pt2, double radius1, double radius2){
return ISurfaceCreator.cylinder(pt1,pt2,radius1,radius2);
}
public static ICylinder cylinder(IVecI pt1, IVecI pt2, IDoubleI radius1, IDoubleI radius2){
return ISurfaceCreator.cylinder(pt1,pt2,radius1,radius2);
}
public static ICylinder cone(IVecI pt1, IVecI pt2, double radius){
return ISurfaceCreator.cone(pt1,pt2,radius);
}
public static ICylinder cone(IVecI pt1, IVecI pt2, IDoubleI radius){
return ISurfaceCreator.cone(pt1,pt2,radius);
}
public static ISurface plane(IVecI corner, double xwidth, double yheight){
return ISurfaceCreator.plane(corner,xwidth,yheight);
}
public static ISurface plane(IVecI corner, IVecI widthVec, IVecI heightVec){
return ISurfaceCreator.plane(corner,widthVec,heightVec);
}
public static ISurface plane(double x, double y, double z, double xwidth, double yheight){
return ISurfaceCreator.plane(new IVec(x,y,z),xwidth,yheight);
}
/** one directional extrusion */
public static ISurface extrude(IVecI[] profile, double extrudeDepth){
return ISurfaceCreator.extrude(profile,extrudeDepth);
}
public static ISurface extrude(IVecI[] profile, IDoubleI extrudeDepth){
return ISurfaceCreator.extrude(profile,extrudeDepth);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, double extrudeDepth){
return ISurfaceCreator.extrude(profile,profileDeg,extrudeDepth);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, IDoubleI extrudeDepth){
return ISurfaceCreator.extrude(profile,profileDeg,extrudeDepth);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile, double extrudeDepth){
return ISurfaceCreator.extrude(profile,profileDeg,closeProfile,extrudeDepth);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile, IDoubleI extrudeDepth){
return ISurfaceCreator.extrude(profile,profileDeg,closeProfile,extrudeDepth);
}
public static ISurface extrude(IVecI[] profile, IVecI extrudeDir){
return ISurfaceCreator.extrude(profile,extrudeDir);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, IVecI extrudeDir){
return ISurfaceCreator.extrude(profile,profileDeg,extrudeDir);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile, IVecI extrudeDir){
return ISurfaceCreator.extrude(profile,profileDeg,closeProfile,extrudeDir);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI extrudeDir){
return ISurfaceCreator.extrude(profile,profileDeg,profileKnots,extrudeDir);
}
public static ISurface extrude(IVecI[] profile, ICurve rail){
return ISurfaceCreator.extrude(profile,rail);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, ICurve rail){
return ISurfaceCreator.extrude(profile,profileDeg,rail);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile,
ICurve rail){
return ISurfaceCreator.extrude(profile,profileDeg,closeProfile,rail);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, double[] profileKnots,
ICurve rail){
return ISurfaceCreator.extrude(profile,profileDeg,profileKnots,rail);
}
public static ISurface extrude(ICurveI profile, IVecI extrudeDir){
return ISurfaceCreator.extrude(profile,extrudeDir);
}
public static ISurface extrude(ICurveI profile, double extrudeDepth){
return ISurfaceCreator.extrude(profile,extrudeDepth);
}
public static ISurface extrude(ICurveI profile, IDoubleI extrudeDepth){
return ISurfaceCreator.extrude(profile,extrudeDepth);
}
/** extrusion along path (profile control points are copied parallely) */
public static ISurface extrude(IVecI[] profile, IVecI[] rail){
return ISurfaceCreator.extrude(profile,rail);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, IVecI[] rail, int railDeg){
return ISurfaceCreator.extrude(profile,profileDeg,rail,railDeg);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI[] rail, int railDeg, boolean closeRail){
return ISurfaceCreator.extrude(profile,profileDeg,closeProfile,
rail,railDeg,closeRail);
}
public static ISurface extrude(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI[] rail, int railDeg, double[] railKnots){
return ISurfaceCreator.extrude(profile,profileDeg,profileKnots,
rail,railDeg,railKnots);
}
public static ISurface extrude(ICurveI profile, ICurveI rail){
return ISurfaceCreator.extrude(profile,rail);
}
/** sweep (profile is redirected perpendicular to rail and centered(actually just on bisector of control points)) */
public static ISurface sweep(IVecI[] profile, IVecI[] rail){
return ISurfaceCreator.sweep(profile,rail);
}
public static ISurface sweep(IVecI[] profile, IVecI profileCenter, IVecI[] rail){
return ISurfaceCreator.sweep(profile,profileCenter,rail);
}
public static ISurface sweep(IVecI[] profile, IVecI profileCenter, IVecI profileDir, IVecI[] rail){
return ISurfaceCreator.sweep(profile,profileCenter,profileDir,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, IVecI[] rail, int railDeg){
return ISurfaceCreator.sweep(profile,profileDeg,rail,railDeg);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, IVecI profileCenter,
IVecI[] rail, int railDeg){
return ISurfaceCreator.sweep(profile,profileDeg,profileCenter,
rail,railDeg);
}
public static ISurface sweep(IVecI[] profile, int profileDeg,
IVecI profileCenter, IVecI profileDir,
IVecI[] rail, int railDeg){
return ISurfaceCreator.sweep(profile,profileDeg,profileCenter,profileDir,
rail,railDeg);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI[] rail, int railDeg, boolean closeRail){
return ISurfaceCreator.sweep(profile,profileDeg,closeProfile,
rail,railDeg,closeRail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI profileCenter,
IVecI[] rail, int railDeg, boolean closeRail){
return ISurfaceCreator.sweep(profile,profileDeg,closeProfile,
profileCenter,
rail,railDeg,closeRail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI profileCenter, IVecI profileDir,
IVecI[] rail, int railDeg, boolean closeRail){
return ISurfaceCreator.sweep(profile,profileDeg,closeProfile,
profileCenter, profileDir,
rail,railDeg,closeRail);
}
public static ISurface sweep(IVecI[] profile, ICurveI rail){
return ISurfaceCreator.sweep(profile,rail);
}
public static ISurface sweep(IVecI[] profile, IVecI profileCenter, ICurveI rail){
return ISurfaceCreator.sweep(profile,profileCenter,rail);
}
public static ISurface sweep(IVecI[] profile, IVecI profileCenter, IVecI profileDir,
ICurveI rail){
return ISurfaceCreator.sweep(profile,profileCenter,profileDir,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, ICurveI rail){
return ISurfaceCreator.sweep(profile,profileDeg,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, IVecI profileCenter,
ICurveI rail){
return ISurfaceCreator.sweep(profile,profileDeg,profileCenter,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg,
IVecI profileCenter, IVecI profileDir, ICurveI rail){
return ISurfaceCreator.sweep(profile,profileDeg,profileCenter,profileDir,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile, ICurveI rail){
return ISurfaceCreator.sweep(profile,profileDeg,closeProfile,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI profileCenter, ICurveI rail){
return ISurfaceCreator.sweep(profile,profileDeg,closeProfile,profileCenter,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, boolean closeProfile,
IVecI profileCenter, IVecI profileDir, ICurveI rail){
return ISurfaceCreator.sweep(profile,profileDeg,closeProfile,
profileCenter,profileDir,rail);
}
public static ISurface sweep(ICurveI profile, IVecI[] rail){
return ISurfaceCreator.sweep(profile,rail);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI[] rail){
return ISurfaceCreator.sweep(profile,profileCenter,rail);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI profileDir, IVecI[] rail){
return ISurfaceCreator.sweep(profile,profileCenter,profileDir,rail);
}
public static ISurface sweep(ICurveI profile, IVecI[] rail, int railDeg){
return ISurfaceCreator.sweep(profile,rail,railDeg);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI[] rail,int railDeg){
return ISurfaceCreator.sweep(profile,profileCenter,rail,railDeg);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI profileDir,
IVecI[] rail,int railDeg){
return ISurfaceCreator.sweep(profile,profileCenter,profileDir,rail,railDeg);
}
public static ISurface sweep(ICurveI profile, IVecI[] rail, int railDeg, boolean closeRail){
return ISurfaceCreator.sweep(profile,rail,railDeg,closeRail);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter,
IVecI[] rail, int railDeg, boolean closeRail){
return ISurfaceCreator.sweep(profile,profileCenter,rail,railDeg,closeRail);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, IVecI profileDir,
IVecI[] rail, int railDeg, boolean closeRail){
return ISurfaceCreator.sweep(profile,profileCenter,profileDir,rail,railDeg,closeRail);
}
public static ISurface sweep(ICurveI profile, ICurveI rail){
return ISurfaceCreator.sweep(profile,rail);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter, ICurveI rail){
return ISurfaceCreator.sweep(profile,profileCenter,rail);
}
public static ISurface sweep(ICurveI profile, IVecI profileCenter,
IVecI profileDir, ICurveI rail){
return ISurfaceCreator.sweep(profile,profileCenter,profileDir,rail);
}
public static ISurface sweep(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI[] rail, int railDeg, double[] railKnots){
return ISurfaceCreator.sweep(profile,profileDeg,profileKnots,
rail,railDeg,railKnots);
}
/**
sweep.
@param profileCenter point on profile to be located at the points of rail
*/
public static ISurface sweep(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI profileCenter,
IVecI[] rail, int railDeg, double[] railKnots){
return ISurfaceCreator.sweep(profile,profileDeg,profileKnots,
profileCenter,
rail,railDeg,railKnots);
}
/**
sweep.
@param profileCenter point on profile to be located at the points of rail
@param profileDir direction on profile to be aligned with the normal of rail
*/
public static ISurface sweep(IVecI[] profile, int profileDeg, double[] profileKnots,
IVecI profileCenter, IVecI profileDir,
IVecI[] rail, int railDeg, double[] railKnots){
return ISurfaceCreator.sweep(profile,profileDeg,profileKnots,
profileCenter, profileDir,
rail,railDeg,railKnots);
}
/*********************
* pipe
*********************/
public static ISurface pipe(IVecI pt1, IVecI pt2, double radius){
return ISurfaceCreator.pipe(pt1,pt2,radius);
}
public static ISurface pipe(IVecI[] rail, double radius){
return ISurfaceCreator.pipe(rail,radius);
}
public static ISurface pipe(IVecI[] rail, int railDeg, double radius){
return ISurfaceCreator.pipe(rail,railDeg,radius);
}
public static ISurface pipe(IVecI[] rail, int railDeg, boolean close, double radius){
return ISurfaceCreator.pipe(rail,railDeg,close,radius);
}
public static ISurface pipe(ICurveI rail, double radius){
return ISurfaceCreator.pipe(rail,radius);
}
public static ISurface pipe(IVecI[] rail, int railDeg, double[] railKnots, double radius){
return ISurfaceCreator.pipe(rail,railDeg,railKnots,radius);
}
/* make an open-ended square pipe surface */
public static ISurface squarePipe(IVecI pt1, IVecI pt2, double size){
return ISurfaceCreator.squarePipe(pt1,pt2,size);
}
/* make an open-ended square pipe surface with width dir specified*/
public static ISurface squarePipe(IVecI pt1, IVecI pt2, IVecI widthDir, double size){
return ISurfaceCreator.squarePipe(pt1,pt2,widthDir,size);
}
public static ISurface squarePipe(IVecI[] rail, double size){
return ISurfaceCreator.squarePipe(rail,size);
}
public static ISurface squarePipe(IVecI[] rail, int deg, double size){
return ISurfaceCreator.squarePipe(rail,deg,size);
}
public static ISurface squarePipe(IVecI[] rail, int deg, boolean close, double size){
return ISurfaceCreator.squarePipe(rail,deg,close,size);
}
public static ISurface squarePipe(ICurveI rail, double size){
return ISurfaceCreator.squarePipe(rail,size);
}
public static ISurface squarePipe(IVecI[] rail, int deg, double[] knots, double size){
return ISurfaceCreator.squarePipe(rail,deg,knots,size);
}
/**
@param width size in the direction of offset of rail
@param height size in the direction of normal of rail
*/
public static ISurface rectPipe(IVecI pt1, IVecI pt2, double width, double height){
return ISurfaceCreator.rectPipe(pt1,pt2,width,height);
}
/* make an open-ended rectangular pipe surface with width dir specified*/
public static ISurface rectPipe(IVecI pt1, IVecI pt2, IVecI widthDir, double width, double height){
return ISurfaceCreator.rectPipe(pt1,pt2,widthDir,width,height);
}
public static ISurface rectPipe(IVecI pt1, IVecI pt2, double left, double right, double bottom, double top){
return ISurfaceCreator.rectPipe(pt1,pt2,left,right,bottom,top);
}
/* make an open-ended rectangular pipe surface with width dir specified*/
public static ISurface rectPipe(IVecI pt1, IVecI pt2, IVecI widthDir, double left, double right, double bottom, double top){
return ISurfaceCreator.rectPipe(pt1,pt2,widthDir,left,right,bottom,top);
}
public static ISurface rectPipe(IVecI[] rail, double width, double height){
return ISurfaceCreator.rectPipe(rail,width,height);
}
public static ISurface rectPipe(IVecI[] rail, double left, double right, double bottom, double top){
return ISurfaceCreator.rectPipe(rail,left,right,bottom,top);
}
public static ISurface rectPipe(IVecI[] rail, int deg, double width, double height){
return ISurfaceCreator.rectPipe(rail,deg,width,height);
}
public static ISurface rectPipe(IVecI[] rail, int deg,
double left, double right, double bottom, double top){
return ISurfaceCreator.rectPipe(rail,deg,left,right,bottom,top);
}
public static ISurface rectPipe(IVecI[] rail, int deg, boolean close, double width, double height){
return ISurfaceCreator.rectPipe(rail,deg,close,width,height);
}
public static ISurface rectPipe(IVecI[] rail, int deg, boolean close,
double left, double right, double bottom, double top){
return ISurfaceCreator.rectPipe(rail,deg,close,left,right,bottom,top);
}
public static ISurface rectPipe(ICurveI rail, double width, double height){
return ISurfaceCreator.rectPipe(rail,width,height);
}
public static ISurface rectPipe(ICurveI rail,
double left, double right, double bottom, double top){
return ISurfaceCreator.rectPipe(rail,left,right,bottom,top);
}
public static ISurface rectPipe(IVecI[] rail, int deg, double[] knots, double width, double height){
return ISurfaceCreator.rectPipe(rail,deg,knots,width,height);
}
public static ISurface rectPipe(IVecI[] rail, int deg, double[] knots,
double left, double right, double bottom, double top){
return ISurfaceCreator.rectPipe(rail,deg,knots,left,right,bottom,top);
}
/*********************
* loft
*********************/
public static ISurface loft(ICurveI[] curves){
return ISurfaceCreator.loft(curves);
}
public static ISurface loft(ICurveI curve1, ICurveI curve2 ){
return ISurfaceCreator.loft(curve1,curve2);
}
public static ISurface loft(ICurveI[] curves, int deg){
return ISurfaceCreator.loft(curves,deg);
}
public static ISurface loft(ICurveI[] curves, int deg, boolean close){
return ISurfaceCreator.loft(curves,deg,close);
}
public static ISurface loft(IVecI[][] pts){
return ISurfaceCreator.loft(pts);
}
public static ISurface loft(IVecI[][] pts, boolean closeLoft, boolean closePts){
return ISurfaceCreator.loft(pts,closeLoft,closePts);
}
public static ISurface loft(IVecI[][] pts, int loftDeg, int ptsDeg){
return ISurfaceCreator.loft(pts,loftDeg,ptsDeg);
}
public static ISurface loft(IVecI[][] pts, int loftDeg, int ptsDeg,
boolean closeLoft, boolean closePts){
return ISurfaceCreator.loft(pts,loftDeg,ptsDeg,closeLoft,closePts);
}
public static ISurface loft(IVecI[] pts1, IVecI[] pts2){
return ISurfaceCreator.loft(pts1,pts2);
}
public static ISurface loft(IVecI[] pts1, IVecI[] pts2, boolean closePts){
return ISurfaceCreator.loft(pts1,pts2,closePts);
}
public static ISurface loft(IVecI[] pts1, IVecI[] pts2, int ptsDeg){
return ISurfaceCreator.loft(pts1,pts2,ptsDeg);
}
public static ISurface loft(IVecI[] pts1, IVecI[] pts2, int ptsDeg, boolean closePts){
return ISurfaceCreator.loft(pts1,pts2,ptsDeg,closePts);
}
public static ISurface loft(IVecI[] pts1, IVecI[] pts2, IVecI[] pts3){
return ISurfaceCreator.loft(pts1,pts2,pts3);
}
public static ISurface loft(IVecI[] pts1, IVecI[] pts2, IVecI[] pts3,
boolean closePts){
return ISurfaceCreator.loft(pts1,pts2,pts3,closePts);
}
public static ISurface loft(IVecI[] pts1, IVecI[] pts2, IVecI[] pts3, int loftDeg, int ptsDeg){
return ISurfaceCreator.loft(pts1,pts2,pts3,loftDeg,ptsDeg);
}
public static ISurface loft(IVecI[] pts1, IVecI[] pts2, IVecI[] pts3, int loftDeg, int ptsDeg, boolean closePts){
return ISurfaceCreator.loft(pts1,pts2,pts3,loftDeg,ptsDeg,closePts);
}
/** loft with sorted curves in x */
public static ISurface loftX(ICurveI[] curves){
return ISurfaceCreator.loftX(curves);
}
public static ISurface loftX(ICurveI[] curves, int deg){
return ISurfaceCreator.loftX(curves,deg);
}
public static ISurface loftX(ICurveI[] curves, int deg, boolean close){
return ISurfaceCreator.loftX(curves,deg,close);
}
/** loft with sorted curves in y */
public static ISurface loftY(ICurveI[] curves){
return ISurfaceCreator.loftY(curves);
}
public static ISurface loftY(ICurveI[] curves, int deg){
return ISurfaceCreator.loftY(curves,deg);
}
public static ISurface loftY(ICurveI[] curves, int deg, boolean close){
return ISurfaceCreator.loftY(curves,deg,close);
}
/** loft with sorted curves in z */
public static ISurface loftZ(ICurveI[] curves){
return ISurfaceCreator.loftZ(curves);
}
public static ISurface loftZ(ICurveI[] curves, int deg){
return ISurfaceCreator.loftZ(curves,deg);
}
public static ISurface loftZ(ICurveI[] curves, int deg, boolean close){
return ISurfaceCreator.loftZ(curves,deg,close);
}
/*********************************************************
* flattening
********************************************************/
public static ICurve flatten(ICurveI curve, IVecI planeDir, IVecI planePt){
return ICurveCreator.flatten(curve,planeDir,planePt);
}
public static ICurve flatten(ICurveI curve, IVecI planeDir){
return ICurveCreator.flatten(curve,planeDir);
}
public static ICurve flatten(ICurveI curve){ return ICurveCreator.flatten(curve); }
public static ISurface flatten(ISurfaceI surface, IVecI planeDir, IVecI planePt){
return ISurfaceCreator.flatten(surface,planeDir,planePt);
}
public static ISurface flatten(ISurfaceI surface, IVecI planeDir){
return ISurfaceCreator.flatten(surface,planeDir);
}
public static ISurface flatten(ISurfaceI surface){ return ISurfaceCreator.flatten(surface); }
/** cap a surface which is cyclically closed in u or v direction. */
public static IBrep cap(ISurfaceI surface){ return ISurfaceCreator.cap(surface); }
/** surface defined by closed profile.if the profile is flat, planar surface is created.
if not lofting profile into the center of the profile
*/
public static ISurface profileSurface(IVecI[] cps, int deg, double[] knots){
return ISurfaceCreator.profileSurface(cps,deg,knots);
}
/**
surface defined by closed profile.if the profile is flat, planar surface is created.
if not lofting profile into the center of the profile
*/
public static ISurface profileSurface(ICurveI profile){
return ISurfaceCreator.profileSurface(profile);
}
/**
surface by lofting profile into the center of the profile
*/
public static ISurface radialSurface(IVecI[] cps, int deg, double[] knots){
return ISurfaceCreator.radialSurface(cps,deg,knots);
}
/**
surface by lofting profile into the center of the profile
*/
public static ISurface radialSurface(ICurveI profile){
return ISurfaceCreator.radialSurface(profile);
}
/**
surface by lofting profile into the specified point
*/
public static ISurface pointLoft(IVecI[] cps, int deg, double[] knots, IVecI center){
return ISurfaceCreator.pointLoft(cps,deg,knots,center);
}
/**
surface by lofting profile into the specified point
*/
public static ISurface pointLoft(ICurveI profile, IVecI center){
return ISurfaceCreator.pointLoft(profile,center);
}
/*********************************************************
* creating mesh
********************************************************/
/** set mesh type (class of vertex, edge, face) */
public static void meshType(IMeshType type){ IMeshCreator.meshType(type); }
/** get the current mesh type (class of vertex, edge, face) */
public static IMeshType meshType(){ return IMeshCreator.meshType(); }
public static IMesh mesh(){ return IMeshCreator.mesh(); }
public static IMesh mesh(IMeshGeo m){ return IMeshCreator.mesh(m); }
public static IMesh mesh(IMesh m){ return IMeshCreator.mesh(m); }
public static IMesh mesh(ArrayList<ICurveI> lines){ return IMeshCreator.mesh(lines); }
public static IMesh mesh(ICurveI[] lines){ return IMeshCreator.mesh(lines); }
public static IMesh mesh(IVec[][] matrix){ return IMeshCreator.mesh(matrix); }
public static IMesh mesh(IVec[][] matrix, boolean triangulateDir){
return IMeshCreator.mesh(matrix,triangulateDir);
}
public static IMesh mesh(IVec[][] matrix, int unum, int vnum, boolean triangulateDir){
return IMeshCreator.mesh(matrix,triangulateDir);
}
public static IMesh mesh(ArrayList<IVertex> v, ArrayList<IEdge> e, ArrayList<IFace> f){
return IMeshCreator.mesh(v,e,f);
}
public static IMesh mesh(IVertex[] vtx, IEdge[] edg,IFace[] fcs){
return IMeshCreator.mesh(vtx,edg,fcs);
}
public static IMesh mesh(IVec[] vert){ return IMeshCreator.mesh(vert); }
public static IMesh mesh(IVertex[] vert){ return IMeshCreator.mesh(vert); }
public static IMesh mesh(IVertex v1, IVertex v2, IVertex v3){ return IMeshCreator.mesh(v1,v2,v3); }
public static IMesh mesh(IVertex v1, IVertex v2, IVertex v3, IVertex v4){
return IMeshCreator.mesh(v1,v2,v3,v4);
}
public static IMesh mesh(IVecI v1, IVecI v2, IVecI v3){ return IMeshCreator.mesh(v1,v2,v3); }
public static IMesh mesh(IVecI v1, IVecI v2, IVecI v3, IVecI v4){
return IMeshCreator.mesh(v1,v2,v3,v4);
}
public static IMesh mesh(double x1, double y1, double z1, double x2, double y2, double z2,
double x3, double y3, double z3){
return IMeshCreator.mesh(x1,y1,z1,x2,y2,z2,x3,y3,z3);
}
public static IMesh mesh(double x1, double y1, double z1, double x2, double y2, double z2,
double x3, double y3, double z3, double x4, double y4, double z4){
return IMeshCreator.mesh(x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4);
}
public static IMesh mesh(IFace[] fcs){ return IMeshCreator.mesh(fcs); }
/** create polygon mesh out of array of triangle points which is array of 3 IVec */
public static IMesh meshFromTriangles(IVecI[][] trianglePts){
return IMeshCreator.meshFromTriangles(trianglePts);
}
/*********************************************************
* creating solid mesh
********************************************************/
/*********************************************************
* creating mesh box
********************************************************/
public static IMesh meshBox(double x, double y, double z, double size){
return IMeshCreator.box(x,y,z,size);
}
public static IMesh meshBox(double x, double y, double z, double width, double height, double depth){
return IMeshCreator.box(x,y,z,width,height,depth);
}
public static IMesh meshBox(IVecI origin, double size){ return IMeshCreator.box(origin,size); }
public static IMesh meshBox(IVecI origin, double width, double height, double depth){
return IMeshCreator.box(origin,width,height,depth);
}
public static IMesh meshBox(IVecI origin, IVecI xvec, IVecI yvec, IVecI zvec){
return IMeshCreator.box(origin,xvec,yvec,zvec);
}
public static IMesh meshBox(IVecI pt1, IVecI pt2, IVecI pt3, IVecI pt4,
IVecI pt5, IVecI pt6, IVecI pt7, IVecI pt8 ){
return IMeshCreator.box(pt1,pt2,pt3,pt4,pt5,pt6,pt7,pt8);
}
public static IMesh meshBox(IVecI[][][] corners){ return IMeshCreator.box(corners); }
public static IMesh meshBox(IVertex[][][] corners){ return IMeshCreator.box(corners); }
public static IMesh meshTetrahedron(IVecI v1, IVecI v2, IVecI v3, IVecI v4){ return IMeshCreator.tetrahedron(v1,v2,v3,v4); }
public static IMesh meshTetrahedron(IVecI[] vtx){ return IMeshCreator.tetrahedron(vtx); }
public static IMesh meshTetrahedron(IVertex v1, IVertex v2, IVertex v3, IVertex v4){ return IMeshCreator.tetrahedron(v1,v2,v3,v4); }
public static IMesh meshTetrahedron(IVertex[] vtx){ return IMeshCreator.tetrahedron(vtx); }
/** mesh sphere
@param topDir length of vector is radius in vertical direction
@param sideDir length of vector is radius in holizontal direction. sideDir is re-orthogonalized to topDir
*/
public static IMesh meshSphere(IVecI center, IVecI topDir, IVecI sideDir, int resolution){
return IMeshCreator.sphere(center,topDir,sideDir,resolution);
}
/** mesh sphere
@param topDir length of vector is radius in vertical direction
@param sideDir length of vector is radius in holizontal direction. sideDir is re-orthogonalized to topDir
*/
public static IMesh meshSphere(IVecI center, IVecI topDir, IVecI sideDir){
return IMeshCreator.sphere(center,topDir,sideDir);
}
/** mesh sphere
@param topDir length of vector is radius in vertical direction
*/
public static IMesh meshSphere(IVecI center, IVecI topDir, int resolution){
return IMeshCreator.sphere(center,topDir,resolution);
}
/** mesh sphere
@param topDir length of vector is radius in vertical direction
*/
public static IMesh meshSphere(IVecI center, IVecI topDir){
return IMeshCreator.sphere(center,topDir);
}
/** mesh sphere */
public static IMesh meshSphere(IVecI center, IVecI topDir, double radius, int resolution){
return IMeshCreator.sphere(center,topDir,radius,resolution);
}
/** mesh sphere */
public static IMesh meshSphere(IVecI center, IVecI topDir, double topRadius, double sideRadius, int resolution){
return IMeshCreator.sphere(center,topDir,topRadius,sideRadius,resolution);
}
/** mesh sphere */
public static IMesh meshSphere(IVecI center, IVecI topDir, double radius){
return IMeshCreator.sphere(center,topDir,radius);
}
/** mesh sphere */
public static IMesh meshSphere(IVecI center, IVecI topDir, double topRadius, double sideRadius){
return IMeshCreator.sphere(center,topDir,topRadius,sideRadius);
}
/** mesh sphere */
public static IMesh meshSphere(IVecI center, double radius, int resolution){
return IMeshCreator.sphere(center,radius,resolution);
}
/** mesh sphere */
public static IMesh meshSphere(IVecI center, double radius){
return IMeshCreator.sphere(center,radius);
}
/** mesh sphere */
public static IMesh meshSphere(IVecI center, double zradius, double xyradius, int resolution){
return IMeshCreator.sphere(center,zradius,xyradius,resolution);
}
/** mesh sphere */
public static IMesh meshSphere(IVecI center, double zradius, double xyradius){
return IMeshCreator.sphere(center,zradius,xyradius);
}
public static IMesh meshRectStick(IVecI pt1, IVecI pt2, IVecI udir, IVecI vdir){
return IMeshCreator.rectStick(pt1,pt2,udir,vdir);
}
/**
creating closed mesh stick with 2 points and with and height
@param heightDir it provides reference to the direction of height but actual direction is re-calculated to be perpendicular to pt1-pt2 direction.
*/
public static IMesh meshRectStick(IVecI pt1, IVecI pt2, double width, double height, IVecI heightDir){
return IMeshCreator.rectStick(pt1,pt2,width,height,heightDir);
}
/** creating closed mesh stick. reference height direction is z axis */
public static IMesh meshRectStick(IVecI pt1, IVecI pt2, double width, double height){
return IMeshCreator.rectStick(pt1,pt2,width,height);
}
/**
creating closed mesh stick with square profile.
@param heightDir it provides reference to the direction of height but actual direction is re-calculated to be perpendicular to pt1-pt2 direction.
*/
public static IMesh meshSquareStick(IVecI pt1, IVecI pt2, double width, IVecI heightDir){
return IMeshCreator.squareStick(pt1,pt2,width,heightDir);
}
/** creating closed mesh stick. height direction is z axis */
public static IMesh meshSquareStick(IVecI pt1, IVecI pt2, double width){
return IMeshCreator.squareStick(pt1,pt2,width);
}
/**
creates closed mesh stick with polygon profile
@param pt1 center of one side of a stick
@param pt2 center of another side of a stick
@param polygonVertexNum number of vertex of profile polygon
*/
public static IMesh meshPolygonStick(IVecI pt1, IVecI pt2, double radius, int polygonVertexNum){
return IMeshCreator.polygonStick(pt1,pt2,radius,polygonVertexNum);
}
/**
creates closed mesh stick with polygon profile
@param pt1 center of one side of a stick
@param pt2 center of another side of a stick
@param polygonVertexNum number of vertex of profile polygon
@param heightDir reference vector to locate one of vertex of polygon aligned with this direction
*/
public static IMesh meshPolygonStick(IVecI pt1, IVecI pt2, double radius, int polygonVertexNum,
IVecI heightDir){
return IMeshCreator.polygonStick(pt1,pt2,radius,polygonVertexNum,heightDir);
}
/**
creates closed mesh stick with polygon profile
@param pt1 center of one side of a stick
@param pt2 center of another side of a stick
@param polygonVertexNum number of vertex of profile polygon
*/
public static IMesh meshPolygonStick(IVecI pt1, IVecI pt2, double radius1, double radius2,
int polygonVertexNum){
return IMeshCreator.polygonStick(pt1,pt2,radius1,radius2,polygonVertexNum);
}
/**
creates closed mesh stick with polygon profile
@param pt1 center of one side of a stick
@param pt2 center of another side of a stick
@param polygonVertexNum number of vertex of profile polygon
@param heightDir reference vector to locate one of vertex of polygon aligned with this direction
*/
public static IMesh meshPolygonStick(IVecI pt1, IVecI pt2, double radius1, double radius2,
int polygonVertexNum, IVecI heightDir){
return IMeshCreator.polygonStick(pt1,pt2,radius1,radius2,polygonVertexNum,heightDir);
}
public static IMesh meshPolygonStick(ICurveI railCurve, double radius, int polygonVertexNum,
int railSegmentNum){
return IMeshCreator.polygonStick(railCurve,radius,polygonVertexNum,railSegmentNum);
}
public static IMesh meshPolygonStick(ICurveI railCurve, double radius, int polygonVertexNum){
return IMeshCreator.polygonStick(railCurve,radius,polygonVertexNum);
}
/** round stick */
public static IMesh meshStick(IVecI pt1, IVecI pt2, double radius){
return IMeshCreator.stick(pt1,pt2,radius);
}
/** round stick */
public static IMesh meshStick(IVecI pt1, IVecI pt2, double radius1, double radius2){
return IMeshCreator.stick(pt1,pt2,radius1,radius2);
}
/** round stick */
public static IMesh meshStick(ICurveI railCurve, double radius, int railSegmentNum){
return IMeshCreator.roundStick(railCurve,radius,railSegmentNum);
}
/** round stick */
public static IMesh meshStick(ICurveI railCurve, double radius){
return IMeshCreator.roundStick(railCurve,radius);
}
/** round stick (alias of stick()) */
public static IMesh meshRoundStick(IVecI pt1, IVecI pt2, double radius){
return IMeshCreator.roundStick(pt1,pt2,radius);
}
/** round stick (alias of stick()) */
public static IMesh meshRoundStick(IVecI pt1, IVecI pt2, double radius1, double radius2){
return IMeshCreator.roundStick(pt1,pt2,radius1,radius2);
}
/** round stick */
public static IMesh meshRoundStick(ICurveI railCurve, double radius, int railSegmentNum){
return IMeshCreator.roundStick(railCurve,radius,railSegmentNum);
}
/** round stick */
public static IMesh meshRoundStick(ICurveI railCurve, double radius){
return IMeshCreator.roundStick(railCurve,radius);
}
/** square stick */
public static IMesh meshSquareStick(ICurveI railCurve, double radius, int railSegmentNum){
return IMeshCreator.squareStick(railCurve,radius,railSegmentNum);
}
/** square stick */
public static IMesh meshSquareStick(ICurveI railCurve, double radius){
return IMeshCreator.squareStick(railCurve,radius);
}
/** open pipe mesh */
public static IMesh meshRectPipe(IVecI pt1, IVecI pt2, IVecI udir, IVecI vdir){
return IMeshCreator.rectPipe(pt1,pt2,udir,vdir);
}
/**
creating open mesh pipe with 2 points and with and height
@param heightDir it provides reference to the direction of height but actual direction is re-calculated to be perpendicular to pt1-pt2 direction.
*/
public static IMesh meshRectPipe(IVecI pt1, IVecI pt2, double width, double height, IVecI heightDir){
return IMeshCreator.rectPipe(pt1,pt2,width,height,heightDir);
}
/** creating open mesh pipe. reference height direction is z axis */
public static IMesh meshRectPipe(IVecI pt1, IVecI pt2, double width, double height){
return IMeshCreator.rectPipe(pt1,pt2,width,height);
}
/**
creating open mesh pipe with square profile.
@param heightDir it provides reference to the direction of height but actual direction is re-calculated to be perpendicular to pt1-pt2 direction.
*/
public static IMesh meshSquarePipe(IVecI pt1, IVecI pt2, double width, IVecI heightDir){
return IMeshCreator.squarePipe(pt1,pt2,width,heightDir);
}
/** creating open mesh stick. height direction is z axis */
public static IMesh meshSquarePipe(IVecI pt1, IVecI pt2, double width){
return IMeshCreator.squarePipe(pt1,pt2,width);
}
/*********************************************************
* creating vector
********************************************************/
public static IVec vec(){ return v(); }
public static IVec vec(double x, double y, double z){ return v(x,y,z); }
public static IVec vec(double x, double y){ return v(x,y); }
public static IVec vec(IVec v){ return v(v); }
public static IVec vec(IVecI v){ return v(v); }
public static IVec vec(IDoubleI x, IDoubleI y, IDoubleI z){ return v(x,y,z); }
public static IVec vec(IDoubleI x, IDoubleI y){ return v(x,y); }
public static IVec vec(IVec2I v){ return v(v); }
/*********************************************************
* vector shorter name
********************************************************/
public static IVec v(){ return new IVec(); }
public static IVec v(double x, double y, double z){ return new IVec(x,y,z); }
public static IVec v(double x, double y){ return new IVec(x,y); }
public static IVec v(IVec v){ return new IVec(v); }
public static IVec v(IVecI v){ return new IVec(v); }
public static IVec v(IDoubleI x, IDoubleI y, IDoubleI z){
return new IVec(x,y,z);
}
public static IVec v(IDoubleI x, IDoubleI y){ return new IVec(x,y,new IDouble(0)); }
public static IVec v(IVec2I v){ return new IVec(v); }
/*********************************************************
* vector longer name
********************************************************/
public static IVec vector(){ return v(); }
public static IVec vector(double x, double y, double z){ return v(x,y,z); }
public static IVec vector(double x, double y){ return v(x,y); }
public static IVec vector(IVec v){ return v(v); }
public static IVec vector(IVecI v){ return v(v); }
public static IVec vector(IDoubleI x, IDoubleI y, IDoubleI z){ return v(x,y,z); }
public static IVec vector(IDoubleI x, IDoubleI y){ return v(x,y); }
public static IVec vector(IVec2I v){ return v(v); }
/*********************************************************
* creating 4 dimensional vector with weight
********************************************************/
public static IVec4 vec4(){ return v4(); }
public static IVec4 vec4(double x, double y, double z, double w){ return v4(x,y,z,w); }
public static IVec4 vec4(IVec v, double w){ return v4(v,w); }
public static IVec4 vec4(IVec4 v){ return v4(v); }
public static IVec4 vec4(IVecI v){ return v4(v); }
public static IVec4 vec4(IVecI v, double w){ return v4(v,w); }
public static IVec4 vec4(IVecI v, IDoubleI w){ return v4(v,w); }
public static IVec4 vec4(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI w){ return v4(x,y,z,w); }
/*********************************************************
* 4d vector shorter name
********************************************************/
public static IVec4 v4(){ return new IVec4(); }
public static IVec4 v4(double x, double y, double z, double w){ return new IVec4(x,y,z,w); }
public static IVec4 v4(IVec v, double w){ return new IVec4(v,w); }
public static IVec4 v4(IVec4 v){ return new IVec4(v); }
public static IVec4 v4(IVecI v){ return new IVec4(v); }
public static IVec4 v4(IVecI v, double w){ return new IVec4(v,w); }
public static IVec4 v4(IVecI v, IDoubleI w){ return new IVec4(v,w); }
public static IVec4 v4(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI w){
return new IVec4(x,y,z,w);
}
/*********************************************************
* 4d vector longer name
********************************************************/
public static IVec4 vector4(){ return v4(); }
public static IVec4 vector4(double x, double y, double z, double w){ return v4(x,y,z,w); }
public static IVec4 vector4(IVec v, double w){ return v4(v,w); }
public static IVec4 vector4(IVec4 v){ return v4(v); }
public static IVec4 vector4(IVecI v){ return v4(v); }
public static IVec4 vector4(IVecI v, double w){ return v4(v,w); }
public static IVec4 vector4(IVecI v, IDoubleI w){ return v4(v,w); }
public static IVec4 vector4(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI w){ return v4(x,y,z,w); }
/*********************************************************
* creating 2 dimensional vector
********************************************************/
public static IVec2 vec2(){ return v2(); }
public static IVec2 vec2(double x, double y){ return v2(x,y); }
public static IVec2 vec2(IVec2 v){ return v2(v); }
public static IVec2 vec2(IVecI v){ return v2(v); }
public static IVec2 vec2(IDoubleI x, IDoubleI y){ return v2(x,y); }
/*********************************************************
* 2d vector shorter name
********************************************************/
public static IVec2 v2(){ return new IVec2(); }
public static IVec2 v2(double x, double y){ return new IVec2(x,y); }
public static IVec2 v2(IVec2 v){ return new IVec2(v); }
public static IVec2 v2(IVecI v){ return new IVec2(v); }
public static IVec2 v2(IDoubleI x, IDoubleI y){ return new IVec2(x,y); }
/*********************************************************
* 2d vector longer name
********************************************************/
public static IVec2 vector2(){ return v2(); }
public static IVec2 vector2(double x, double y){ return v2(x,y); }
public static IVec2 vector2(IVec2 v){ return v2(v); }
public static IVec2 vector2(IVecI v){ return v2(v); }
public static IVec2 vector2(IDoubleI x, IDoubleI y){ return v2(x,y); }
/*********************************************************
* vector array
********************************************************/
public static IVec[] vec(double x, double y, double z, double ... xyzvals){
return v(x,y,z,xyzvals);
}
public static IVec[] vec(IVec ... v){ return v(v); }
public static IVecI[] vec(IVecI ... v){ return v(v); }
public static IVec[] vec(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI ... xyzvals){
return v(x,y,z,xyzvals);
}
public static IVec[] vec(IVec2I ... v){ return v(v); }
public static IVec[][] vec(IVec[] ... v){ return v(v); }
public static IVecI[][] vec(IVecI[] ... v){ return v(v); }
public static IVec[][][] vec(IVec[][] ... v){ return v(v); }
public static IVecI[][][] vec(IVecI[][] ... v){ return v(v); }
/*********************************************************
* vector array shorter name
********************************************************/
public static IVec[] v(double x, double y, double z, double ... xyzvals){
int num = xyzvals.length/3 + 1;
if(xyzvals.length%3>0) num++;
IVec[] array = new IVec[num];
array[0] = new IVec(x,y,z);
for(int i=1; i<num; i++){
array[i] = new IVec(xyzvals[(i-1)*3],
(i-1)*3+1<xyzvals.length?xyzvals[(i-1)*3+1]:0,
(i-1)*3+2<xyzvals.length?xyzvals[(i-1)*3+2]:0);
}
return array;
}
public static IVec[] v(IVec ... v){ return v; }
public static IVecI[] v(IVecI ... v){ return v;
/*
if(v==null) return null;
IVec[] array = new IVec[v.length];
for(int i=0; i<v.length; i++){ array[i] = v[i].get(); }
return array;
*/
}
public static IVec[] v(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI ... xyzvals){
int num = xyzvals.length/3 + 1;
if(xyzvals.length%3>0) num++;
IVec[] array = new IVec[num];
array[0] = new IVec(x,y,z);
for(int i=1; i<num; i++){
array[i] = new IVec(xyzvals[(i-1)*3],
(i-1)*3+1<xyzvals.length?xyzvals[(i-1)*3+1]:new IDouble(0),
(i-1)*3+2<xyzvals.length?xyzvals[(i-1)*3+2]:new IDouble(0));
}
return array;
}
public static IVec[] v(IVec2I ... v){
if(v==null) return null;
IVec[] array = new IVec[v.length];
for(int i=0; i<v.length; i++){ array[i] = new IVec(v[i]); }
return array;
}
/**
IVec 2d array
*/
public static IVec[][] v(IVec[] ... v){ return v; }
public static IVecI[][] v(IVecI[] ... v){ return v; }
/**
IVec 3d array
*/
public static IVec[][][] v(IVec[][] ... v){ return v; }
public static IVecI[][][] v(IVecI[][] ... v){ return v; }
/*********************************************************
* vector array longer name
********************************************************/
public static IVec[] vector(double x, double y, double z, double ... xyzvals){
return v(x,y,z,xyzvals);
}
public static IVec[] vector(IVec ... v){ return v(v); }
public static IVecI[] vector(IVecI ... v){ return v(v); }
public static IVec[] vector(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI ... xyzvals){
return v(x,y,z,xyzvals);
}
public static IVec[] vector(IVec2I ... v){ return v(v); }
public static IVec[][] vector(IVec[] ... v){ return v(v); }
public static IVecI[][] vector(IVecI[] ... v){ return v(v); }
public static IVec[][][] vector(IVec[][] ... v){ return v(v); }
public static IVecI[][][] vector(IVecI[][] ... v){ return v(v); }
/*********************************************************
* vector (IVec4) array
********************************************************/
public static IVec4[] vec4(double x, double y, double z, double w, double ... xyzwvals){
return v4(x,y,z,w,xyzwvals);
}
public static IVec4[] vec4(IVec4 ... v){ return v4(v); }
public static IVec4I[] vec4(IVec4I ... v){ return v4(v); }
public static IVec4[] vec4(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI w, IDoubleI ... xyzwvals){
return v4(x,y,z,w,xyzwvals);
}
/** IVec4 2d array */
public static IVec4[][] vec4(IVec4[] ... v){ return v4(v); }
public static IVec4I[][] vec4(IVec4I[] ... v){ return v4(v); }
/** IVec4 3d array */
public static IVec4[][][] vec4(IVec4[][] ... v){ return v4(v); }
public static IVec4I[][][] vec4(IVec4I[][] ... v){ return v4(v); }
public static IVec4[] v4(double x, double y, double z, double w, double ... xyzwvals){
int num = xyzwvals.length/4 + 1;
if(xyzwvals.length%4>0) num++;
IVec4[] array = new IVec4[num];
array[0] = new IVec4(x,y,z,w);
for(int i=1; i<num; i++){
array[i] = new IVec4(xyzwvals[(i-1)*4],
(i-1)*4+1<xyzwvals.length?xyzwvals[(i-1)*4+1]:0,
(i-1)*4+2<xyzwvals.length?xyzwvals[(i-1)*4+2]:0,
(i-1)*4+3<xyzwvals.length?xyzwvals[(i-1)*4+3]:0);
}
return array;
}
public static IVec4[] v4(IVec4 ... v){ return v; }
public static IVec4I[] v4(IVec4I ... v){ return v; }
public static IVec4[] v4(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI w, IDoubleI ... xyzwvals){
int num = xyzwvals.length/4 + 1;
if(xyzwvals.length%4>0) num++;
IVec4[] array = new IVec4[num];
array[0] = new IVec4(x,y,z,w);
for(int i=1; i<num; i++){
array[i] = new IVec4(xyzwvals[(i-1)*4],
(i-1)*4+1<xyzwvals.length?xyzwvals[(i-1)*4+1]:new IDouble(0),
(i-1)*4+2<xyzwvals.length?xyzwvals[(i-1)*4+2]:new IDouble(0),
(i-1)*4+3<xyzwvals.length?xyzwvals[(i-1)*4+3]:new IDouble(0));
}
return array;
}
/** IVec4 2d array */
public static IVec4[][] v4(IVec4[] ... v){ return v; }
public static IVec4I[][] v4(IVec4I[] ... v){ return v; }
/** IVec4 3d array */
public static IVec4[][][] v4(IVec4[][] ... v){ return v; }
public static IVec4I[][][] v4(IVec4I[][] ... v){ return v; }
public static IVec4[] vector4(double x, double y, double z, double w, double ... xyzwvals){
return v4(x,y,z,w,xyzwvals);
}
public static IVec4[] vector4(IVec4 ... v){ return v4(v); }
public static IVec4I[] vector4(IVec4I ... v){ return v4(v); }
public static IVec4[] vector4(IDoubleI x, IDoubleI y, IDoubleI z, IDoubleI w, IDoubleI ... xyzwvals){
return v4(x,y,z,w,xyzwvals);
}
/** IVec4 2d array */
public static IVec4[][] vector4(IVec4[] ... v){ return v4(v); }
public static IVec4I[][] vector4(IVec4I[] ... v){ return v4(v); }
/** IVec4 3d array */
public static IVec4[][][] vector4(IVec4[][] ... v){ return v4(v); }
public static IVec4I[][][] vector4(IVec4I[][] ... v){ return v4(v); }
/*********************************************************
* vector (IVec2) array
********************************************************/
public static IVec2[] vec2(double x, double y, double ... xyvals){ return v2(x,y,xyvals); }
public static IVec2[] vec2(IVec2 ... v){ return v2(v); }
public static IVec2I[] vec2(IVec2I ... v){ return v2(v); }
public static IVec2[] vec2(IDoubleI x, IDoubleI y, IDoubleI... xyvals){ return v2(x,y,xyvals); }
/** IVec2 2d array from IVecI*/
public static IVec2I[] vec2(IVecI ... v){ return v2(v); }
/** IVec2 2d array from IVecI*/
public static IVec2[] vec2(IVec ... v){ return v2(v); }
/** IVec2 2d array */
public static IVec2[][] vec2(IVec2[] ... v){ return v2(v); }
public static IVec2I[][] vec2(IVec2I[] ... v){ return v2(v); }
/** IVec2 3d array */
public static IVec2[][][] vec2(IVec2[][] ... v){ return v2(v); }
public static IVec2I[][][] vec2(IVec2I[][] ... v){ return v2(v); }
public static IVec2[] v2(double x, double y, double ... xyvals){
int num = xyvals.length/2 + 1;
if(xyvals.length%2>0) num++;
IVec2[] array = new IVec2[num];
array[0] = new IVec2(x,y);
for(int i=1; i<num; i++){
array[i] = new IVec2(xyvals[(i-1)*2],(i-1)*2+1<xyvals.length?xyvals[(i-1)*2+1]:0);
}
return array;
}
public static IVec2[] v2(IVec2 ... v){ return v; }
public static IVec2I[] v2(IVec2I ... v){ return v; }
public static IVec2[] v2(IDoubleI x, IDoubleI y, IDoubleI... xyvals){
int num = xyvals.length/2 + 1;
if(xyvals.length%2>0) num++;
IVec2[] array = new IVec2[num];
array[0] = new IVec2(x,y);
for(int i=1; i<num; i++){
array[i] =
new IVec2(xyvals[(i-1)*2],(i-1)*2+1<xyvals.length?xyvals[(i-1)*2+1]:new IDouble(0));
}
return array;
}
/** IVec2 array from IVec (projection) */
public static IVec2[] v2(IVec ... v){
IVec2[] array = new IVec2[v.length];
for(int i=0; i<v.length; i++){ array[i] = v[i].to2d(); }
return array;
}
/** IVec2I array from IVecI (projection) */
public static IVec2I[] v2(IVecI ... v){
IVec2I[] array = new IVec2I[v.length];
for(int i=0; i<v.length; i++){ array[i] = v[i].to2d(); }
return array;
}
/** IVec4 2d array */
public static IVec2[][] v2(IVec2[] ... v){ return v; }
public static IVec2I[][] v2(IVec2I[] ... v){ return v; }
/** IVec4 3d array */
public static IVec2[][][] v2(IVec2[][] ... v){ return v; }
public static IVec2I[][][] v2(IVec2I[][] ... v){ return v; }
public static IVec2[] vector2(double x, double y, double ... xyvals){ return v2(x,y,xyvals); }
public static IVec2[] vector2(IVec2 ... v){ return v2(v); }
public static IVec2I[] vector2(IVec2I ... v){ return v2(v); }
public static IVec2[] vector2(IDoubleI x, IDoubleI y, IDoubleI... xyvals){ return v2(x,y,xyvals); }
/** IVec4 2d array */
public static IVec2[][] vector2(IVec2[] ... v){ return v2(v); }
public static IVec2I[][] vector2(IVec2I[] ... v){ return v2(v); }
/** IVec4 3d array */
public static IVec2[][][] vector2(IVec2[][] ... v){ return v2(v); }
public static IVec2I[][][] vector2(IVec2I[][] ... v){ return v2(v); }
/*********************************************************
* generic array
********************************************************/
/** create array of any class. */
public static <T> T[] array(T ... vals){ return a(vals); }
/** create array of any class. */
public static <T> T[] array(int length, T ... vals){ return a(length,vals); }
/** create 2D array of any class. */
public static <T> T[][] array2(int length1, int length2, T ... vals){
return a2(length1,length2,vals);
}
/** create 2D array of any class. */
public static <T> T[][] array2(int length2, T ... vals){ return a2(length2,vals); }
/** create 3D array of any class. */
public static <T> T[][][] array3(int length1, int length2, int length3, T ... vals){
return a3(length1,length2,length3,vals);
}
/** create 3D array of any class. */
public static <T> T[][][] array3(int length2, int length3, T ... vals){
return a3(length2,length3,vals);
}
/*********************************************************
* generic array short name
********************************************************/
/** create array of any class. */
public static <T> T[] arr(T ... vals){ return a(vals); }
/** create array of any class. */
public static <T> T[] arr(int length, T ... vals){ return a(length,vals); }
/** create 2D array of any class. */
public static <T> T[][] arr2(int length1, int length2, T ... vals){
return a2(length1,length2,vals);
}
/** create 2D array of any class. */
public static <T> T[][] arr2(int length2, T ... vals){ return a2(length2,vals); }
/** create 3D array of any class. */
public static <T> T[][][] arr3(int length1, int length2, int length3, T ... vals){
return a3(length1,length2,length3,vals);
}
/** create 3D array of any class. */
public static <T> T[][][] arr3(int length2, int length3, T ... vals){
return a3(length2,length3,vals);
}
/*********************************************************
* generic array much shorter name
********************************************************/
/** create array of any class. */
public static <T> T[] a(T ... vals){ return vals; }
/** create array of any class. */
@SuppressWarnings({"unchecked"})
public static <T> T[] a(int length, T ... vals){
if(vals==null) return null;
if(vals.length!=length){
IOut.err("length1*length2 doesn't match with number of values");
}
T[] array = (T[])Array.newInstance(vals[0].getClass(),length);
int i=0;
for(; i<length && i<vals.length; i++) array[i] = vals[i];
//for(; i<length; i++) array[i] = null;
return vals;
}
/** create 2D array of any class. */
@SuppressWarnings({"unchecked"})
public static <T> T[][] a2(int length1, int length2, T ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
T[][] array = (T[][])Array.newInstance(vals.getClass(),length1);
for(int i=0; i<length1; i++){
array[i] = (T[])Array.newInstance(vals[0].getClass(),length2);
}
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
array[i][j] = vals[idx++];
return array;
}
/** create 2D array of any class. */
public static <T> T[][] a2(int length2, T ... vals){
if(vals==null) return null;
int length1 = vals.length/length2;
if(vals.length!=length1*length2){
IOut.err("length2 doesn't match with number of values");
}
if(length1==0) length1=1;
return array2(length1,length2,vals);
}
/** create 3D array of any class. */
@SuppressWarnings({"unchecked"})
public static <T> T[][][] a3(int length1, int length2, int length3, T ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
T[][][] array = (T[][][])Array.newInstance
( ((T[][])Array.newInstance(vals.getClass(),0)).getClass(), length1); // zero?
for(int i=0; i<length1; i++){
array[i] = (T[][])Array.newInstance(vals.getClass(),length2);
}
for(int i=0; i<length1; i++){
for(int j=0; j<length2; j++){
array[i][j] = (T[])Array.newInstance(vals[0].getClass(),length3);
}
}
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++)
array[i][j][k] = vals[idx++];
return array;
}
/** create 3D array of any class. */
public static <T> T[][][] a3(int length2, int length3, T ... vals){
if(vals==null) return null;
int length1 = vals.length/(length2*length3);
if(vals.length!=length1*length2*length3){
IOut.err("length2*length3 doesn't match with number of values");
}
if(length1==0) length1=1;
return array3(length1,length2,length3,vals);
}
/*********************************************************
* generic vector array copy
********************************************************/
public static IVecI[] cp(IVecI ... vecarray){
if(vecarray==null) return null;
IVecI[] retval = new IVecI[vecarray.length];
for(int i=0; i<vecarray.length; i++){
retval[i] = vecarray[i].cp();
}
return retval;
}
public static IVec[] cp(IVec ... vecarray){
if(vecarray==null) return null;
IVec[] retval = new IVec[vecarray.length];
for(int i=0; i<vecarray.length; i++){
retval[i] = vecarray[i].cp();
}
return retval;
}
public static IVec2I[] cp(IVec2I ... vecarray){
if(vecarray==null) return null;
IVec2I[] retval = new IVec2I[vecarray.length];
for(int i=0; i<vecarray.length; i++){
retval[i] = vecarray[i].cp();
}
return retval;
}
public static IVec2[] cp(IVec2 ... vecarray){
if(vecarray==null) return null;
IVec2[] retval = new IVec2[vecarray.length];
for(int i=0; i<vecarray.length; i++){
retval[i] = vecarray[i].cp();
}
return retval;
}
public static IVec4[] cp(IVec4 ... vecarray){
if(vecarray==null) return null;
IVec4[] retval = new IVec4[vecarray.length];
for(int i=0; i<vecarray.length; i++){
retval[i] = vecarray[i].cp();
}
return retval;
}
public static IVecI[] copy(IVecI ... vecarray){ return cp(vecarray); }
public static IVec[] copy(IVec ... vecarray){ return cp(vecarray); }
public static IVec2I[] copy(IVec2I ... vecarray){ return cp(vecarray); }
public static IVec2[] copy(IVec2 ... vecarray){ return cp(vecarray); }
public static IVec4[] copy(IVec4 ... vecarray){ return cp(vecarray); }
/*********************************************************
* primitive array
********************************************************/
/*********************************************************
* int array
********************************************************/
/** create array of any class. */
//public static int[] array(int ... vals){ return vals; }
/** create 2D array of any class. */
/*
public static int[][] array2(int length1, int length2, int ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
int[][] array = new int[length1][length2];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++) array[i][j] = vals[idx++];
return array;
}
*/
/** create 3D array of any class. */
/*
public static int[][][] array3(int length1, int length2, int length3, int ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
int[][][] array = new int[length1][length2][length3];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++) array[i][j][k] = vals[idx++];
return array;
}
*/
/** create array of any class. */
//public static int[] arr(int ... vals){ return array(vals); }
/** create 2D array of any class. */
/*
public static int[][] arr2(int length1, int length2, int ... vals){
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static int[][][] arr3(int length1, int length2, int length3, int ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create array of any class. */
//public static int[] a(int ... vals){ return array(vals); }
//public static Integer[] ia(Integer ... vals){ return array(vals); }
/** create 2D array of any class. */
/*
public static int[][] a2(int length1, int length2, int ... vals){
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static int[][][] a3(int length1, int length2, int length3, int ... vals){
return array3(length1,length2,length3,vals);
}
*/
/*********************************************************
* double array
********************************************************/
/** create array of any class. */
//public static double[] array(double ... vals){ return vals; }
/** create array of any class. */
/*
public static double[] array(int length, double ... vals){
if(vals==null) return null;
if(vals.length!=length){
IOut.err("length1*length2 doesn't match with number of values");
}
double[] array = new double[length];
int i=0;
for(; i<length && i<vals.length; i++) array[i] = vals[i];
return vals;
}
*/
/** create 2D array of any class. */
/*
public static double[][] array2(int length1, int length2, double ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
double[][] array = new double[length1][length2];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
array[i][j] = vals[idx++];
return array;
}
*/
/** create 2D array of any class. */
/*
public static double[][] array2(int length2, double ... vals){
if(vals==null) return null;
int length1 = vals.length/length2;
if(vals.length!=length1*length2){
IOut.err("length2 doesn't match with number of values");
}
if(length1==0) length1=1;
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static double[][][] array3(int length1, int length2, int length3, double ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
double[][][] array = new double[length1][length2][length3];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++)
array[i][j][k] = vals[idx++];
return array;
}
*/
/** create 3D array of any class. */
/*
public static double[][][] array3(int length2, int length3, double ... vals){
if(vals==null) return null;
int length1 = vals.length/(length2*length3);
if(vals.length!=length1*length2*length3){
IOut.err("length2*length3 doesn't match with number of values");
}
if(length1==0) length1=1;
return array3(length1,length2,length3,vals);
}
*/
/** create array of any class. */
//public static double[] arr(double ... vals){ return array(vals); }
/** create array of any class. */
//public static double[] arr(int length, double ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static double[][] arr2(int length1, int length2, double ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static double[][] arr2(int length2, double ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static double[][][] arr3(int length1, int length2, int length3, double ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static double[][][] arr3(int length2, int length3, double ... vals){
return array3(length2,length3,vals);
}
*/
/** create array of any class. */
//public static double[] a(double ... vals){ return array(vals); }
/** create array of any class. */
//public static double[] a(int length, double ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static double[][] a2(int length1, int length2, double ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static double[][] a2(int length2, double ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static double[][][] a3(int length1, int length2, int length3, double ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static double[][][] a3(int length2, int length3, double ... vals){
return array3(length2,length3,vals);
}
*/
/*********************************************************
* float array
********************************************************/
/** create array of any class. */
//public static float[] array(float ... vals){ return vals; }
/** create array of any class. */
/*
public static float[] array(int length, float ... vals){
if(vals==null) return null;
if(vals.length!=length){
IOut.err("length1*length2 doesn't match with number of values");
}
float[] array = new float[length];
int i=0;
for(; i<length && i<vals.length; i++) array[i] = vals[i];
return vals;
}
*/
/** create 2D array of any class. */
/*
public static float[][] array2(int length1, int length2, float ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
float[][] array = new float[length1][length2];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
array[i][j] = vals[idx++];
return array;
}
*/
/** create 2D array of any class. */
/*
public static float[][] array2(int length2, float ... vals){
if(vals==null) return null;
int length1 = vals.length/length2;
if(vals.length!=length1*length2){
IOut.err("length2 doesn't match with number of values");
}
if(length1==0) length1=1;
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static float[][][] array3(int length1, int length2, int length3, float ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
float[][][] array = new float[length1][length2][length3];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++)
array[i][j][k] = vals[idx++];
return array;
}
*/
/** create 3D array of any class. */
/*
public static float[][][] array3(int length2, int length3, float ... vals){
if(vals==null) return null;
int length1 = vals.length/(length2*length3);
if(vals.length!=length1*length2*length3){
IOut.err("length2*length3 doesn't match with number of values");
}
if(length1==0) length1=1;
return array3(length1,length2,length3,vals);
}
*/
/** create array of any class. */
//public static float[] arr(float ... vals){ return array(vals); }
/** create array of any class. */
//public static float[] arr(int length, float ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static float[][] arr2(int length1, int length2, float ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static float[][] arr2(int length2, float ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static float[][][] arr3(int length1, int length2, int length3, float ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static float[][][] arr3(int length2, int length3, float ... vals){
return array3(length2,length3,vals);
}
*/
/** create array of any class. */
//public static float[] a(float ... vals){ return array(vals); }
/** create array of any class. */
//public static float[] a(int length, float ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static float[][] a2(int length1, int length2, float ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static float[][] a2(int length2, float ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static float[][][] a3(int length1, int length2, int length3, float ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static float[][][] a3(int length2, int length3, float ... vals){
return array3(length2,length3,vals);
}
*/
/*********************************************************
* short array
********************************************************/
/** create array of any class. */
//public static short[] array(short ... vals){ return vals; }
/** create array of any class. */
/*
public static short[] array(int length, short ... vals){
if(vals==null) return null;
if(vals.length!=length){
IOut.err("length1*length2 doesn't match with number of values");
}
short[] array = new short[length];
int i=0;
for(; i<length && i<vals.length; i++) array[i] = vals[i];
return vals;
}
*/
/** create 2D array of any class. */
/*
public static short[][] array2(int length1, int length2, short ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
short[][] array = new short[length1][length2];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
array[i][j] = vals[idx++];
return array;
}
*/
/** create 2D array of any class. */
/*
public static short[][] array2(int length2, short ... vals){
if(vals==null) return null;
int length1 = vals.length/length2;
if(vals.length!=length1*length2){
IOut.err("length2 doesn't match with number of values");
}
if(length1==0) length1=1;
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static short[][][] array3(int length1, int length2, int length3, short ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
short[][][] array = new short[length1][length2][length3];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++)
array[i][j][k] = vals[idx++];
return array;
}
*/
/** create 3D array of any class. */
/*
public static short[][][] array3(int length2, int length3, short ... vals){
if(vals==null) return null;
int length1 = vals.length/(length2*length3);
if(vals.length!=length1*length2*length3){
IOut.err("length2*length3 doesn't match with number of values");
}
if(length1==0) length1=1;
return array3(length1,length2,length3,vals);
}
*/
/** create array of any class. */
//public static short[] arr(short ... vals){ return array(vals); }
/** create array of any class. */
//public static short[] arr(int length, short ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static short[][] arr2(int length1, int length2, short ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static short[][] arr2(int length2, short ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static short[][][] arr3(int length1, int length2, int length3, short ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static short[][][] arr3(int length2, int length3, short ... vals){
return array3(length2,length3,vals);
}
*/
/** create array of any class. */
//public static short[] a(short ... vals){ return array(vals); }
/** create array of any class. */
//public static short[] a(int length, short ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static short[][] a2(int length1, int length2, short ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static short[][] a2(int length2, short ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static short[][][] a3(int length1, int length2, int length3, short ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static short[][][] a3(int length2, int length3, short ... vals){
return array3(length2,length3,vals);
}
*/
/*********************************************************
* long array
********************************************************/
/** create array of any class. */
//public static long[] array(long ... vals){ return vals; }
/** create array of any class. */
/*
public static long[] array(int length, long ... vals){
if(vals==null) return null;
if(vals.length!=length){
IOut.err("length1*length2 doesn't match with number of values");
}
long[] array = new long[length];
int i=0;
for(; i<length && i<vals.length; i++) array[i] = vals[i];
return vals;
}
*/
/** create 2D array of any class. */
/*
public static long[][] array2(int length1, int length2, long ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
long[][] array = new long[length1][length2];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
array[i][j] = vals[idx++];
return array;
}
*/
/** create 2D array of any class. */
/*
public static long[][] array2(int length2, long ... vals){
if(vals==null) return null;
int length1 = vals.length/length2;
if(vals.length!=length1*length2){
IOut.err("length2 doesn't match with number of values");
}
if(length1==0) length1=1;
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static long[][][] array3(int length1, int length2, int length3, long ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
long[][][] array = new long[length1][length2][length3];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++)
array[i][j][k] = vals[idx++];
return array;
}
*/
/** create 3D array of any class. */
/*
public static long[][][] array3(int length2, int length3, long ... vals){
if(vals==null) return null;
int length1 = vals.length/(length2*length3);
if(vals.length!=length1*length2*length3){
IOut.err("length2*length3 doesn't match with number of values");
}
if(length1==0) length1=1;
return array3(length1,length2,length3,vals);
}
*/
/** create array of any class. */
//public static long[] arr(long ... vals){ return array(vals); }
/** create array of any class. */
//public static long[] arr(int length, long ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static long[][] arr2(int length1, int length2, long ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static long[][] arr2(int length2, long ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static long[][][] arr3(int length1, int length2, int length3, long ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static long[][][] arr3(int length2, int length3, long ... vals){
return array3(length2,length3,vals);
}
*/
/** create array of any class. */
//public static long[] a(long ... vals){ return array(vals); }
/** create array of any class. */
//public static long[] a(int length, long ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static long[][] a2(int length1, int length2, long ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static long[][] a2(int length2, long ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static long[][][] a3(int length1, int length2, int length3, long ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static long[][][] a3(int length2, int length3, long ... vals){
return array3(length2,length3,vals);
}
*/
/*********************************************************
* byte array
********************************************************/
/** create array of any class. */
//public static byte[] array(byte ... vals){ return vals; }
/** create array of any class. */
/*
public static byte[] array(int length, byte ... vals){
if(vals==null) return null;
if(vals.length!=length){
IOut.err("length1*length2 doesn't match with number of values");
}
byte[] array = new byte[length];
int i=0;
for(; i<length && i<vals.length; i++) array[i] = vals[i];
return vals;
}
*/
/** create 2D array of any class. */
/*
public static byte[][] array2(int length1, int length2, byte ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
byte[][] array = new byte[length1][length2];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
array[i][j] = vals[idx++];
return array;
}
*/
/** create 2D array of any class. */
/*
public static byte[][] array2(int length2, byte ... vals){
if(vals==null) return null;
int length1 = vals.length/length2;
if(vals.length!=length1*length2){
IOut.err("length2 doesn't match with number of values");
}
if(length1==0) length1=1;
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static byte[][][] array3(int length1, int length2, int length3, byte ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
byte[][][] array = new byte[length1][length2][length3];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++)
array[i][j][k] = vals[idx++];
return array;
}
*/
/** create 3D array of any class. */
/*
public static byte[][][] array3(int length2, int length3, byte ... vals){
if(vals==null) return null;
int length1 = vals.length/(length2*length3);
if(vals.length!=length1*length2*length3){
IOut.err("length2*length3 doesn't match with number of values");
}
if(length1==0) length1=1;
return array3(length1,length2,length3,vals);
}
*/
/** create array of any class. */
//public static byte[] arr(byte ... vals){ return array(vals); }
/** create array of any class. */
//public static byte[] arr(int length, byte ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static byte[][] arr2(int length1, int length2, byte ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static byte[][] arr2(int length2, byte ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static byte[][][] arr3(int length1, int length2, int length3, byte ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static byte[][][] arr3(int length2, int length3, byte ... vals){
return array3(length2,length3,vals);
}
*/
/** create array of any class. */
//public static byte[] a(byte ... vals){ return array(vals); }
/** create array of any class. */
//public static byte[] a(int length, byte ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static byte[][] a2(int length1, int length2, byte ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static byte[][] a2(int length2, byte ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static byte[][][] a3(int length1, int length2, int length3, byte ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static byte[][][] a3(int length2, int length3, byte ... vals){
return array3(length2,length3,vals);
}
*/
/*********************************************************
* char array
********************************************************/
/** create array of any class. */
//public static char[] array(char ... vals){ return vals; }
/** create array of any class. */
/*
public static char[] array(int length, char ... vals){
if(vals==null) return null;
if(vals.length!=length){
IOut.err("length1*length2 doesn't match with number of values");
}
char[] array = new char[length];
int i=0;
for(; i<length && i<vals.length; i++) array[i] = vals[i];
return vals;
}
*/
/** create 2D array of any class. */
/*
public static char[][] array2(int length1, int length2, char ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
char[][] array = new char[length1][length2];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
array[i][j] = vals[idx++];
return array;
}
*/
/** create 2D array of any class. */
/*
public static char[][] array2(int length2, char ... vals){
if(vals==null) return null;
int length1 = vals.length/length2;
if(vals.length!=length1*length2){
IOut.err("length2 doesn't match with number of values");
}
if(length1==0) length1=1;
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static char[][][] array3(int length1, int length2, int length3, char ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
char[][][] array = new char[length1][length2][length3];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++)
array[i][j][k] = vals[idx++];
return array;
}
*/
/** create 3D array of any class. */
/*
public static char[][][] array3(int length2, int length3, char ... vals){
if(vals==null) return null;
int length1 = vals.length/(length2*length3);
if(vals.length!=length1*length2*length3){
IOut.err("length2*length3 doesn't match with number of values");
}
if(length1==0) length1=1;
return array3(length1,length2,length3,vals);
}
*/
/** create array of any class. */
//public static char[] arr(char ... vals){ return array(vals); }
/** create array of any class. */
//public static char[] arr(int length, char ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static char[][] arr2(int length1, int length2, char ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static char[][] arr2(int length2, char ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static char[][][] arr3(int length1, int length2, int length3, char ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static char[][][] arr3(int length2, int length3, char ... vals){
return array3(length2,length3,vals);
}
*/
/** create array of any class. */
//public static char[] a(char ... vals){ return array(vals); }
/** create array of any class. */
//public static char[] a(int length, char ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static char[][] a2(int length1, int length2, char ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static char[][] a2(int length2, char ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static char[][][] a3(int length1, int length2, int length3, char ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static char[][][] a3(int length2, int length3, char ... vals){
return array3(length2,length3,vals);
}
*/
/*********************************************************
* boolean array
********************************************************/
/** create array of any class. */
//public static boolean[] array(boolean ... vals){ return vals; }
/** create array of any class. */
/*
public static boolean[] array(int length, boolean ... vals){
if(vals==null) return null;
if(vals.length!=length){
IOut.err("length1*length2 doesn't match with number of values");
}
boolean[] array = new boolean[length];
int i=0;
for(; i<length && i<vals.length; i++) array[i] = vals[i];
return vals;
}
*/
/** create 2D array of any class. */
/*
public static boolean[][] array2(int length1, int length2, boolean ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2){
IOut.err("length1*length2 doesn't match with number of values");
}
boolean[][] array = new boolean[length1][length2];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
array[i][j] = vals[idx++];
return array;
}
*/
/** create 2D array of any class. */
/*
public static boolean[][] array2(int length2, boolean ... vals){
if(vals==null) return null;
int length1 = vals.length/length2;
if(vals.length!=length1*length2){
IOut.err("length2 doesn't match with number of values");
}
if(length1==0) length1=1;
return array2(length1,length2,vals);
}
*/
/** create 3D array of any class. */
/*
public static boolean[][][] array3(int length1, int length2, int length3, boolean ... vals){
if(vals==null) return null;
if(vals.length!=length1*length2*length3){
IOut.err("length1*length2*length3 doesn't match with number of values");
}
boolean[][][] array = new boolean[length1][length2][length3];
int idx=0;
for(int i=0; i<length1 && idx<vals.length; i++)
for(int j=0; j<length2 && idx<vals.length; j++)
for(int k=0; k<length3 && idx<vals.length; k++)
array[i][j][k] = vals[idx++];
return array;
}
*/
/** create 3D array of any class. */
/*
public static boolean[][][] array3(int length2, int length3, boolean ... vals){
if(vals==null) return null;
int length1 = vals.length/(length2*length3);
if(vals.length!=length1*length2*length3){
IOut.err("length2*length3 doesn't match with number of values");
}
if(length1==0) length1=1;
return array3(length1,length2,length3,vals);
}
*/
/** create array of any class. */
//public static boolean[] arr(boolean ... vals){ return array(vals); }
/** create array of any class. */
//public static boolean[] arr(int length, boolean ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static boolean[][] arr2(int length1, int length2, boolean ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static boolean[][] arr2(int length2, boolean ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static boolean[][][] arr3(int length1, int length2, int length3, boolean ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static boolean[][][] arr3(int length2, int length3, boolean ... vals){
return array3(length2,length3,vals);
}
*/
/** create array of any class. */
//public static boolean[] a(boolean ... vals){ return array(vals); }
/** create array of any class. */
//public static boolean[] a(int length, boolean ... vals){ return array(length,vals); }
/** create 2D array of any class. */
/*
public static boolean[][] a2(int length1, int length2, boolean ... vals){
return array2(length1,length2,vals);
}
*/
/** create 2D array of any class. */
//public static boolean[][] a2(int length2, boolean ... vals){ return array2(length2,vals); }
/** create 3D array of any class. */
/*
public static boolean[][][] a3(int length1, int length2, int length3, boolean ... vals){
return array3(length1,length2,length3,vals);
}
*/
/** create 3D array of any class. */
/*
public static boolean[][][] a3(int length2, int length3, boolean ... vals){
return array3(length2,length3,vals);
}
*/
public static boolean eq(double v1, double v2){ return Math.abs(v1-v2)<=IConfig.tolerance; }
public static boolean eq(double v1, double v2, double tolerance){ return Math.abs(v1-v2)<=tolerance; }
/*********************************************************
* random number
********************************************************/
public static void initRand(int seed){ IRand.init(seed); }
public static void initRandByTime(){ IRand.initByTime(); }
public static void initRand(){ initRandByTime(); }
public static void seed(int seed){ initRand(seed); }
public static void seedByTime(){ initRandByTime(); }
public static void seedRand(){ initRandByTime(); }
public static double rand(){ return IRand.get(); }
public static double rand(double max){ return IRand.get(max); }
public static double rand(double min, double max){ return IRand.get(min,max); }
public static float rand(float max){ return IRand.getf(max); }
public static float rand(float min, float max){ return IRand.getf(min,max); }
public static int rand(int max){ return IRand.geti(max); }
public static int rand(int min, int max){ return IRand.geti(min,max); }
public static IVec randPt(){ return IRand.pt(); }
public static IVec randPt(double max){ return IRand.pt(max); }
public static IVec randPt(double min, double max){ return IRand.pt(min,max); }
public static IVec randPt(double maxx,double maxy,double maxz){
return IRand.pt(maxx,maxy,maxz);
}
public static IVec randPt(double minx, double miny, double maxx, double maxy){
return IRand.pt(minx,miny,maxx,maxy);
}
public static IVec randPt(double minx, double miny, double minz,
double maxx, double maxy, double maxz){
return IRand.pt(minx,miny,minz,maxx,maxy,maxz);
}
public static IVec randDir(){ return IRand.dir(); }
public static IVec randDir(double len){ return IRand.dir(len); }
static public IVec randDir(IVecI perpendicularAxis){ return IRand.dir(perpendicularAxis); }
static public IVec randDir(IVecI perpendicularAxis, double length){ return IRand.dir(perpendicularAxis,length); }
public static IColor randClr(){ return IRand.clr(); }
public static IColor randClr(float alpha){ return IRand.clr(alpha); }
public static IColor randClr(int alpha){ return IRand.clr(alpha); }
public static IColor randColor(){ return randClr(); }
public static IColor randColor(float alpha){ return randClr(alpha); }
public static IColor randColor(int alpha){ return randClr(alpha); }
public static IColor randGray(){ return IRand.gray(); }
public static IColor randGray(float alpha){ return IRand.gray(alpha); }
public static IColor randGray(int alpha){ return IRand.gray(alpha); }
public static <T> T rand(T[] array){ return IRand.get(array); }
public static <T> T rand(java.util.List<T> array){ return IRand.get(array); }
public static boolean randPercent(double percent){ return pct(percent); }
public static boolean randPct(double percent){ return pct(percent); }
public static boolean percent(double percent){ return pct(percent); }
public static boolean pct(double percent){ return IRand.pct(percent); }
// group attribute setting methods
public static IObject clr(IObject obj, IColor c){ obj.clr(c); return obj; }
public static IObject[] clr(IObject[] objs, IColor c){
for(int i=0; i<objs.length; i++){ objs[i].clr(c); } return objs;
}
public static ArrayList<IObject> clr(ArrayList<IObject> objs, IColor c){
for(int i=0; i<objs.size(); i++){ objs.get(i).clr(c); } return objs;
}
public static IObject clr(IObject obj, IColor c, int alpha){ obj.clr(c,alpha); return obj; }
public static IObject[] clr(IObject[] objs, IColor c, int alpha){
for(int i=0; i<objs.length; i++){ objs[i].clr(c,alpha); } return objs;
}
public static ArrayList<IObject> clr(ArrayList<IObject> objs, IColor c, int alpha){
for(int i=0; i<objs.size(); i++){ objs.get(i).clr(c,alpha); } return objs;
}
public static IObject clr(IObject obj, IColor c, float alpha){ obj.clr(c,alpha); return obj; }
public static IObject[] clr(IObject[] objs, IColor c, float alpha){
for(int i=0; i<objs.length; i++){ objs[i].clr(c,alpha); } return objs;
}
public static ArrayList<IObject> clr(ArrayList<IObject> objs, IColor c, float alpha){
for(int i=0; i<objs.size(); i++){ objs.get(i).clr(c,alpha); } return objs;
}
public static IObject clr(IObject obj, IColor c, double alpha){ obj.clr(c,alpha); return obj; }
public static IObject[] clr(IObject[] objs, IColor c, double alpha){
for(int i=0; i<objs.length; i++){ objs[i].clr(c,alpha); } return objs;
}
public static ArrayList<IObject> clr(ArrayList<IObject> objs, IColor c, double alpha){
for(int i=0; i<objs.size(); i++){ objs.get(i).clr(c,alpha); } return objs;
}
public static IObject clr(IObject obj, Color c){ obj.clr(c); return obj; }
public static IObject[] clr(IObject[] objs, Color c){ return clr(objs, new IColor(c)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, Color c){ return clr(objs, new IColor(c)); }
public static IObject clr(IObject obj, Color c, int alpha){ obj.clr(new IColor(c,alpha)); return obj; }
public static IObject[] clr(IObject[] objs, Color c, int alpha){ return clr(objs, new IColor(c,alpha)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, Color c, int alpha){ return clr(objs, new IColor(c,alpha)); }
public static IObject clr(IObject obj, Color c, float alpha){ obj.clr(new IColor(c,alpha)); return obj; }
public static IObject[] clr(IObject[] objs, Color c, float alpha){ return clr(objs, new IColor(c,alpha)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, Color c, float alpha){ return clr(objs, new IColor(c,alpha)); }
public static IObject clr(IObject obj, Color c, double alpha){ obj.clr(new IColor(c,alpha)); return obj; }
public static IObject[] clr(IObject[] objs, Color c, double alpha){ return clr(objs, new IColor(c,alpha)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, Color c, double alpha){ return clr(objs, new IColor(c,alpha)); }
public static IObject clr(IObject obj, int gray){ obj.clr(new IColor(gray)); return obj; }
public static IObject[] clr(IObject[] objs, int gray){ return clr(objs, new IColor(gray)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, int gray){ return clr(objs, new IColor(gray)); }
public static IObject clr(IObject obj, float gray){ obj.clr(new IColor(gray)); return obj; }
public static IObject[] clr(IObject[] objs, float gray){ return clr(objs, new IColor(gray)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, float gray){ return clr(objs, new IColor(gray)); }
public static IObject clr(IObject obj, double gray){ obj.clr(new IColor(gray)); return obj; }
public static IObject[] clr(IObject[] objs, double gray){ return clr(objs, new IColor(gray)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, double gray){ return clr(objs, new IColor(gray)); }
public static IObject clr(IObject obj, int gray, int alpha){ obj.clr(new IColor(gray,alpha)); return obj; }
public static IObject[] clr(IObject[] objs, int gray, int alpha){ return clr(objs, new IColor(gray,alpha)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, int gray, int alpha){ return clr(objs, new IColor(gray,alpha)); }
public static IObject clr(IObject obj, float gray, float alpha){ obj.clr(new IColor(gray,alpha)); return obj; }
public static IObject[] clr(IObject[] objs, float gray, float alpha){ return clr(objs, new IColor(gray,alpha)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, float gray, float alpha){ return clr(objs, new IColor(gray,alpha)); }
public static IObject clr(IObject obj, double gray, double alpha){ obj.clr(new IColor(gray,alpha)); return obj; }
public static IObject[] clr(IObject[] objs, double gray, double alpha){ return clr(objs, new IColor(gray,alpha)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, double gray, double alpha){ return clr(objs, new IColor(gray,alpha)); }
public static IObject clr(IObject obj, int r, int g, int b){ obj.clr(new IColor(r,g,b)); return obj; }
public static IObject[] clr(IObject[] objs, int r, int g, int b){ return clr(objs, new IColor(r,g,b)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, int r, int g, int b){ return clr(objs, new IColor(r,g,b)); }
public static IObject clr(IObject obj, double r, double g, double b){ obj.clr(new IColor(r,g,b)); return obj; }
public static IObject[] clr(IObject[] objs, double r, double g, double b){ return clr(objs, new IColor(r,g,b)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, double r, double g, double b){ return clr(objs, new IColor(r,g,b)); }
public static IObject clr(IObject obj, float r, float g, float b){ obj.clr(new IColor(r,g,b)); return obj; }
public static IObject[] clr(IObject[] objs, float r, float g, float b){ return clr(objs, new IColor(r,g,b)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, float r, float g, float b){ return clr(objs, new IColor(r,g,b)); }
public static IObject clr(IObject obj, int r, int g, int b, int a){ obj.clr(new IColor(r,g,b,a)); return obj; }
public static IObject[] clr(IObject[] objs, int r, int g, int b, int a){ return clr(objs, new IColor(r,g,b,a)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, int r, int g, int b, int a){ return clr(objs, new IColor(r,g,b,a)); }
public static IObject clr(IObject obj, double r, double g, double b, double a){ obj.clr(new IColor(r,g,b,a)); return obj; }
public static IObject[] clr(IObject[] objs, double r, double g, double b, double a){ return clr(objs, new IColor(r,g,b,a)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, double r, double g, double b, double a){ return clr(objs, new IColor(r,g,b,a)); }
public static IObject clr(IObject obj, float r, float g, float b, float a){ obj.clr(new IColor(r,g,b,a)); return obj; }
public static IObject[] clr(IObject[] objs, float r, float g, float b, float a){ return clr(objs, new IColor(r,g,b,a)); }
public static ArrayList<IObject> clr(ArrayList<IObject> objs, float r, float g, float b, float a){ return clr(objs, new IColor(r,g,b,a)); }
public static IObject hsb(IObject obj, float h, float s, float b, float a){ obj.clr(IColor.hsb(h,s,b,a)); return obj; }
public static IObject[] hsb(IObject[] objs, float h, float s, float b, float a){ return clr(objs, IColor.hsb(h,s,b,a)); }
public static ArrayList<IObject> hsb(ArrayList<IObject> objs, float h, float s, float b, float a){ return clr(objs, IColor.hsb(h,s,b,a)); }
public static IObject hsb(IObject obj, double h, double s, double b, double a){ obj.clr(IColor.hsb(h,s,b,a)); return obj; }
public static IObject[] hsb(IObject[] objs, double h, double s, double b, double a){ return clr(objs, IColor.hsb(h,s,b,a)); }
public static ArrayList<IObject> hsb(ArrayList<IObject> objs, double h, double s, double b, double a){ return clr(objs, IColor.hsb(h,s,b,a)); }
public static IObject hsb(IObject obj, float h, float s, float b){ obj.clr(IColor.hsb(h,s,b)); return obj; }
public static IObject[] hsb(IObject[] objs, float h, float s, float b){ return clr(objs, IColor.hsb(h,s,b)); }
public static ArrayList<IObject> hsb(ArrayList<IObject> objs, float h, float s, float b){ return clr(objs, IColor.hsb(h,s,b)); }
public static IObject hsb(IObject obj, double h, double s, double b){ obj.clr(IColor.hsb(h,s,b)); return obj; }
public static IObject[] hsb(IObject[] objs, double h, double s, double b){ return clr(objs, IColor.hsb(h,s,b)); }
public static ArrayList<IObject> hsb(ArrayList<IObject> objs, double h, double s, double b){ return clr(objs, IColor.hsb(h,s,b)); }
public static IObject weight(IObject obj, double w){ obj.weight(w); return obj; }
public static IObject[] weight(IObject[] objs, double w){
for(int i=0; i<objs.length; i++){ objs[i].weight(w); } return objs;
}
public static ArrayList<IObject> weight(ArrayList<IObject> objs, double w){
for(int i=0; i<objs.size(); i++){ objs.get(i).weight(w); } return objs;
}
public static IObject weight(IObject obj, float w){ obj.weight(w); return obj; }
public static IObject[] weight(IObject[] objs, float w){
for(int i=0; i<objs.length; i++){ objs[i].weight(w); } return objs;
}
public static ArrayList<IObject> weight(ArrayList<IObject> objs, float w){
for(int i=0; i<objs.size(); i++){ objs.get(i).weight(w); } return objs;
}
public static IObject hide(IObject obj){ obj.hide(); return obj; }
public static IObject[] hide(IObject[] objs){
for(int i=0; i<objs.length; i++){ objs[i].hide(); } return objs;
}
public static ArrayList<IObject> hide(ArrayList<IObject> objs){
for(int i=0; i<objs.size(); i++){ objs.get(i).hide(); } return objs;
}
public static IObject show(IObject obj){ obj.show(); return obj; }
public static IObject[] show(IObject[] objs){
for(int i=0; i<objs.length; i++){ objs[i].show(); } return objs;
}
public static ArrayList<IObject> show(ArrayList<IObject> objs){
for(int i=0; i<objs.size(); i++){ objs.get(i).show(); } return objs;
}
}
| sghr/iGeo | IG.java |
1,007 | import java.io.DataInputStream;
import java.util.Random;
import javax.microedition.lcdui.Graphics;
public final class f {
public static final Random bq = new Random();
public static int au = 0;
public static int aF = 0;
public static int r;
public static int i;
public static byte[] O;
public static int[] a;
public static int f;
public static int t;
public static int m;
public static int aH;
public static short[] cB;
public static short[] ct;
public static int aJ;
public static int az;
public static int aD;
public static int[] ai;
public static int[] W;
public static int[] aj;
public static int bv;
public static int bD;
public static int[] bA;
public static int by;
public static long bn;
public int bu = 0;
public int bM;
public int bI;
public int[] ac;
public int[][] ae;
public static int cq;
public static int ba;
public int[][] cc;
public static byte[] cy;
public static short[] bY;
public static short[] bU;
public int[] cF;
public int cf;
public int q;
public int bf;
public int aA = 0;
public int aE = 0;
public int cp = 0;
public int bJ;
public static int bH;
public static int cA;
public static boolean cL;
public static boolean cK;
public static long cE;
public static long aX;
public static long aN;
public static long aC;
public static long al;
public static long aB;
public static boolean ar;
public static long Q;
public static int bo;
public static int an;
public static int I;
public static int M;
public static int C;
public static int z;
public static int U;
public static int S;
public static int aq;
public static int ch;
public static int cH;
public static int cu;
public static int w;
public static int j;
public static int d;
public static long g;
public static int P;
public static int ao;
public static int Z;
public static int B;
public static int cb;
public static int ck;
public static boolean cJ;
public static int bO;
public static int aU;
public static int X;
public static int aw;
public static int at;
public static int l;
public static int aT;
public static int ay;
public static int aI;
public static int bQ;
public static int cm;
public static int cC;
public static int bK;
public static int H;
public static int J;
public static boolean cj;
public static int u;
public static int bP;
public static int bW;
public static int bz;
public static int bB;
public static int ce;
public static boolean o;
public static int bF;
public static int bR;
public static int cn;
public static int cw;
public static int G;
public static int Y;
public static int V;
public static long bw;
public int aS = 0;
public int aO = 0;
public int bj;
public int bm;
public static DataInputStream T;
public static boolean aL;
public int ad;
public static int af;
public static int cr;
public static int bb;
public static int cd;
public static int cz;
public static short[] bZ;
public static short[] bV;
public static short[] cG;
public static int cg;
public static int am;
public static int br;
public static int ak;
public static int ab;
public static int bE;
public static int aV;
public static int aZ;
public static int bi;
public static int ah;
public static int as;
public static int ag;
public static int bC;
public static int aY;
public static int v;
public static int av;
public static int ax;
public static int aQ;
public static int n;
public static int N;
public static int bL;
public static int A;
public static int y;
public static long bN;
public static int bs;
public static boolean cl;
public static boolean bX;
public static int ca;
public static int ci;
public static int cI;
public static int cv;
public static int x;
public static int k;
public static int e;
public static int h;
public static int R;
public static int ap;
public static int aa;
public static int aK;
public static int L;
public static int E;
public static int K;
public static int D;
public static int cs;
public static int p;
public static int c;
public static int s;
public static int aG;
public static int aR;
public static int aP;
public static int aM;
public static long bh;
public static int bl;
public static int aW;
public static int cD;
public static long bc;
public static long be;
public static boolean bt;
public static boolean bd;
public static final boolean[] bp;
public static int bx;
public static int b;
public static int bT;
public static short[][] bg;
public static final int[][] bk;
public static final byte[][] bG;
public static int[] bS;
public static int[] co;
public static int[] cx;
public static int[] F;
public f() {
boolean var10001 = false;
var10001 = false;
var10001 = false;
var10001 = false;
var10001 = false;
var10001 = false;
var10001 = false;
var10001 = false;
var10001 = false;
this.ad = 2;
System.gc();
}
public final void b() {
C();
this.bm = d.al >> 1;
int var10001 = d.au >> 1;
var10001 = this.bm;
var10001 = d.au - 30;
}
public final void g() {
R();
c.D();
if (cL || cK) {
this.a(ay, aI, aT, U - 17, u, bF);
}
}
public final void z(int var1) {
int var2 = this.ae[this.bu + 3][var1];
int var3 = this.ae[this.bu + 4][var1];
int var4 = this.ae[this.bu + 7][var1] * bF >> 16;
this.bM = var2;
this.bI = var3 - var4;
}
public final void a(int var1, int var2, int var3) {
c.bg[var2][var3] = (short)this.ae[this.bu + 3][var1];
c.ag[var2][var3] = (short)this.ae[this.bu + 4][var1];
}
public final void x() {
int var1 = this.ae[this.bu + 3][2];
int var2 = this.ae[this.bu + 4][2];
int var3 = this.ae[this.bu + 7][2] * bF >> 16;
bR = var1 + -10;
cn = var2 - var3 + -15;
}
public final boolean o() {
try {
this.ac = null;
this.ae = (int[][])null;
cy = null;
bY = null;
bU = null;
this.cF = null;
System.gc();
T = new DataInputStream((new String("")).getClass().getResourceAsStream("/testdog.bin"));
this.bj = T.readByte();
this.bJ = T.readByte();
byte var12 = T.readByte();
cq = T.readByte();
this.aS = T.readByte() & 255;
int var13 = T.readByte() & 255;
int var14 = T.readByte() & 255;
this.aO = T.readByte() & 255;
this.cF = new int[var14];
this.ac = new int[var12];
int var1;
int var15;
for(var1 = 0; var1 < var12; ++var1) {
var15 = T.readUnsignedShort();
this.ac[var1] = (var15 >>> 8) + ((var15 & 255) << 8);
}
if (d.at) {
return false;
} else {
this.cc = new int[cq][];
int var2;
int var16;
int var18;
for(var1 = 0; var1 < cq; ++var1) {
this.cc[var1] = new int[8];
for(var2 = 0; var2 < 8; ++var2) {
var15 = T.readByte() & 255;
var16 = T.readByte() & 255;
int var17 = T.readByte() & 255;
var18 = T.readByte() & 255;
this.cc[var1][var2] = (var15 << 16) + (var16 << 8) + var17;
}
}
if (d.at) {
return false;
} else {
int[] var11 = new int[this.aS * 6];
var1 = 0;
for(var2 = 0; var1 < this.aS; var2 += 6) {
var11[var2 + 0] = T.readByte() & 255;
var15 = T.readByte() & 255;
var11[var2 + 1] = var15;
var11[var2 + 2] = T.readByte() & 255;
var11[var2 + 3] = T.readByte() & 255;
var11[var2 + 4] = T.readByte() & 255;
var11[var2 + 5] = T.readByte();
++var1;
}
if (d.at) {
return false;
} else {
this.ae = new int[var13 * 10][];
int var3;
for(var3 = 0; var3 < var13 * 10; var3 += 10) {
for(var15 = 0; var15 < 10; ++var15) {
this.ae[var3 + var15] = new int[this.aO];
}
for(var1 = 0; var1 < this.aO; ++var1) {
byte var8 = T.readByte();
byte var9 = T.readByte();
byte var10 = T.readByte();
byte var4 = T.readByte();
byte var5 = T.readByte();
byte var6 = T.readByte();
byte var7 = T.readByte();
this.ae[var3 + 0][var1] = var5;
this.ae[var3 + 1][var1] = var6;
this.ae[var3 + 2][var1] = var7;
this.ae[var3 + 3][var1] = 0;
this.ae[var3 + 4][var1] = 0;
this.ae[var3 + 5][var1] = 0;
this.ae[var3 + 6][var1] = var8;
if (var9 < 0) {
var16 = 1;
this.ae[var3 + 7][var1] = var10;
var15 = 0;
} else {
if (var10 == 0) {
var10 = (byte)var11[var9 * 6 + 2];
}
var16 = var11[var9 * 6 + 1];
var15 = var11[var9 * 6 + 5];
}
this.ae[var3 + 8][var1] = var16 & '\uffff';
this.ae[var3 + 7][var1] = var10;
this.ae[var3 + 9][var1] = var15;
}
}
Object var20 = null;
System.gc();
if (d.at) {
return false;
} else {
bU = new short[this.aO];
for(var3 = 0; var3 < this.aO; ++var3) {
bU[var3] = 0;
}
var15 = 0;
byte[][] var21 = new byte[var14][];
bY = new short[var14];
for(var3 = 0; var3 < var14; ++var3) {
short var22 = T.readShort();
T.readByte();
this.cF[var3] = T.readByte();
var21[var3] = new byte[var22];
bY[var3] = (short)var15;
var15 += var22;
for(var18 = 0; var18 < var22; ++var18) {
var21[var3][var18] = T.readByte();
}
}
cy = new byte[var15];
for(var3 = 0; var3 < var14; ++var3) {
for(var1 = 0; var1 < var21[var3].length; ++var1) {
cy[bY[var3] + var1] = var21[var3][var1];
}
var21[var3] = null;
}
var21 = (byte[][])null;
T.close();
T = null;
System.gc();
return true;
}
}
}
}
} catch (Exception var19) {
T = null;
return false;
}
}
public final void a(int var1, int var2, int var3, int var4, int var5, int var6) {
bQ = var1;
cm = var1;
cC = var3;
bK = var3;
int var18 = a.d(var4);
int var19 = a.a(var4);
int var20 = a.d(-var4);
this.t();
this.d(var5, 0);
int var9 = this.cf;
int var11 = this.bf;
int var12 = var9 * var19 - var11 * var18 >> 16;
var11 = -(var9 * var20 - var11 * var19) >> 16;
int var15 = var1 - var12;
int var16 = var2 - this.q;
int var17 = var3 - var11;
this.ae[this.bu + 3][0] = var15;
this.ae[this.bu + 4][0] = var16;
this.ae[this.bu + 5][0] = var17;
if (var15 < bQ) {
bQ = var15;
}
if (var15 > cm) {
cm = var15;
}
if (var17 < cC) {
cC = var17;
}
if (var17 > bK) {
bK = var17;
}
int var7;
for(var7 = 1; var7 < this.aO; ++var7) {
int var14 = this.ae[this.bu + 6][var7];
var15 = this.ae[this.bu + 3][var14];
var16 = this.ae[this.bu + 4][var14];
var17 = this.ae[this.bu + 5][var14];
this.d(var5, var7);
var9 = this.cf * var6 >> 16;
int var10 = this.q * var6 >> 16;
var11 = this.bf * var6 >> 16;
var12 = var9 * var19 - var11 * var18 >> 16;
var11 = -(var9 * var20 - var11 * var19) >> 16;
var15 -= var12;
var16 -= var10;
var17 -= var11;
this.ae[this.bu + 3][var7] = var15;
this.ae[this.bu + 4][var7] = var16;
this.ae[this.bu + 5][var7] = var17;
if (var15 < bQ) {
bQ = var15;
}
if (var15 > cm) {
cm = var15;
}
if (var17 < cC) {
cC = var17;
}
if (var17 > bK) {
bK = var17;
}
}
c.e = this.ae[this.bu + 3][4];
c.k = this.ae[this.bu + 4][3];
boolean var13 = true;
for(int var8 = 0; var13; ++var8) {
var7 = 1;
for(var13 = false; var7 < this.bJ - var8; ++var7) {
if (this.ae[this.bu + 5][this.ac[var7 - 1] & 255] < this.ae[this.bu + 5][this.ac[var7] & 255]) {
var13 = true;
int var21 = this.ac[var7 - 1];
this.ac[var7 - 1] = this.ac[var7];
this.ac[var7] = var21;
}
}
}
}
public final void d(int var1, int var2) {
int var7 = 0;
int var8 = 0;
int var9 = var1 >> 16;
boolean var10 = true;
short var12 = bU[var2];
byte var11 = cy[var12];
int var3;
int var4;
int var5;
if (var11 == 0) {
var3 = 0;
var4 = 0;
var5 = 0;
} else {
int var21 = var12 + 1;
int var6;
for(var6 = 0; var6 < var11; ++var6) {
var7 = var8;
if (cy[var21 + var6 * 4] == -1) {
break;
}
var8 = var6;
if ((cy[var21 + var6 * 4] & 255) > var9) {
break;
}
}
if (var6 == var11) {
var7 = var11 - 1;
var8 = var7;
}
if (var7 == var8) {
var3 = cy[var21 + var7 * 4 + 1] << 7;
var4 = cy[var21 + var7 * 4 + 2] << 7;
var5 = cy[var21 + var7 * 4 + 3] << 7;
} else {
int var13 = cy[var21 + var7 * 4] & 255;
int var20 = (cy[var21 + var8 * 4] & 255) - var13;
if (var20 == 0) {
var3 = (cy[var21 + var7 * 4 + 1] << 7) + 128;
var4 = (cy[var21 + var7 * 4 + 2] << 7) + 128;
var5 = (cy[var21 + var7 * 4 + 3] << 7) + 128;
} else {
var20 = (var1 - (var13 << 16)) / var20;
int var14 = cy[var21 + var7 * 4 + 1] << 7;
int var15 = cy[var21 + var7 * 4 + 2] << 7;
int var16 = cy[var21 + var7 * 4 + 3] << 7;
int var17 = (cy[var21 + var8 * 4 + 1] << 7) - var14;
int var18 = (cy[var21 + var8 * 4 + 2] << 7) - var15;
int var19 = (cy[var21 + var8 * 4 + 3] << 7) - var16;
var3 = var14 + (var17 * var20 + 'θ' >> 16) + 128;
var4 = var15 + (var18 * var20 + 'θ' >> 16) + 128;
var5 = var16 + (var19 * var20 + 'θ' >> 16) + 128;
}
}
}
this.cf = this.ae[this.bu + 0][var2] - (var3 >> 8);
this.q = this.ae[this.bu + 1][var2] - (var4 >> 8);
this.bf = this.ae[this.bu + 2][var2] - (var5 >> 8);
}
public final void b(Graphics var1) {
if (bH == this.aE) {
var1.setClip(au, aF, r, i);
int var2 = this.ae[this.bu + 7][2] * bF >> 16;
int var3 = cm - bQ;
int var4 = bK - cC;
int var5 = var3 * 176 >> 8;
int var6 = var4 * 144 >> 8;
int var7 = bQ + (var3 - var5 >> 1);
int var8 = aI - var6 + (var2 >> 1);
var1.setColor(H);
var1.fillArc(var7, var8, var5, var6, 0, 360);
}
}
public final void a(Graphics var1) {
int var6 = ba;
if (c.bH == 3) {
var6 = c.cy;
}
if (cL || cK) {
var1.setClip(au, aF, r, i);
int var2;
int var3;
int var4;
int var5;
int var7;
if (this.bj != -1) {
var1.setColor(this.cc[var6][0]);
if (bF < 65536) {
var7 = this.bj * bF >> 16;
if (var7 < 1) {
var7 = 1;
}
} else {
var7 = this.bj;
}
for(var2 = 0; var2 < this.bJ; ++var2) {
int var8 = this.ac[var2] >>> 8;
int var9;
if (var8 != 0) {
var4 = this.ac[var8++];
for(var3 = 0; var3 < var4; ++var3) {
var5 = this.ac[var8++];
var9 = this.ae[this.bu + 7][var5] * bF >> 16;
var9 += var7;
++var9;
var1.fillArc(this.ae[this.bu + 3][var5] - var9, this.ae[this.bu + 4][var5] - var9, var9 * 2, var9 * 2, 0, 360);
}
} else {
var5 = this.ac[var2] & 255;
if (var5 != 0) {
var9 = this.ae[this.bu + 7][var5] * bF >> 16;
var9 += var7;
++var9;
var1.fillArc(this.ae[this.bu + 3][var5] - var9, this.ae[this.bu + 4][var5] - var9, var9 * 2, var9 * 2, 0, 360);
}
}
}
}
for(var2 = 0; var2 < this.bJ; ++var2) {
var7 = this.ac[var2] >>> 8;
if (var7 == 0) {
var5 = this.ac[var2] & 255;
if (var5 != 0) {
if (this.ae[this.bu + 9][var5] != 0) {
this.b(var1, var5, bF, var6);
}
this.a(var1, var5, bF, var6);
}
} else {
var4 = this.ac[var7++];
for(var3 = 0; var3 < var4; ++var3) {
var5 = this.ac[var7 + var3];
if (this.ae[this.bu + 9][var5] != 0) {
this.b(var1, var5, bF, var6);
}
}
for(var3 = 0; var3 < var4; ++var3) {
var5 = this.ac[var7++];
this.a(var1, var5, bF, var6);
}
}
}
}
}
public static final short e(int var0, int var1, int var2) {
int var3 = (-3640 + 52 * var0 + ((5880 - 27 * var0) * var2 >> 8)) / 40 * r / 176;
return (short)(var3 + au);
}
public static final short c(int var0, int var1, int var2) {
int var3 = ((6600 + 18 * var0 - ((2360 + 15 * var0) * var2 >> 8)) / 40 - var1 * 112 / (var2 + 256)) * i / 208;
return (short)(var3 + aF);
}
public static final int o(int var0, int var1) {
return var0 * 112 / ((var1 >> 2) + 256) * i / 208;
}
public final void a(int var1, boolean var2) {
int[] var10000;
if (var2) {
var10000 = this.ae[this.bu + 8];
var10000[var1] |= 16777216;
} else {
var10000 = this.ae[this.bu + 8];
var10000[var1] &= -16777217;
}
}
public final void a(Graphics var1, int var2, int var3, int var4) {
int var5 = this.ae[this.bu + 7][var2];
int var7 = this.ae[this.bu + 8][var2];
int var6;
if ((var7 & 16777216) != 0) {
var6 = this.cc[var4][(var7 & 240) >> 4];
} else {
var6 = this.cc[var4][var7 & 15];
}
int var8 = var5 * var3 >> 16;
++var8;
var1.setColor(var6);
var1.fillArc(this.ae[this.bu + 3][var2] - var8, this.ae[this.bu + 4][var2] - var8, var8 * 2, var8 * 2, 0, 360);
}
public final void b(Graphics var1, int var2, int var3, int var4) {
int var5 = this.ae[this.bu + 7][var2];
int var7 = this.ae[this.bu + 8][var2];
int var6 = this.ae[this.bu + 9][var2];
int var8 = var5 * var3 >> 16;
++var8;
if (var6 != 0) {
var1.setColor(this.cc[var4][0]);
var1.fillArc(this.ae[this.bu + 3][var2] - var8, this.ae[this.bu + 4][var2] - var8 + var6, var8 * 2, var8 * 2, 0, 360);
}
}
public static final void C() {
bZ[0] = 0;
bV[0] = cG[31];
bZ[1] = 0;
bV[1] = cG[32];
bZ[2] = 0;
bV[2] = cG[33];
bZ[51] = 0;
bV[51] = cG[38];
bZ[53] = 0;
bV[53] = cG[39];
bZ[52] = cG[36];
bV[52] = cG[37];
bZ[54] = cG[40];
bV[54] = cG[41];
aU = 128;
X = 80;
f var10000 = c.C;
ca = l(cG[1], cG[6]);
var10000 = c.C;
ci = l(cG[2], cG[7]);
var10000 = c.C;
cI = l(cG[5], cG[10]);
var10000 = c.C;
cv = l(cG[3], cG[8]);
var10000 = c.C;
x = l(cG[4], cG[9]);
var10000 = c.C;
h = l(cG[11], cG[12]);
R = 86400 / cG[0];
ca <<= 16;
ci <<= 16;
cI <<= 16;
cv <<= 16;
x <<= 16;
h <<= 16;
ca /= R / 2;
ci /= R / 2;
cI /= R / 2;
cv /= R / 2;
x /= R / 2;
h /= R / 2;
k = 3342336;
e = 4980736;
k /= 300 / cG[0];
e /= 180 / cG[0];
k /= R;
e /= R;
cg = 0;
am = 0;
var10000 = c.C;
cr = k(4) + 3;
cd = 0;
cz = -1;
d();
var10000 = c.C;
aR = k(40) - 20;
var10000 = c.C;
ax = k(3) + 0;
y = -1;
var10000 = c.C;
av = k(8) + 19;
for(A = av; av == A; A = k(9) + 18) {
var10000 = c.C;
}
var10000 = c.C;
aQ = k(15) + 3;
for(bs = aQ; aQ == bs; bs = k(15) + 3) {
var10000 = c.C;
}
var10000 = c.C;
n = k(24) + 27;
for(N = n; n == N; N = k(24) + 27) {
var10000 = c.C;
}
at = aU;
aT = X;
U = 32;
ap = 0;
for(int var0 = 0; var0 < 3; ++var0) {
bA[0] = 0;
}
l();
aK = bo;
bw = aN;
Y = -1;
V = -1;
cE = aN;
cJ = false;
cj = true;
I();
}
public static final void l() {
al = System.currentTimeMillis();
if (ar) {
aB = al - aC;
} else {
aB = 0L;
ar = true;
}
if (aB < 0L) {
aB = 0L;
}
aC = al;
cE = aN;
aN = System.currentTimeMillis() + aX;
}
public static final void R() {
int[] var0 = new int[]{0, 2, 4, 30, 60, 360, 720, 1440, 10080};
l();
if (bx > 0 && e.g == 0 && c.bH == 0) {
aX += aB * (long)(var0[bx] - 1);
aN += aB * (long)(var0[bx] - 1);
}
if (aN / 1000L != Q / 1000L) {
bo = (int)((long)bo + (aN / 1000L - Q / 1000L));
Q = aN;
}
if (bv != -1 && (c.an[bD][bv] & 2) == 0) {
bv = -1;
}
if (e.g == 0) {
A();
U();
K();
c.d(at, l, aT, bH);
}
int var10000 = ay;
var10000 = aI;
if (cj) {
ay = e(at, l, aT);
aI = c(at, l, aT);
bF = o(106496, aT);
} else {
ay = at;
aI = aT;
}
cL = c.C.aE == bH;
if (cJ) {
c.I();
cJ = false;
}
}
public static final void K() {
f var10000;
switch(bO) {
case 0:
O();
break;
case 1:
P();
break;
case 2:
f();
break;
case 3:
ad();
break;
case 5:
q();
break;
case 6:
k();
break;
case 7:
B();
break;
case 8:
w();
break;
case 9:
W();
break;
case 10:
V();
break;
case 11:
v();
break;
case 99:
if (s() || bd) {
var10000 = c.C;
switch(k(4)) {
case 1:
s(12);
break;
case 2:
s(17);
break;
case 3:
f(13, 1);
break;
default:
s(4);
}
bd = false;
}
break;
case 100:
if (ar) {
c.au = a(true);
if (s() && c.aE == 10) {
var10000 = c.C;
switch(k(4)) {
case 1:
f(15, 1);
break;
case 2:
case 3:
f(13, 1);
break;
default:
s(14);
}
}
}
break;
case 101:
s();
break;
default:
y(0);
}
}
public static final void A() {
long var1 = ((long)bo - bc) / (long)cG[0];
ck = 0;
if (var1 > 0L) {
ck = (int)var1;
bc = (long)bo;
if (bO == 7) {
L = (int)((long)L - ((long)ca * var1 >> 18));
E = (int)((long)E - ((long)ci * var1 >> 18));
D = (int)((long)D - ((long)cv * var1 >> 18));
} else if (c.cg == 1) {
L = (int)((long)L - ((long)ca * var1 >> 17));
E = (int)((long)E - ((long)ci * var1 >> 17));
K = (int)((long)K - ((long)cI * var1 >> 16));
D = (int)((long)D - ((long)cv * var1 >> 17));
} else {
L = (int)((long)L - ((long)ca * var1 >> 16));
E = (int)((long)E - ((long)ci * var1 >> 16));
K = (int)((long)K - ((long)cI * var1 >> 16));
D = (int)((long)D - ((long)cv * var1 >> 16));
}
bL = (int)((long)bL - ((long)x * var1 >> 16));
Y();
int var3 = 9830 + (L + E) / 2;
K = e(K, var3);
int var0 = aG - cG[28];
if (var0 < 0) {
var0 = var0 * cG[29] >> 8;
} else {
var0 = var0 * cG[30] >> 8;
}
s = (int)((long)s + ((long)var0 * var1 >> 16));
s = k(s, 0);
s = e(s, aM);
if (cg > 0) {
cs = (int)((long)cs + (long)k * var1);
}
if (am > 0) {
p = (int)((long)p + (long)e * var1);
}
}
}
public static final void E() {
at = 240;
aT = 50;
S = aU;
aq = X;
a(S, aq, bH, 11, 2);
}
public static final void F() {
long var1 = ((long)bo - bc) / (long)cG[0];
long var3 = (long)bo - bc;
int var5 = (int)(var3 / 3600L);
int var6 = var5 / 24;
ck = 0;
if (var1 > 0L) {
ck = (int)var1;
bc = (long)bo;
L = (int)((long)L - ((long)ca * var1 >> 17));
E = (int)((long)E - ((long)ci * var1 >> 17));
D = (int)((long)D - ((long)cv * var1 >> 17));
K = (int)((long)K + ((long)h * var1 >> 16));
bL = (int)((long)bL - ((long)x * var1 >> 16));
Y();
int var8 = 9830 + (L + E) / 2;
K = e(K, var8);
int var0 = aG - cG[28];
if (var0 < 0) {
var0 = var0 * cG[29] >> 8;
} else {
var0 = var0 * cG[30] >> 8;
}
s = (int)((long)s + ((long)var0 * var1 >> 16));
s = k(s, 0);
s = e(s, aM);
if (cg > 0) {
cs = (int)((long)cs + (long)k * var1);
}
if (am > 0) {
p = (int)((long)p + (long)e * var1);
}
}
if (var6 >= 5) {
var5 = 120;
cJ = true;
}
if (var5 > 12) {
for(int var7 = 0; var7 < var5 / 12; ++var7) {
x(10);
x(0);
}
cs = 0;
cg = 0;
p = 0;
am = 0;
}
U();
if (var3 > 600L) {
if (ah > af) {
j(14);
}
if (as > af) {
j(15);
}
}
}
public static void x(int var0) {
int var2 = s >> 8;
f var10001 = c.C;
var2 += k(127);
f var10000;
int var4;
int var5;
int var6;
int var7;
if (var2 > 127 && c.l(0, 2) < 5) {
if (var0 != 10) {
var10000 = c.C;
var6 = k(40);
var10000 = c.C;
var7 = k(256);
var4 = 128 + (var6 * a.d(var7) >> 16);
var5 = 128 + (var6 * a.a(var7) >> 16);
c.a(var0, var4, 0, var5, 2, 7, aN);
}
} else {
int var8 = bH;
for(int var3 = 0; var3 < 3; ++var3) {
if (var8 >= 3) {
var8 -= 3;
}
int var1 = c.l(0, var8);
var1 += c.l(10, var8);
if (var1 < 5) {
if (var8 == 2 && var0 == 10) {
return;
}
var10000 = c.C;
var6 = k(40);
var10000 = c.C;
var7 = k(256);
var4 = 128 + (var6 * a.d(var7) >> 16);
var5 = 128 + (var6 * a.a(var7) >> 16);
c.a(var0, var4, 0, var5, var8, 7, aN);
return;
}
++var8;
}
}
}
public static final void U() {
c = bL;
int var4 = c.l(0, 0);
var4 += c.l(0, 1);
var4 += c.l(0, 2);
int var5 = c.l(10, 0);
var5 += c.l(10, 1);
c -= var4 * cG[42];
c -= var5 * cG[43];
k(c, 0);
aG = (L + E + K + D + c) / 5;
aP = (L + E + K) / 3;
aG += aG * aR / 100;
if (cd == cr) {
aG -= 6553;
}
if (cd > cr) {
aG -= 22936;
}
int var3 = Q();
if (var3 > cr * 4) {
if (var3 > cr * 8) {
aG -= 19660;
} else {
aG -= 9830;
}
}
if (cl) {
aG -= 9830;
}
if (bX) {
aG -= 9830;
}
aG = e(aG, 32767);
aG = k(aG, 0);
br = (32767 - L) * cG[13] >> 8;
ak = (32767 - E) * cG[14] >> 8;
ab = (32767 - K) * cG[17] >> 8;
bE = (32767 - c) * cG[16] >> 8;
aV = (32767 - D) * cG[15] >> 8;
aZ = cs;
bi = p;
int var0 = c.cg == 1 ? 64 : 256;
int var1 = c.e(3, 0);
var0 += (c.an[0][var1] & 2) != 0 ? 128 : -96;
var0 += bH == 0 ? 64 : 0;
var0 -= aG >> 9;
var0 += ab >> 11;
ah = br * var0 >> 8;
var0 = c.cg == 1 ? 64 : 256;
var1 = c.e(4, 0);
var0 += (c.an[0][var1] & 2) != 0 ? 128 : -96;
var0 += bH == 0 ? 64 : 0;
var0 -= aG >> 10;
var0 += bE >> 11;
as = ak * var0 >> 8;
var0 = c.cg == 1 ? 512 : 160;
var1 = c.e(9, 1);
var0 += (c.an[1][var1] & 2) != 0 ? 96 : -96;
if (bH == 1) {
var1 = c.e(8, 1);
var0 += (c.an[1][var1] & 2) != 0 ? -384 : 64;
}
var0 += aG >> 10;
var0 += bE >> 11;
var0 += 32767 - aG >> 9;
var0 += bO == 7 ? 160 : 0;
ag = ab * var0 >> 8;
var0 = c.cg == 1 ? 0 : 256;
boolean var2 = c.e(bH);
var0 += var2 ? 128 : -128;
var2 = c.e(bH + 1);
var0 += var2 ? 96 : 0;
var2 = c.e(bH + 2);
var0 += var2 ? 96 : 0;
var0 += aG >> 8;
var0 -= 32767 - aG >> 11;
bC = aV * var0 >> 8;
var0 = c.cg == 1 ? 0 : 128;
var0 += bH == 2 ? 64 : -64;
var0 -= aG >> 10;
var0 -= 32767 - aG >> 11;
var0 = k(var0, 0);
int var10000 = bE * var0 >> 8;
var0 = c.cg == 1 ? 128 : 512;
var0 += bH == 2 ? 80 : 0;
var0 -= s >> 9;
var0 -= 32767 - aG >> 11;
aY = aZ * var0 >> 8;
var0 = c.cg == 1 ? 128 : 512;
var0 += bH == 2 ? 80 : 0;
var0 -= s >> 9;
var0 += 32767 - aG >> 11;
v = bi * var0 >> 8;
af = 8191 + aG >> 2;
y();
a((byte)1, ah);
a((byte)2, as);
a((byte)3, bC);
a((byte)5, ag);
a((byte)7, v);
a((byte)6, aY);
aW = e();
}
public static final void y() {
f = 0;
}
public static final void a(byte var0, int var1) {
if (var1 >= af && f < 8) {
O[f] = var0;
a[f] = var1;
++f;
}
}
public static final int e() {
for(int var2 = 1; var2 <= f - 1; ++var2) {
for(int var3 = 0; var3 < f - var2; ++var3) {
if (a[var3] < a[var3 + 1]) {
byte var0 = O[var3];
int var1 = a[var3];
O[var3] = O[var3 + 1];
a[var3] = a[var3 + 1];
O[var3 + 1] = var0;
a[var3 + 1] = var1;
}
}
}
if (f > 0) {
return O[0];
} else {
return 0;
}
}
public static final void e(int var0) {
L += bZ[var0];
if (!m(var0)) {
D += bV[var0];
}
if (aW == 1) {
int var10001 = bV[var0] * cG[18];
f var10002 = c.C;
D += var10001 >> 8;
}
if (var0 == aQ) {
D += bV[var0] * cG[23] >> 8;
}
K += bZ[var0] >> 2;
++cg;
Y();
i(var0);
A(var0);
}
public static final void a(int var0) {
E += bZ[var0];
if (!m(var0)) {
D += bV[var0];
}
if (aW == 2) {
int var10001 = bV[var0] * cG[19];
f var10002 = c.C;
D += var10001 >> 8;
}
if (var0 == av) {
D += bV[var0] * cG[24] >> 8;
}
K += bZ[var0] >> 3;
++am;
Y();
i(var0);
A(var0);
}
public static final void B(int var0) {
if (!m(var0)) {
D += bV[var0];
}
if (var0 == ax) {
D += bV[var0] * cG[35] >> 8;
}
Y();
i(var0);
A(var0);
}
public static final void i(int var0, int var1) {
if (var0 != -1) {
byte var2 = c.ch[var1][var0];
if (c.aS[var1][var0] < 255) {
++c.aS[var1][var0];
}
L -= bZ[var2] >> 3;
if (!m(var2)) {
D += bV[var2];
}
if (aW == 3) {
D += bV[var2] * cG[20] >> 8;
}
if (var2 == n) {
D += bV[var2] * cG[25] >> 8;
}
K -= bZ[var2] >> 3;
Y();
i(var2);
A(var2);
}
}
public static final void h(int var0) {
L -= bZ[var0] >> 2;
if (aW == 3) {
D += bV[var0] * cG[20] >> 8;
}
if (var0 == n) {
D += bV[var0] * cG[25] >> 8;
}
K -= bZ[var0] >> 3;
Y();
A(var0);
}
public static final void q(int var0) {
if (bL < 26213) {
D += bV[var0];
} else {
D -= bV[var0] << 1;
}
bL = 32767;
ap = bo;
k(D, 0);
e(D, 32767);
i(var0);
A(var0);
}
public static final void Y() {
L = k(L, 0);
L = e(L, 32767);
E = k(E, 0);
E = e(E, 32767);
D = k(D, 0);
D = e(D, 32767);
K = k(K, 0);
K = e(K, 32767);
c = k(c, 0);
c = e(c, 32767);
bL = k(bL, 0);
bL = e(bL, 32767);
}
public static int k(int var0, int var1) {
return var0 < var1 ? var1 : var0;
}
public static int e(int var0, int var1) {
return var0 > var1 ? var1 : var0;
}
public static final void i(int var0) {
int var1 = -1;
if (cz == var0) {
++cd;
} else {
cd = 0;
cz = var0;
}
int var2;
for(var2 = 0; var2 < 5; ++var2) {
if (ct[var2] == var0) {
var1 = var2;
break;
}
}
if (var1 == -1) {
for(var2 = 4; var2 > 0; --var2) {
cB[var2] = cB[var2 - 1];
ct[var2] = ct[var2 - 1];
}
cB[0] = 0;
ct[0] = (short)var0;
} else {
short var3 = cB[var1];
short var4;
for(var4 = ct[var1]; var1 > 0; --var1) {
cB[var1] = cB[var1 - 1];
ct[var1] = ct[var1 - 1];
}
cB[0] = (short)var3;
ct[0] = (short)var4;
++cB[0];
}
}
public static final int Q() {
int var0 = 0;
short var1;
for(var1 = 0; var0 < 5; ++var0) {
if (ct[var0] != -1 && cB[var0] > var1) {
var1 = cB[var0];
}
}
return var1;
}
public static final boolean m(int var0) {
if (cz == var0 && cd >= cr) {
return true;
} else {
for(int var1 = 0; var1 < 5; ++var1) {
if (ct[var1] == var0 && cB[var1] >= cr * 4) {
return true;
}
}
return false;
}
}
public static final void d() {
for(int var0 = 0; var0 < 5; ++var0) {
cB[var0] = 0;
ct[var0] = -1;
}
}
public static final void a(String var0) {
try {
T = new DataInputStream((new String("")).getClass().getResourceAsStream(var0));
int var1;
for(var1 = 0; var1 < 45; ++var1) {
cG[var1] = T.readShort();
}
bZ = new short[55];
bV = new short[55];
for(var1 = 3; var1 < 51; ++var1) {
bZ[var1] = T.readShort();
bV[var1] = T.readShort();
}
T.close();
T = null;
} catch (Exception var2) {
T = null;
}
}
public static final void a(int var0, int var1) {
int var10000 = j;
j = var0;
d = var1;
long var2 = aN;
}
public static final void C(int var0) {
if (bO != var0) {
int var10000 = bO;
bO = var0;
g = aN;
}
}
public static final boolean aa() {
S = aU;
aq = X;
ch = 1;
return true;
}
public static final boolean X() {
int var0 = c.e(11, 2);
if (var0 != -1 && (c.an[2][var0] & 2) != 0) {
S = aU;
aq = X;
ch = 2;
return true;
} else {
return false;
}
}
public static final boolean v(int var0) {
int var2 = c.l(0, bH);
var2 += c.l(10, bH);
switch(bH) {
case 0:
case 1:
default:
int var1 = s >> 8;
f var10001 = c.C;
var1 += k(127);
if (var1 > 127 && c.l(0, 2) < 5) {
c(80);
ch = 2;
return true;
}
break;
case 2:
if (var2 < 5) {
c(80);
ch = 2;
return true;
}
}
int var4 = bH;
if (var2 < 5) {
c(80);
return true;
} else {
for(int var3 = 0; var3 < 2; ++var3) {
++var4;
if (var4 >= 3) {
var4 -= 3;
}
var2 = c.l(0, var4);
var2 += c.l(10, var4);
if (var2 < 5) {
c(80);
ch = var4;
return true;
}
}
return false;
}
}
public static final boolean z() {
return (ao & 768) != 0;
}
public static final boolean c() {
if ((ao & 768) != 0) {
switch(j) {
case 2:
case 3:
case 12:
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 23:
case 30:
case 31:
case 33:
case 34:
case 35:
case 37:
long var0 = (aN - bn) / 1000L;
if (var0 >= 0L && var0 <= 30L) {
if ((ao & 512) != 0) {
if (bo - bA[2] < 120) {
bX = true;
}
for(int var2 = 2; var2 > 0; --var2) {
bA[var2] = bA[var2 - 1];
}
bA[0] = bo;
ch = by;
ao |= 64;
} else {
ch = bH;
}
ao &= -769;
S = aU;
aq = X;
return true;
}
ao &= -833;
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 13:
case 20:
case 21:
case 22:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 32:
case 36:
}
}
return false;
}
public static final boolean t(int var0) {
int var1;
if (var0 == 1) {
var1 = c.e(3, 0);
} else {
var1 = c.e(4, 0);
}
if (var1 != -1 && (c.an[0][var1] & 2) != 0) {
S = c.bT[0][var1];
aq = c.cd[0][var1];
ch = 0;
return true;
} else {
S = 100;
aq = 100;
ch = 0;
return false;
}
}
public static final int j() {
n();
if (b != -1 && (c.an[bT][b] & 2) != 0) {
switch(c.bW[bT][b]) {
case 8:
S = 100;
aq = 100;
ch = bT;
break;
case 34:
S = 100;
aq = 200;
ch = bT;
break;
default:
S = c.bL[bT][b];
aq = c.aJ[bT][b];
ch = bT;
}
bv = b;
bD = bT;
return c.bW[bD][bv];
} else {
return 0;
}
}
public static final void n() {
int var1 = -1;
int var2 = -1;
int var3 = 10;
int var4 = 0;
int var5 = bH;
int var0;
for(int var6 = 0; var6 < 3; ++var6) {
var0 = c.a(var5);
var4 = 0;
if (var0 != -1 && (c.an[var5][var0] & 2) != 0) {
var4 = aW == 3 ? 288 : 128;
if (bH == var5) {
var4 += 128;
}
var4 -= c.aS[var5][var0] >> 2;
}
if (var4 > var3) {
var3 = var4;
var1 = var0;
var2 = var5;
}
++var5;
var5 %= 3;
}
var0 = c.e(8, 1);
if (var0 != -1) {
if ((c.an[1][var0] & 2) != 0) {
var4 = aW == 3 ? 128 : 0;
if (bH == 1) {
var4 += 128;
}
var4 -= c.aS[1][var0] >> 2;
}
if (var4 > var3) {
var1 = var0;
var2 = 1;
}
}
if (var1 == -1) {
var0 = c.e(34, 2);
if (var0 != -1 && bH == 2) {
var1 = var0;
var2 = 2;
}
}
b = var1;
bT = var2;
}
public static final void l(int var0) {
int var1;
int var2;
switch(var0) {
case 20:
cs = 0;
--cg;
var1 = at - (36 * a.d(U) >> 16);
var2 = aT + (36 * a.a(U) >> 16);
var1 = k(var1, 80);
var1 = e(var1, 192);
var2 = k(var2, 64);
var2 = e(var2, 200);
c.a(0, var1, 0, var2, bH, 7, aN);
break;
case 21:
p = 0;
--am;
if (bH != 2) {
var1 = at - (36 * a.d(U) >> 16);
var2 = aT + (36 * a.a(U) >> 16);
var1 = k(var1, 80);
var1 = e(var1, 192);
var2 = k(var2, 64);
var2 = e(var2, 200);
c.a(10, var1, 0, var2, bH, 7, aN);
}
}
aW = 0;
be = aN;
if (bH == 2) {
ao |= 2;
} else {
ao |= 1;
}
}
public static final void j(int var0) {
byte[] var10000;
int var1;
if (var0 == 14) {
var1 = c.e(3, 0);
if (var1 != -1 && (c.an[0][var1] & 2) != 0) {
var10000 = c.an[0];
var10000[var1] &= -3;
e(m);
}
} else {
var1 = c.e(4, 0);
if (var1 != -1 && (c.an[0][var1] & 2) != 0) {
var10000 = c.an[0];
var10000[var1] &= -3;
a(t);
}
}
}
public static final int J() {
if (c()) {
if (j == 2 && bH == ch) {
ao &= -65;
if (f(S, aq, 10)) {
return 2;
}
}
cu = 2;
cH = 11;
cH = 10;
return 4;
} else {
ao &= -65;
if (X()) {
cu = 22;
if (bL < 26213) {
cH = 11;
} else {
cH = 10;
}
return 4;
} else {
int var0;
int var1;
for(int var2 = 0; var2 < f; ++var2) {
switch(O[var2]) {
case 1:
case 2:
if (t(O[var2])) {
if (O[var2] == 1) {
cu = 14;
} else {
cu = 15;
}
cH = 11;
return 4;
}
if (var2 == 0 && a[var2] > 26624) {
if (ch != bH) {
cu = 2;
cH = 11;
return 4;
}
if (f(S, S, 10)) {
return 2;
}
cu = 2;
cH = 10;
return 4;
}
break;
case 3:
if ((var0 = j()) != 0) {
var1 = p(var0);
if (var1 != -1) {
return var1;
}
}
case 4:
default:
break;
case 5:
if (aa()) {
cu = 8;
cH = 10;
return 4;
}
break;
case 6:
case 7:
if (v(O[var2])) {
if (O[var2] == 6) {
cu = 20;
} else {
cu = 21;
}
if (ch != bH) {
cH = 11;
} else {
cH = 10;
}
return 4;
}
}
}
var0 = j();
if (var0 != 0) {
var1 = p(var0);
if (var1 != -1) {
return var1;
}
}
if (bO == 3) {
return a();
} else {
return 1;
}
}
}
}
public static final int p(int var0) {
switch(var0) {
case 5:
case 24:
case 25:
case 26:
case 27:
case 28:
cu = 16;
cH = 12;
return 12;
case 6:
case 7:
case 16:
case 20:
case 21:
case 32:
case 36:
if (j != 19) {
cu = 19;
cH = 13;
return 13;
}
return 19;
case 8:
case 34:
case 37:
if (j != 35) {
cu = 35;
cH = 11;
return 11;
}
return 35;
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 19:
default:
return -1;
case 17:
case 22:
case 33:
case 35:
cu = 37;
cH = 12;
return 37;
case 18:
case 30:
if (j != 33) {
cu = 33;
cH = 11;
return 11;
}
return 33;
case 23:
case 29:
case 31:
if (j != 23) {
cu = 23;
cH = 13;
return 13;
} else {
return 23;
}
}
}
public static final int a() {
long var0 = (aN - g) / 1000L;
int var10000 = (32767 - aG >> 8) + 10;
f var10001 = c.C;
int var2 = var10000 + k(1 + (aG >> 9));
if (var0 > (long)var2) {
return 4;
} else if (P < 0) {
switch(j) {
case 2:
w = 4;
var10001 = c.C;
P = 5 + k(6);
return 2;
case 3:
default:
w = 1;
var10001 = c.C;
P = 5 + k(6);
return 3;
case 31:
w = 21;
var10001 = c.C;
P = 1 + k(3);
return 31;
}
} else {
if (P > 0) {
--P;
} else {
P = -1;
r();
switch(j) {
case 2:
case 3:
default:
if (bH == 2) {
a(112, 100, 7, 30);
}
a(112, 60, 39, 31);
a(64, 40, 21, 31);
a(16, 40, 2, 3);
a(48, 40, 17, 2);
a(80, 40, 16, 2);
a(96, 40, 18, 2);
a(112, 40, 13, 3);
a(80, 40, 42, 3);
a(96, 40, 41, 3);
break;
case 31:
a(112, 60, 39, 31);
a(112, 60, 19, 31);
a(16, 40, 2, 3);
a(48, 40, 17, 2);
a(80, 40, 16, 2);
a(96, 40, 18, 2);
a(112, 40, 13, 3);
a(80, 40, 42, 3);
a(96, 40, 41, 3);
}
if (u() != -1) {
w = az;
return aD;
}
}
return 1;
}
}
public static final int y(int var0) {
h();
f var10000 = c.C;
int var1 = k(10);
int var2 = bH;
if (c.cg == 1) {
var2 = 1;
}
f var10001;
if (bt) {
var10001 = c.C;
var2 += k(2);
if (var2 >= 3) {
var2 -= 3;
}
bt = false;
}
if (var0 == 1) {
switch(j) {
case 2:
case 3:
case 8:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 33:
case 35:
case 37:
var0 = J();
break;
case 4:
case 6:
case 10:
case 11:
case 12:
case 13:
case 36:
if (cu != 0) {
var0 = cH;
} else if (var1 < 3) {
var0 = 11;
} else {
var0 = 10;
}
case 5:
case 7:
case 9:
case 24:
case 25:
case 32:
case 34:
default:
break;
case 14:
case 15:
var0 = 3;
}
}
if (var0 == 11) {
int var3 = aG >> 1;
var10001 = c.C;
var1 = var3 + k(6553);
if (var1 < 9830) {
var0 = 10;
}
}
switch(var0) {
case 1:
case 5:
case 7:
case 9:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 32:
case 34:
default:
return 0;
case 2:
case 3:
case 31:
return b(var0, 1, w);
case 4:
case 6:
return u(var0);
case 8:
return g(var0);
case 10:
case 11:
case 12:
case 13:
case 36:
if (cu != 0) {
a(S, aq, ch, var0, cu);
cu = 0;
return var0;
} else {
if (var2 == bH) {
c(0);
return a(S, aq, var2, var0, 3);
}
return a(aU, X, var2, var0, 3);
}
case 14:
case 15:
return h(var0, 4);
case 16:
case 17:
case 18:
case 37:
return n(var0, 1);
case 19:
return n(19, 4);
case 20:
case 21:
return b(var0, 4);
case 22:
return g(var0, 4);
case 23:
case 33:
case 35:
return n(var0, 4);
case 30:
return w(3);
}
}
public static final int g(int var0, int var1) {
S();
int var2 = c.e(11, 2);
if (var2 != -1 && (c.an[2][var2] & 2) != 0) {
switch(var0) {
case 22:
if (bL < 26213) {
f(23, 1);
} else {
s(2);
}
default:
a(var0, var1);
c.L();
C(8);
return var0;
}
} else {
return b(2, 1, 4);
}
}
public static final boolean w() {
if (s()) {
if (B == 2) {
f(3, 1);
return false;
}
if (B != 23 && B != 3) {
y(d);
return true;
}
b(j);
s(24);
}
return false;
}
public static final void b(int var0) {
switch(var0) {
case 22:
q(52);
c += cG[36];
c = c > 32767 ? 32767 : c;
int var10000 = cD;
c.i();
default:
aW = 0;
}
}
public static final int u(int var0) {
s(0);
a((int)var0, 1);
C(0);
return var0;
}
public static final boolean O() {
if (s()) {
y(d);
return true;
} else {
return false;
}
}
public static final int a(int var0, int var1, int var2, int var3, int var4) {
byte var5 = 30;
switch(var3) {
case 10:
s(8);
var5 = 30;
break;
case 11:
case 12:
case 13:
s(9);
var5 = 60;
break;
case 36:
s(49);
var5 = -30;
}
b(var0, var1, var5, var2);
a(var3, var4);
C(1);
return var3;
}
public static final boolean P() {
short var0 = 0;
short var1 = 0;
s();
if (j == 12 && cA == -1) {
if (bv != -1) {
var0 = c.bL[bD][bv];
var1 = c.aJ[bD][bv];
c(var0, var1);
}
if (f(var0, var1, 10)) {
y(d);
return true;
}
}
if (j == 13 && cA == -1) {
if (bv != -1) {
byte var2 = c.bW[bD][bv];
short var3 = c.w[var2][12];
short var4 = c.w[var2][13];
int var5 = c.bL[bD][bv] + var3;
int var6 = c.aJ[bD][bv] + var4;
c(var5, var6);
if (f(var5, var6, 10)) {
y(d);
return true;
} else {
if (a(true)) {
ao &= -65;
}
return false;
}
} else {
y(1);
return true;
}
} else if (a(true)) {
y(d);
return true;
} else {
return false;
}
}
public static final int h(int var0, int var1) {
int var2;
byte var3;
short var4;
short var5;
switch(var0) {
case 14:
var2 = c.e(3, 0);
if (var2 != -1) {
var3 = c.bW[0][var2];
var4 = c.w[var3][12];
var5 = c.w[var3][13];
at = c.bL[0][var2] + var4;
l = c.O[0][var2];
aT = c.aJ[0][var2] + var5;
U = c.cq[0][var2];
}
s(50);
break;
case 15:
var2 = c.e(4, 0);
if (var2 != -1) {
var3 = c.bW[0][var2];
var4 = c.w[var3][12];
var5 = c.w[var3][13];
at = c.bL[0][var2] + var4;
l = c.O[0][var2];
aT = c.aJ[0][var2] + var5;
U = c.cq[0][var2];
}
s(50);
}
a(var0, var1);
C(2);
return var0;
}
public static final boolean f() {
if (s()) {
switch(B) {
case 10:
case 11:
j(j);
s(51);
break;
case 50:
if (j == 15) {
f(11, 4);
} else {
f(10, 5);
}
break;
case 51:
default:
S = at + 32;
aq = aT;
a(S, aq, bH, 36, 3);
return true;
}
}
return false;
}
public static final int b(int var0, int var1, int var2) {
S();
label34:
switch(var0) {
case 2:
case 3:
f var10001;
switch(var2) {
case 1:
if (aG >> 12 > 3) {
s(1);
} else if (B == 2) {
s(2);
} else {
s(3);
}
break label34;
case 2:
case 3:
case 12:
case 16:
case 17:
case 41:
case 42:
s(var2);
break label34;
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 18:
case 20:
case 21:
case 22:
case 23:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
default:
if (U > 128) {
aw = 240;
} else {
aw = 32;
}
if (aG >> 12 > 3) {
s(4);
} else {
s(5);
}
break label34;
case 13:
var10001 = c.C;
f(var2, k(4));
break label34;
case 14:
var10001 = c.C;
f(var2, k(2) + 2);
break label34;
case 15:
var10001 = c.C;
f(var2, k(4));
break label34;
case 19:
s(19);
break label34;
}
case 4:
default:
s(1);
a((int)var0, 1);
C(0);
return var0;
case 31:
switch(var2) {
case 19:
f(39, 2);
break;
case 21:
default:
f(21, 20);
}
}
a(var0, var1);
C(3);
return var0;
}
public static final boolean ad() {
U = j(aw, U);
if (z()) {
y(1);
return true;
} else if (s()) {
y(d);
return true;
} else {
return false;
}
}
public static final int w(int var0) {
byte var1 = 60;
s(9);
bh = (long)bo;
bl = 0;
b(aU, X, var1, bH);
a((int)30, var0);
C(9);
return 30;
}
public static final boolean W() {
boolean var2 = s();
if (z()) {
y(1);
return true;
} else {
bl = (int)((long)bl + (long)a.b(100) * (aN - cE) / 1000L);
bl &= 255;
int var0 = 128 + (40 * a.d(bl) >> 16);
int var1 = 128 + (40 * a.a(bl) >> 16);
c(var0, var1);
a(false);
if (var2 && (long)bo - bh > 20L) {
h(54);
y(2);
return true;
} else {
return false;
}
}
}
public static final int b(int var0, int var1) {
S();
switch(var0) {
case 20:
s(43);
break;
case 21:
if (!d.Y) {
s(45);
} else {
s(47);
}
}
a(var0, var1);
C(6);
return var0;
}
public static final boolean k() {
if (s()) {
switch(B) {
case 43:
l(j);
s(44);
return false;
case 44:
case 46:
default:
y(d);
return true;
case 45:
l(j);
s(46);
return false;
case 47:
l(j);
s(48);
return false;
}
} else {
return false;
}
}
public static final int n(int var0, int var1) {
if (bv != -1 && c.br[bD][bv] == 0L) {
c.br[bD][bv] = aN;
}
switch(var0) {
case 16:
c.n(bv, bD);
s(25);
break;
case 17:
s(12);
break;
case 18:
s(20);
break;
case 19:
m(bv, bD);
s(20);
case 20:
case 21:
case 22:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 34:
case 36:
default:
break;
case 23:
m(bv, bD);
s(34);
break;
case 33:
m(bv, bD);
s(35);
break;
case 35:
aw = 177;
s(4);
break;
case 37:
s(13);
cu = 37;
var1 = 12;
}
a(var0, var1);
C(5);
return var0;
}
public static final boolean q() {
if (z()) {
i(bv, bD);
y(1);
return true;
} else {
byte[] var10000;
int var10001;
switch(j) {
case 19:
default:
break;
case 23:
if (bv != -1) {
var10000 = c.an[bD];
var10001 = bv;
var10000[var10001] = (byte)(var10000[var10001] | 16);
}
case 35:
U = j(aw, U);
break;
case 33:
if (bv != -1) {
var10000 = c.an[bD];
var10001 = bv;
var10000[var10001] &= -5;
var10000 = c.an[bD];
var10001 = bv;
var10000[var10001] = (byte)(var10000[var10001] | 8);
c.C.a(13, bD, bv);
int var2 = (int)(aN >> 6) & 15;
short[] var3;
switch(c.bW[bD][bv]) {
case 18:
default:
var3 = c.bg[bD];
var10001 = bv;
var3[var10001] = (short)(var3[var10001] + (15 - var2));
break;
case 30:
var3 = c.bg[bD];
var10001 = bv;
var3[var10001] = (short)(var3[var10001] + (var2 >> 1));
var3 = c.ag[bD];
var10001 = bv;
var3[var10001] = (short)(var3[var10001] + var2);
}
}
}
if (!s() && bv != -1) {
return false;
} else {
long var0;
if (bv != -1) {
var0 = (aN - c.br[bD][bv]) / 1000L;
} else {
var0 = 100L;
}
switch(j) {
case 16:
case 17:
case 18:
case 37:
if (var0 >= 0L && var0 <= 20L) {
c.a(bv, bD, U);
cu = 16;
y(12);
return true;
}
i(bv, bD);
y(2);
return true;
case 19:
if (var0 >= 0L && var0 <= 20L) {
f(26, 3);
return false;
}
i(bv, bD);
S();
y(4);
return true;
case 20:
case 21:
case 22:
case 24:
case 25:
case 26:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 34:
case 36:
default:
y(d);
return true;
case 23:
if (var0 >= 0L && var0 <= 20L) {
f(34, 3);
return false;
}
i(bv, bD);
if (bv != -1) {
var10000 = c.an[bD];
var10001 = bv;
var10000[var10001] &= -17;
}
y(4);
return true;
case 33:
if (var0 >= 0L && var0 <= 20L) {
s(35);
return false;
}
i(bv, bD);
if (bv != -1) {
var10000 = c.an[bD];
var10001 = bv;
var10000[var10001] &= -9;
var10000 = c.an[bD];
var10001 = bv;
var10000[var10001] = (byte)(var10000[var10001] | 4);
}
y(4);
return true;
case 35:
if (var0 >= 0L && var0 <= 20L) {
f var4 = c.C;
switch(k(6)) {
case 1:
f(15, 2);
break;
case 2:
f(14, 2);
if (c.bW[bD][bv] == 34) {
var10000 = c.an[bD];
var10001 = bv;
var10000[var10001] &= -3;
}
break;
case 3:
s(17);
break;
case 4:
f(13, 1);
break;
default:
s(4);
}
return false;
} else {
i(bv, bD);
y(4);
return true;
}
}
}
}
}
public static final int g(int var0) {
S();
s(27);
bN = (long)bo;
aw = 128;
a((int)var0, 8);
C(7);
return var0;
}
public static final boolean B() {
if (c.cg == 1) {
K += h * ck >> 15;
} else {
K += h * ck >> 12;
}
K = e(K, 32767);
U = j(aw, U);
switch(B) {
case 27:
case 28:
if ((ao & 512) != 0) {
cu = 1;
s(29);
return true;
}
}
if (s()) {
switch(B) {
case 27:
f(28, 5);
c.C.a(5, true);
c.C.a(6, true);
break;
case 28:
if ((long)bo - bN > 30L) {
int var0 = J();
if (cu != 8 && var0 != 1) {
s(29);
break;
}
}
f(28, 5);
break;
case 29:
default:
K += 3276;
K = e(K, 32767);
y(4);
c.C.a(5, false);
c.C.a(6, false);
return true;
}
}
return false;
}
public static final void c(int var0) {
boolean var2 = true;
byte var3;
if (bH == 0) {
var3 = 7;
} else {
var3 = 10;
}
while(var2) {
f var10000 = c.C;
int var1 = k(var3);
S = bg[var1][0];
aq = bg[var1][1];
if (!f(S, aq, 32)) {
var2 = false;
}
if (aq < var0) {
var2 = true;
}
}
}
public static final void d(int var0) {
S();
if (bO == 7) {
c.C.a(5, false);
c.C.a(6, false);
}
if ((ao & 3) != 0) {
long var1 = aN - be;
if (var1 < 30000L) {
if ((ao & 1) != 0) {
s -= 16383;
aM -= 16383;
s = k(s, 0);
aM = k(aM, 0);
}
if ((ao & 2) != 0) {
s += 6553;
aM += 6553;
s = e(s, 32767);
aM = e(aM, 32767);
}
ao &= -20;
}
}
bb = cr;
switch(var0) {
case 27:
if (m(0)) {
bb = 0;
s(3);
} else {
s(15);
}
break;
case 28:
if (m(1)) {
bb = 0;
s(3);
} else {
s(15);
}
break;
case 29:
if (m(2)) {
bb = 0;
s(3);
} else {
s(23);
}
}
a((int)var0, 2);
C(11);
}
public static final boolean v() {
if (s()) {
if (!c.ai || bb <= 0) {
switch(j) {
case 27:
B(0);
break;
case 28:
B(1);
break;
case 29:
B(2);
}
y(2);
return true;
}
switch(j) {
case 27:
--bb;
s(15);
break;
case 28:
bb -= 2;
s(16);
break;
case 29:
switch(B) {
case 21:
s(37);
break;
case 37:
s(39);
break;
case 39:
--bb;
s(39);
break;
default:
f(21, 5);
}
}
}
return false;
}
public static final boolean o(int var0) {
boolean var1 = true;
if (at <= 192 && bH == c.C.aE) {
if (var0 != -1) {
c.B();
switch(var0) {
case 1:
d(27);
break;
case 2:
d(28);
break;
case 3:
d(29);
break;
case 4:
if (bO == 10) {
N();
var1 = false;
} else {
ae();
}
}
}
return var1;
} else {
return false;
}
}
public static final void ae() {
if ((ao & 3) != 0) {
long var0 = aN - be;
if (var0 < 30000L) {
ao |= 16;
}
}
a((int)24, 25);
s(30);
c.C.a(5, false);
c.C.a(6, false);
C(10);
}
public static final void N() {
if (j != 24) {
if ((ao & 16) != 0) {
if ((ao & 1) != 0) {
if (bH == 2) {
s += 6553;
aM += 6553;
} else {
s -= 16383;
aM -= 16383;
}
}
if ((ao & 2) != 0) {
s -= 13106;
aM -= 13106;
}
s = k(s, 0);
aM = k(aM, 0);
s = e(s, 32767);
aM = e(aM, 32767);
}
ao &= -20;
}
s(33);
a((int)26, 4);
}
public static final boolean V() {
bH = c.C.aE;
boolean var0 = s();
if (var0) {
switch(j) {
case 24:
s(31);
j = 25;
break;
case 25:
if (B == 31) {
s(32);
} else {
s(31);
}
break;
case 26:
b(2, 1, 4);
}
}
return var0;
}
public static final void M() {
if ((ao & 64) == 0) {
by = c.C.aE;
bn = aN;
ao |= 512;
}
}
public static final void b(int var0, int var1, int var2, int var3) {
an = var2;
if (var3 != bH) {
if (c.C.aE != bH) {
at = 240;
aT = 50;
d(var0, l, var1);
bH = var3;
cA = -1;
} else {
C = var0;
z = var1;
cA = var3;
d(240, l, 50);
}
} else {
cA = -1;
d(var0, l, var1);
}
}
public static final void c(int var0, int var1) {
if (cA == -1) {
int var10000 = at;
var10000 = l;
var10000 = aT;
I = var0;
var10000 = l;
M = var1;
} else {
C = var0;
z = var1;
}
}
public static final boolean f(int var0, int var1, int var2) {
int var3 = at - var0;
int var4 = aT - var1;
return var3 * var3 + var4 * var4 < var2 * var2;
}
public static final boolean a(boolean var0) {
long var3 = aB;
int var5 = (int)((long)an * var3 / 1000L);
if (f(I, M, var5) && var0) {
U = aw;
if (cA == -1) {
at = I;
aT = M;
return true;
}
at = 240;
aT = 50;
d(C, 0, z);
bH = cA;
cA = -1;
} else {
switch(c.C.aA) {
case 2:
case 4:
int var1 = I - at;
int var2 = M - aT;
if (var5 < 0) {
aw = a.a(var2, -var1) & 255;
} else {
aw = a.a(-var2, var1) & 255;
}
U = j(aw, U);
at += var5 * a.d(U) >> 16;
aT -= var5 * a.a(U) >> 16;
}
}
return false;
}
public static final void S() {
if (bv != -1) {
c.br[bD][bv] = 0L;
if (c.bW[bD][bv] != 8) {
byte[] var10000 = c.an[bD];
int var10001 = bv;
var10000[var10001] &= -3;
}
c.j(bv, bD);
}
}
public static final void m(int var0, int var1) {
if (var0 != -1) {
U = c.cq[var1][var0];
aw = U;
at = c.bT[var1][var0];
l = c.O[var1][var0];
aT = c.cd[var1][var0];
}
}
public static final int j(int var0, int var1) {
if (a.c(var1 - var0) > 128) {
if (var1 > var0) {
var0 += 256;
} else {
var1 += 256;
}
}
int var2 = var1 - var0;
int var3 = var2 >> 1;
if (a.c(var3) <= 1) {
var1 = var0;
} else if (a.c(var3) < 21) {
var1 -= var3;
} else if (var3 < 0) {
var1 += 21;
} else {
var1 -= 21;
}
var1 &= 255;
return var1;
}
public static final void f(int var0, int var1) {
Z = -1;
int var2 = f(B);
int var3 = f(var0);
byte var4 = bG[var2][var3];
if (var4 != -1) {
Z = var0;
cb = var1;
var1 = 0;
var0 = var4;
}
a(bk[var0][0], var1, bk[var0][1], bk[var0][2], bk[var0][3], bk[var0][4], bk[var0][5]);
B = var0;
}
public static final int f(int var0) {
switch(var0) {
case 4:
case 5:
case 6:
case 17:
case 18:
return 1;
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
case 14:
case 15:
case 16:
case 22:
case 23:
case 24:
case 25:
case 27:
case 28:
case 29:
case 30:
case 31:
case 32:
case 33:
case 34:
case 35:
default:
return 0;
case 19:
case 39:
return 4;
case 20:
case 21:
case 26:
case 38:
return 2;
case 36:
case 37:
case 40:
return 3;
}
}
public static final void s(int var0) {
f(var0, 0);
}
public static final boolean s() {
int var0 = 1966 / Math.abs(bP);
int var1 = (int)aB * var0;
if (bP < 0) {
u -= var1;
if (o && u <= bB) {
if (e.g == 0 && cL && d.s == 9) {
b.a(ce);
}
o = false;
}
if (u < bW) {
if (bz == 0) {
u = bW;
} else {
while(u < bW) {
u += bz;
if (u < bW) {
u = bW;
}
}
}
--aH;
if (aH < 0) {
if (Z != -1) {
f(Z, cb);
return false;
}
return true;
}
if (bB > 0) {
o = true;
}
}
} else {
u += var1;
if (o && u >= bB) {
if (e.g == 0 && cL && d.s == 9) {
b.a(ce);
}
o = false;
}
if (u > bW) {
if (bz == 0) {
u = bW;
} else {
while(u > bW) {
u -= bz;
if (u > bW) {
u = bW;
}
}
}
--aH;
if (aH < 0) {
if (Z != -1) {
f(Z, cb);
return false;
}
return true;
}
if (bB > 0) {
o = true;
}
}
}
return false;
}
public static final void a(int var0, int var1, int var2, int var3, int var4, int var5, int var6) {
c.C.aA = var0;
aH = var1;
bP = var4;
int var10000;
if (var4 < 0) {
if (var2 < 0) {
var2 = c.C.cF[var0];
}
if (var3 < 0) {
var3 = 0;
}
u = var2 << 16;
var10000 = var2 << 16;
bW = var3 << 16;
bz = var2 - var3 << 16;
if (var4 == -99) {
bz = 0;
}
} else {
if (var2 < 0) {
var2 = 0;
}
if (var3 < 0) {
var3 = c.C.cF[var0];
}
u = var2 << 16;
var10000 = var2 << 16;
bW = var3 << 16;
bz = var3 - var2 << 16;
if (var4 == 99) {
bz = 0;
}
}
if (var6 >= 0) {
if (var6 == 0) {
if (e.g == 0 && cL && d.s == 9) {
b.a(var5);
}
bB = -1;
ce = 0;
o = false;
} else {
bB = var6;
ce = var5;
o = true;
if (e.g == 0 && cL && d.s == 9) {
b.b(var5);
}
}
} else {
bB = -1;
ce = 0;
}
}
public static final void h() {
if (bo > aK) {
f var10002 = c.C;
aK = bo + 60 + k(60);
int var0 = 0;
byte var1;
for(var1 = -1; var0 < f && (var1 == -1 || var1 == V); ++var0) {
switch(O[var0]) {
case 1:
var1 = 20;
break;
case 2:
var1 = 24;
break;
case 3:
var1 = 36;
break;
case 4:
var1 = 35;
break;
case 5:
var1 = 23;
}
}
if (var1 == -1 || var1 == V) {
int var2 = c.l(0, 0);
var2 += c.l(0, 1);
var2 += c.l(0, 2);
var2 += c.l(10, 0);
var2 += c.l(10, 1);
if (var2 > 5) {
var1 = 22;
}
}
if (var1 == -1 || var1 == V) {
if (aG > 26213) {
var1 = 16;
} else if (aG > 19660) {
var1 = 30;
} else if (aG > 13106) {
var1 = 18;
} else if (aG > 6553) {
var1 = 29;
} else {
var1 = 17;
}
}
Y = var1;
V = var1;
bw = aN + 3000L;
}
}
public static final void A(int var0) {
byte var1 = 19;
if (var0 == aQ || var0 == av || var0 == ax || var0 == n) {
var1 = 31;
}
if (var0 == bs || var0 == A || var0 == N) {
var1 = 32;
}
if (m(var0)) {
int var2 = Q();
if (var2 > cr * 2) {
var1 = 34;
bt = true;
} else {
var1 = 33;
}
}
if (var1 != -1) {
f var10002 = c.C;
aK = bo + 60 + k(60);
Y = var1;
bw = aN + 3000L;
}
}
public static final void d(int var0, int var1, int var2) {
int var10000 = at;
var10000 = l;
var10000 = aT;
I = var0;
M = var2;
C(1);
}
public static final void I() {
aW = 0;
bo = 0;
bc = (long)bo;
L = 22936;
E = 19660;
K = 26213;
D = 19660;
c = 32767;
bL = 19660;
s = 6553;
aM = 6553;
aG = 32767;
aP = 32767;
aW = 0;
af = 16383;
cs = 3276;
p = 3276;
l();
cD = 0;
bH = 0;
an = 60;
cA = -1;
at = 240;
l = 0;
aT = 50;
u = 0;
o = false;
bB = 0;
U = 32;
j = 11;
d = 1;
cu = 0;
}
public static final void ab() {
aW = 0;
L = 22936;
E = 19660;
K = 26213;
D = 19660;
c = 32767;
bL = 19660;
s = 6553;
aM = 6553;
aG = 32767;
aP = 32767;
aW = 0;
af = 16383;
cs = 3276;
p = 3276;
y();
}
public static final void p() {
cK = true;
C(99);
cj = false;
at = 132 * d.al >> 8;
l = 0;
aT = 194 * d.au >> 8;
bF = 106496 * (128 * d.au / 208) >> 8;
f var10000 = c.C;
bd = false;
s(4);
}
public static final void ac() {
C(3);
a((int)3, 1);
cK = true;
cj = true;
s(1);
I();
}
public static int k(int var0) {
if (var0 == 0) {
return 0;
} else {
int var1 = bq.nextInt() % var0;
var1 = var1 > 0 ? var1 : -var1;
return var1;
}
}
public static int l(int var0, int var1) {
int var2 = k(var1 - var0);
return var2 + var0;
}
public static final void G() {
aa = bo;
bH = 0;
if (aW == 3) {
D += bV[36] * cG[20] >> 8;
}
K -= bZ[36] >> 3;
L -= bZ[36] >> 5;
Y();
}
public static final void D() {
bL -= 9830;
k(bL, 0);
}
public static final void m() {
cl = true;
}
public static final void Z() {
D += 6553;
e(D, 32767);
}
public static final void r() {
aJ = 0;
}
public static final void a(int var0, int var1, int var2, int var3) {
if (aJ < 12) {
int var4 = var1 - a.c(var0 - (aG >> 8));
if (var4 <= 0) {
return;
}
var4 = var4 * 100 / var1;
ai[aJ] = var4;
W[aJ] = var2;
aj[aJ] = var3;
++aJ;
}
}
public static final int u() {
int var0 = 0;
int var1;
for(var1 = 0; var0 < aJ; ++var0) {
var1 += ai[var0];
}
if (var1 > 0) {
f var10000 = c.C;
int var2 = k(var1);
var0 = 0;
for(var1 = 0; var0 < aJ; ++var0) {
var1 += ai[var0];
if (var2 < var1) {
az = W[var0];
aD = aj[var0];
return var0;
}
}
}
return -1;
}
public static final void L() {
int[] var0 = new int[20];
byte var2 = 20;
int var1;
for(var1 = 0; var1 < var2; var0[var1] = var1++) {
}
int var3;
int var4;
for(var1 = 0; var1 < var2; ++var1) {
var3 = k(var2);
var4 = var0[var3];
var0[var3] = var0[var1];
var0[var1] = var4;
}
for(var1 = 0; var1 < 4; ++var1) {
bS[var1] = var0[var1];
}
var2 = 5;
for(var1 = 0; var1 < var2; var0[var1] = var1++) {
}
var2 = 15;
for(var1 = 0; var1 < var2; var0[var1] = var1++) {
}
for(var1 = 0; var1 < var2; ++var1) {
var3 = k(var2);
var4 = var0[var3];
var0[var3] = var0[var1];
var0[var1] = var4;
}
for(var1 = 0; var1 < 4; ++var1) {
F[var1] = var0[var1];
}
}
public static final void r(int var0) {
int var2 = 0;
label37:
for(int var1 = 0; var1 < 4; ++var1) {
boolean var3 = true;
while(true) {
do {
if (!var3) {
co[var1] = var2;
cx[var1] = n(co[var1]);
continue label37;
}
f var10000 = c.C;
var2 = k(35) + 6;
} while(var2 == var0);
var3 = false;
for(int var4 = 0; var4 < var1; ++var4) {
if (var2 == co[var4]) {
var3 = true;
}
}
}
}
}
public static final int i() {
int var0 = (aP << 1) + c + (c >> 1) + (aG >> 1) >> 12;
var0 = (var0 << 2) + var0 >> 2;
if (var0 < 0) {
var0 = 30;
}
return var0;
}
public static final int T() {
int var0 = aP + (aP >> 1) + D + aG + (aG >> 1) >> 12;
var0 = (var0 << 2) + var0 >> 2;
if (var0 < 0) {
var0 = 30;
}
return var0;
}
public static final int n(int var0) {
int[] var1 = new int[4];
int var4;
for(var4 = 4; var4 > 1; --var4) {
int var2 = var0 / var4;
f var10001 = c.C;
int var3 = var2 + (k(6) - 3);
var3 = k(var3, 0);
var3 = e(var3, 10);
var3 = e(var3, var0);
var1[var4 - 1] = var3;
var0 -= var3;
}
var1[0] = var0;
boolean var6 = true;
while(var6) {
var6 = false;
for(var4 = 0; var4 < 4; ++var4) {
if (var1[var4] > 10) {
var6 = true;
for(int var5 = 0; var5 < 4; ++var5) {
if (var1[var5] < 10) {
int var10002 = var1[var4]--;
var10002 = var1[var5]++;
break;
}
}
}
}
}
return var1[0] << 12 | var1[1] << 8 | var1[2] << 4 | var1[3];
}
public static final void H() {
int var0 = c.e(14, 2);
if (var0 != -1) {
c.m(2, var0);
}
var0 = c.e(15, 1);
if (var0 != -1) {
c.m(1, var0);
}
var0 = c.e(1, 0);
if (var0 != -1) {
c.m(0, var0);
}
}
public final void t() {
int var2 = bY[this.aA];
for(int var3 = 0; var3 < this.aO; ++var3) {
bU[var3] = (short)var2;
byte var1 = cy[var2];
var2 += 4 * var1 + 1;
}
}
static {
r = d.al;
i = d.au;
O = new byte[8];
a = new int[8];
cB = new short[5];
ct = new short[5];
ai = new int[12];
W = new int[12];
aj = new int[12];
bA = new int[3];
cK = false;
aX = 0L;
aL = false;
cG = new short[45];
int[] var10000 = new int[]{0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240};
bt = false;
bd = false;
bp = new boolean[]{false, true, false, false, true, true, false};
bx = 0;
bg = new short[][]{{96, 128}, {96, 180}, {128, 64}, {128, 128}, {128, 180}, {160, 128}, {160, 180}, {96, 64}, {64, 128}, {64, 180}};
bk = new int[][]{{5, 34, 40, 1, 0, -1}, {15, -1, -1, 1, 0, -1}, {14, -1, -1, 2, 7, 0}, {14, 24, -1, 2, 0, -1}, {0, -1, -1, 2, 0, -1}, {0, -1, -1, 2, 0, -1}, {3, -1, -1, 1, 0, -1}, {3, -1, -1, -1, 0, -1}, {4, -1, -1, 1, 0, -1}, {2, -1, -1, 1, 0, -1}, {1, 8, 15, 2, 2, 8}, {1, 8, 15, 2, 1, 8}, {5, -1, -1, 1, 0, -1}, {13, -1, -1, 1, 0, 5}, {11, -1, -1, 1, 0, 5}, {15, -1, -1, 1, 0, -1}, {16, -1, -1, 2, 0, -1}, {21, -1, -1, 1, 7, 0}, {17, -1, -1, 1, 7, 0}, {22, -1, -1, 1, 0, -1}, {6, -1, 9, 1, 0, -1}, {6, 9, 9, 1, 0, -1}, {6, 9, -1, 1, 0, -1}, {24, -1, -1, 2, 0, -1}, {23, -1, -1, 1, 0, -1}, {7, -1, -1, 1, 0, 3}, {18, -1, -1, 2, 5, 0}, {8, -1, -1, 1, 0, -1}, {8, 50, 60, 1, 0, -1}, {8, -1, -1, -1, 0, -1}, {12, -1, 15, 1, 0, -1}, {12, 10, 15, 1, 0, -1}, {12, 10, 15, -1, 0, -1}, {12, 15, -1, -1, 0, -1}, {19, -1, -1, 2, 5, 4}, {24, -1, -1, 2, 0, -1}, {20, -1, -1, 1, 0, -1}, {20, 15, -1, 1, 0, -1}, {20, 15, -1, -1, 0, -1}, {22, 15, -1, 1, 0, -1}, {22, 15, -1, -1, 0, -1}, {1, -1, -1, 3, 0, -1}, {25, -1, -1, 2, 0, -1}, {10, -1, 30, 2, 0, -1}, {10, 30, -1, 2, 0, -1}, {9, -1, 18, 2, 4, 4}, {9, 18, -1, 2, 0, -1}, {10, -1, 20, 2, 4, 4}, {10, 20, 34, 2, 0, -1}, {4, -1, -1, -1, 0, -1}, {1, -1, 8, 2, 0, -1}, {1, 15, -1, 2, 0, -1}};
bG = new byte[][]{{-1, 6, 20, 20, 20}, {7, -1, 7, 7, 7}, {22, 22, -1, 36, 36}, {38, 38, 38, -1, 19}, {40, 40, 40, 40, -1}};
var10000 = new int[]{2, 0, 1};
var10000 = new int[]{1, 2, 0};
var10000 = new int[]{74, 73, 72};
bS = new int[4];
co = new int[4];
cx = new int[4];
F = new int[4];
}
}
| Gamr13/MyDogDecomp | f.java |
1,008 | import java.applet.Applet;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Canvas;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Random;
import java.awt.Color;
import java.awt.Component;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class b extends Applet implements Runnable {
private static final long serialVersionUID = 1L;
public void start() {
setSize(128, 128);
if (this.b2 == null) {
this.b2 = new Thread(this);
this.b2.start();
}
bbb = false;
}
public static int aaa;
public static boolean bbb;
public static boolean ccc;
public static boolean ddd;
public static boolean ee;
public static boolean ff;
public static boolean gg;
public static boolean hh;
public static boolean ii;
public static boolean j;
public static boolean k;
public static boolean l;
public static boolean m;
public static boolean n;
public static int o;
public static int p;
public static int q;
public static int r;
public static int s;
public static int t;
public static int u;
public static final int[] v = { 239, 16 };
public static Random w;
public static int x;
public static int y = 10;
public static int z;
public static int[] aa;
public static int[] ab;
public static int[] ac;
public static int[] ad;
public static boolean[] ae;
public static boolean[] af;
public static boolean[] ag;
public static long ah;
public static int ai;
public static int aj;
public static int ak;
public static int al;
public static int am;
public static int an;
public static int ao;
public static int ap;
public static int aq;
public static int ar;
public static int as;
public static int at;
public static int au;
public static int av;
public static int aw;
public static int ax;
public static int ay;
public static int az;
public static int a0;
public static int a1;
public static int a2;
public static int a3;
public static int a4;
public static DataInputStream a5;
public static e[] a6;
public static Image[] a7;
public static Image[] a8;
public static Image[] a9;
public static Image ba;
public static Image bb;
public static Image bc;
public static Image bd;
public static Image be;
public static Image bf;
public static Graphics bg;
public static Graphics bh;
public static Graphics bi;
public static Graphics bj;
public static String[] bk;
public static String[] bl;
public static c bm;
public static c bn;
public static c bo;
public static String bp;
//public static j bq;
public static byte[] br;
public static byte[] bs;
public static byte bt;
public static d[] bu;
//public static BluetoothBiplanes bv;
public static e bw;
public static e bx;
public static e by;
public static e bz;
public static int b0;
public static int b1;
public Thread b2;
public static final int[] b3 = { 9578383, 2593407, 281486 };
public static final int[] b4 = { 16776704, 16768512, 16757760, 16711937 };
public static int[] b5;
public static int[] b6;
public static int b7;
public static int b8;
public static int b9;
public static int ca;
public static int cb;
public static int cc;
public static int cd;
public static int ce;
public static int cf;
public static int cg;
public static Image ch;
public static Image ci;
public static Image cj;
public static Image ck;
public static Image cl;
public static Image cm;
public static Graphics cn;
public static Graphics co;
public static final String[] cp = { "Engine Sleep", "Engine Latency", "Bluetooth Sleep" };
public static int cq;
public static int cr = 12;
public static int cs = 5;
public static int ct = 0;
public static int cu = 0;
public static int cv = 13;
public static int cw = 15;
public static int cx = 7;
public static int cy;
public static int cz;
public static int c0;
public static int c1;
public static String c2;
public static int c3;
public static int c4;
public static int c5;
public static boolean c6;
public static boolean c7;
public static int c8;
public static int[] c9;
public static int da;
public static int db;
private static int dc = 43;
public static String[] dd = new String[40];
private static byte[] de = new byte[8];
private static byte[] df;
private static byte[] dg = new byte[12];
private static byte[] dh = new byte[15];
private static byte[] di = new byte[4];
private static int[] dj = new int[256];
private static boolean dk = false;
private static final int[] dl = { 0, 2, 4, 7, 9, 11, 13, 16, 18, 20, 22, 24, 27, 29, 31, 33, 35, 37, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 73, 75, 77, 79, 81, 82, 84, 86, 87, 89, 91, 92, 94, 95, 97, 98, 99, 101, 102, 104, 105, 106, 107, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 119, 120, 121, 122, 122, 123, 124, 124, 125, 125, 126, 126, 126, 127, 127, 127, 128, 128, 128, 128, 128 };
private static final byte[][] dm = { { 45, 27, 18, 14, 11, 9, 8, 7, 6, 6 }, { 63, 45, 34, 27, 22, 18, 16, 14, 13, 11 }, { 72, 56, 45, 37, 31, 27, 23, 21, 18, 17 }, { 76, 63, 53, 45, 39, 34, 30, 27, 24, 22 }, { 79, 68, 59, 51, 45, 40, 36, 32, 29, 27 }, { 81, 72, 63, 56, 50, 45, 41, 37, 34, 31 }, { 82, 74, 67, 60, 54, 49, 45, 41, 38, 35 }, { 83, 76, 69, 63, 58, 53, 49, 45, 42, 39 }, { 84, 77, 72, 66, 61, 56, 52, 48, 45, 42 }, { 84, 79, 73, 68, 63, 59, 55, 51, 48, 45 } };
private static int dn;
private static int jdField_do;
private static int dp;
private static int dq;
private static int dr;
private static int ds;
private static int dt;
private static int du;
private static int dv;
private static int dw;
private static StringBuffer[] dx;
private static int[] dy;
private static int[] dz;
private static int[] d0;
private static int[] d1;
private static int[] d2;
private static long d3;
private static long d4;
private static long d5;
private static boolean d6;
private static int d7;
private static final char[][] d8 = { { '0', '_' }, { '1', '-', '@' }, { 'A', 'B', 'C', '2', 'a', 'b', 'c' }, { 'D', 'E', 'F', '3', 'd', 'e', 'f' }, { 'G', 'H', 'I', '4', 'g', 'h', 'i' }, { 'J', 'K', 'L', '5', 'j', 'k', 'l' }, { 'M', 'N', 'O', '6', 'm', 'n', 'o' }, { 'P', 'Q', 'R', 'S', '7', 'p', 'q', 'r', 's' }, { 'T', 'U', 'V', '8', 't', 'u', 'v' }, { 'W', 'X', 'Y', 'Z', '9', 'w', 'x', 'y', 'z' } };
//public b(BluetoothBiplanes var1) {
public b() {
// bv = var1;
r = getWidth();
s = getHeight();
if (r == 128)
x = 50;
else
x = 25;
dn = 5;
jdField_do = dn + 3;
dt = r - 3;
ds = dt - 2;
dq = ds - 6;
dp = ds - 8;
dr = 0;
d6 = false;
d5 = System.currentTimeMillis();
d7 = 500;
dz = new int[] { 2, 11 };
d0 = new int[] { 10, 11 };
d1 = new int[] { s - 48, s - 28 };
d2 = new int[] { 1, 0 };
dx = new StringBuffer[2];
dy = new int[2];
dx[0] = new StringBuffer();
dx[1] = new StringBuffer();
b1 = 666;
br = new byte[18];
w = new Random();
// bq.a();
bp = "";
gg = true;
o();
c();
ii = true;
}
public static void a(boolean paramBoolean) {
}
public static void a(String paramString) {
bp = paramString;
}
public static void a(int paramInt, DataInputStream paramDataInputStream) {
try {
an = paramInt;
e locale1 = a6[1];
e locale2 = a6[0];
paramDataInputStream.readFully(br);
int i1 = 0;
locale1.a = br[(i1++)];
if (locale1.a == 2)
locale1.p = 0;
locale1.d = (br[(i1++)] & 0xFF);
locale1.e = (br[(i1++)] & 0xFF);
locale1.bb = (locale1.d << 6);
locale1.c = (locale1.e << 6);
locale1.f = br[(i1++)];
locale2.p = br[(i1++)];
int i2 = 2;
do {
i2--;
f localf = locale1.av[i2];
localf.a = (br[(i1++)] & 0xFF);
localf.bb = (br[(i1++)] & 0xFF);
}
while (i2 > 0);
for (int i3 = aq; i3 < ar; i3++) {
aa[i3] = ((br[(i1++)] & 0xFF) * 2);
ab[i3] = ((br[(i1++)] & 0xFF) * 2);
}
locale1.v = br[(i1++)];
if (locale1.v != 0) {
locale1.w = ((br[(i1++)] & 0xFF) << 6);
locale1.x = ((br[(i1++)] & 0xFF) << 6);
locale1.aa = br[(i1++)];
locale1.ac = br[(i1++)];
}
if (an > 1)
locale1.a(br[(i1++)]);
else
locale1.ae = br[(i1++)];
int i4 = br[(i1++)];
if ((i4 & 0x1) != 0) {
locale1.m -= 1;
if (locale1.m < 0)
locale1.m = 0;
b(locale2);
c(locale1);
}
if ((i4 & 0x2) != 0)
locale1.f();
if ((i4 & 0x4) != 0) {
locale1.m -= 1;
if (locale1.m < 0)
locale1.m = 0;
c(locale1);
b(locale2);
}
if ((i4 & 0x8) != 0) {
locale2.v = 3;
locale2.aa = 0;
locale1.m += 2;
c(locale1);
b(locale1);
}
if ((i4 & 0x10) != 0)
locale1.ao.v = 5;
if ((i4 & 0x20) != 0) {
locale2.f();
if (locale2.v == 0) {
locale2.v = 3;
locale2.aa = 0;
locale1.m += 1;
c(locale1);
b(locale1);
bt = (byte)(bt + 64);
}
}
if ((i4 & 0x40) != 0) {
locale2.m += 1;
c(locale2);
b(locale2);
}
if ((i4 & 0x80) != 0)
g();
}
catch (Exception localException) {
localException.printStackTrace();
}
}
public static boolean b(boolean paramBoolean) {
ddd = paramBoolean;
if (ddd) {
a6[1].ap = true;
if (a6[0] == bx)
o = 1;
else
o = 2;
}
else {
bp = bk[44];
}
return ddd;
}
public void a() {
switch (aaa) {
case 7:
if ((as == 1) || (by != bw)) {
aaa = 2;
return;
}
aaa = 8;
if (!m)
a();
break;
case 8:
aaa = 9;
if (!n)
a();
break;
case 9:
aaa = 10;
if (!l)
a();
break;
case 10:
aaa = 2;
}
c();
}
private static void j(int paramInt) {
af[paramInt] = true;
n();
}
private static void n() {
try {
g.g = b("/tm");
int i1 = 3;
do {
i1--;
if (af[i1] == false) {
g.g[(4 + i1)] = bk[5];
g.g[(27 + i1)] = bk[5];
g.g[(38 + i1)] = bk[5];
g.g[(43 + i1)] = bk[5];
}
}
while (i1 > 0);
}
catch (Exception localException) {
localException.printStackTrace();
}
}
private static void o() {
try {
bm = new c("/f");
bn = new c("/fzr");
bo = new c("/fzb");
bk = b("/tg");
bl = b("/tt");
b5 = new int[3];
b6 = new int[3];
ac = new int[4];
ad = new int[4];
for (int i1 = 0; i1 < 4; i1++)
ad[i1] = 10;
ag = new boolean[4];
af = new boolean[3];
gg = true;
ii = true;
if (!b())
c(true);
cd = bm.a(bk[11] + " 100% ");
BufferedImage buf = new BufferedImage(cd, 15, BufferedImage.TYPE_INT_ARGB);
cl = (Image) buf;
buf = new BufferedImage(cd, 15, BufferedImage.TYPE_INT_ARGB);
cm = (Image) buf;
cn = cl.getGraphics();
co = cm.getGraphics();
n();
ak = 255 - r;
al = 208 - s;
bu = new d[50];
int i2 = 50;
do {
i2--;
bu[i2] = new d();
}
while (i2 > 0);
aa = new int[2];
ab = new int[2];
ae = new boolean[2];
int i3 = 2;
do {
i3--;
aa[i3] = c(255);
ab[i3] = c(104);
ae[i3] = (c(2) == 0 ? true : false);
}
while (i3 > 0);
ay = c(255) << 6;
az = c(104);
a6 = new e[2];
int i4 = 2;
do {
i4--;
a6[i4] = new e(i4 == 0);
}
while (i4 > 0);
a6[0].ao = a6[1];
a6[1].ao = a6[0];
a5 = new DataInputStream(a6.getClass().getResourceAsStream("/r"));
byte[] arrayOfByte1 = m();
x = arrayOfByte1[0];
z = arrayOfByte1[1];
bs = m();
byte[] arrayOfByte2 = m();
g.a(arrayOfByte2);
i();
a7 = d(32);
ba = k();
bb = k();
Image localImage = k();
t = localImage.getWidth(null);
u = localImage.getHeight(null);
buf = new BufferedImage(t, u, BufferedImage.TYPE_INT_ARGB);
bc = (Image) buf;
bg = bc.getGraphics();
bg.drawImage(localImage, 0, 0, null); // Anchor: 20
buf = new BufferedImage(26, 9, BufferedImage.TYPE_INT_ARGB);
bd = (Image) buf;
bh = bd.getGraphics();
a8 = d(72);
a9 = e(1);
int i5 = a8[69].getWidth(null);
int i6 = a8[69].getHeight(null);
buf = new BufferedImage(i5, i6, BufferedImage.TYPE_INT_ARGB);
be = (Image) buf;
bi = be.getGraphics();
buf = new BufferedImage(128, 100, BufferedImage.TYPE_INT_ARGB);
bf = (Image) buf;
bj = bf.getGraphics();
h.a(a5);
a5.close();
a5 = null;
System.gc();
cy = -1;
aaa = 13;
}
catch (Exception localException) {
localException.printStackTrace();
}
}
public static void c(boolean paramBoolean) {
try {
k = true;
// RecordStore var1 = RecordStore.openRecordStore("s", true);
// ByteArrayOutputStream var2 = new ByteArrayOutputStream();
// DataOutputStream var3 = new DataOutputStream(var2);
// if(var1.getSizeAvailable() >= 600) {
// for(int var4 = 0; var4 < 3; ++var4) {
// var3.writeBoolean(af[var4]);
// }
//
// for(int var5 = 0; var5 < 4; ++var5) {
// var3.writeByte((byte)ac[var5]);
// var3.writeBoolean(ag[var5]);
// var3.writeByte((byte)ad[var5]);
// }
//
// var3.writeBoolean(gg);
// var3.writeBoolean(i);
// byte[] var6 = var2.toByteArray();
// if(var0) {
// var1.addRecord(var6, 0, var6.length);
// } else {
// var1.setRecord(1, var6, 0, var6.length);
// }
//
// k = false;
// }
//
// var1.closeRecordStore();
// var3.close();
// var2.close();
}
catch (Exception localException) {
localException.printStackTrace();
k = true;
}
}
public static boolean b() {
try {
System.gc();
// RecordStore var0 = RecordStore.openRecordStore("s", true);
// if(var0.getNumRecords() > 0) {
// byte[] var1 = var0.getRecord(1);
// ByteArrayInputStream var2 = new ByteArrayInputStream(var1);
// DataInputStream var3 = new DataInputStream(var2);
//
// for(int var4 = 0; var4 < 3; ++var4) {
// af[var4] = var3.readBoolean();
// }
//
// for(int var5 = 0; var5 < 4; ++var5) {
// ac[var5] = var3.readByte();
// ag[var5] = var3.readBoolean();
// ad[var5] = var3.readByte();
// }
//
// gg = var3.readBoolean();
// ii = var3.readBoolean();
// var0.closeRecordStore();
// var3.close();
// var2.close();
// return true;
// }
//
// var0.closeRecordStore();
}
catch (Exception localException) {
}
return false;
}
public static void a(int paramInt1, int paramInt2) {
try {
if (gg)
h.a(paramInt1, paramInt2);
}
catch (Exception localException) {
localException.printStackTrace();
}
}
public static void a(int paramInt1, int paramInt2, int paramInt3, int paramInt4, int paramInt5, int paramInt6, int paramInt7) {
int i4 = 50;
do {
i4--;
if (bu[i4].a == -1) {
int i2 = paramInt5 - paramInt4;
int i1 = c(i2) + paramInt4;
i2 = paramInt7 - paramInt6;
int i3 = c(i2) + paramInt6;
bu[i4].a(paramInt2, paramInt3, i1, i3);
paramInt1--;
if (paramInt1 == 0)
return;
}
}
while (i4 > 0);
}
public static void a(e parame) {
if (as == 1) {
// if(j.d) {
// var0.b(0, v[1], 180, 3);
// } else {
// var0.b(0, v[0], 180, 2);
// }
}
else if (as == 0)
if (parame == a6[0])
parame.b(0, v[1], 180, 3);
else
parame.b(0, v[0], 180, 2);
}
public void run() {
ccc = false;
while (!ccc) {
try {
long l1 = System.currentTimeMillis() - ah;
long l2 = x - l1;
if (l2 > y)
Thread.sleep(l2);
ah = System.currentTimeMillis();
e();
System.out.println(aaa);
if (cy >= 0)
c();
else
switch (aaa) {
case 14:
p += 1;
if (p == 50) {
p = 0;
q += 1;
if (q == 3) {
// int qwe = 1/0;
// bv.destroyApp(true);
// bv.notifyDestroyed();
}
else {
c();
}
}
break;
case 2:
c();
break;
case 5:
case 6:
case 7:
c();
break;
case 0:
if (++a2 > 120)
aaa = 2;
break;
case 13:
if (a2 == 0)
a(0, 1);
if (++a2 > 120) {
a2 = 0;
aaa = 0;
c();
}
break;
case 3:
c();
break;
case 1:
case 4:
if (as == 0)
ee = true;
else if (as == 1)
ee = (!ddd) || (am - an < 2);
if (!ee) {
a4 += 1;
if (a4 > 50) {
if (cy == -1)
a(bk[18], 0);
a4 = 0;
}
}
else {
a4 = 0;
}
if ((ee) && (ddd) && (as == 1)) {
e locale = a6[0];
int i1 = 0;
br[(i1++)] = ((byte)locale.a);
br[(i1++)] = ((byte)locale.d);
br[(i1++)] = ((byte)locale.e);
int i2 = locale.f;
if (locale.i == 3)
i2 += 16;
br[(i1++)] = ((byte)i2);
br[(i1++)] = ((byte)locale.ao.p);
if (locale.ao.p > 2)
locale.ao.p = 0;
int i3 = 2;
do {
i3--;
br[(i1++)] = ((byte)locale.av[i3].a);
br[(i1++)] = ((byte)locale.av[i3].bb);
}
while (i3 > 0);
for (int i4 = ao; i4 < ap; i4++) {
br[(i1++)] = ((byte)(aa[i4] / 2));
br[(i1++)] = ((byte)(ab[i4] / 2));
}
br[(i1++)] = ((byte)locale.v);
if (locale.v != 0) {
br[(i1++)] = ((byte)(locale.w >> 6));
br[(i1++)] = ((byte)(locale.x >> 6));
br[(i1++)] = ((byte)locale.aa);
br[(i1++)] = ((byte)locale.ac);
}
if (am > 1)
br[(i1++)] = ((byte)locale.af);
else
br[(i1++)] = ((byte)locale.ae);
br[(i1++)] = bt;
bt = 0;
// bq.c.writeInt(am);
// bq.c.write(br);
// bq.c.flush();
am += 1;
}
c();
case 8:
case 9:
case 10:
case 11:
case 12:
}
}
catch (Exception localException) {
localException.printStackTrace();
}
}
}
public void c() {
repaint();
//Thread.yield();
}
public static void d() {
bw.ap = true;
bx.ap = true;
if (o == 1) {
a6[0].a(0, v[0], 180, 2);
a6[1].a(0, v[1], 180, 3);
}
else {
a6[0].a(0, v[1], 180, 3);
a6[1].a(0, v[0], 180, 2);
}
am = 0;
an = 0;
a4 = 0;
as = 1;
aaa = 1;
}
public static void a(int paramInt) {
switch (paramInt) {
case 6:
a(bk[36], 0);
break;
case 33:
a(bk[37], 0);
break;
case 7:
aaa = 11;
break;
case 21:
if (as == 1) {
bp = "";
o = 0;
ddd = false;
}
break;
case 13:
aaa = 12;
at = 0;
break;
case 8:
ii = true;
c(false);
break;
case 9:
ii = false;
c(false);
break;
case 10:
gg = true;
c(false);
break;
case 11:
gg = false;
c(false);
break;
case 20:
aaa = 1;
break;
case 24:
case 25:
case 26:
case 27:
if ((paramInt == 24) || (af[(paramInt - 1 - 24)] != false)) {
// bq = null;
System.gc();
// bq = new j();
// bq.a(false);
ddd = false;
bx = a6[0];
bw = a6[1];
a6[1].ae = -1;
a6[0].a(0, v[0], 180, 2);
a6[1].a(0, v[1], 180, 3);
bw.ap = false;
am = 0;
an = 0;
a4 = 0;
aq = 0;
ar = 1;
ao = 1;
ap = 2;
as = 1;
a6[0].ae = (39 + paramInt - 24);
aaa = 1;
au = 30;
}
else {
a(bk[8], 0);
g.a(0);
}
break;
case 28:
case 29:
case 30:
case 31:
if ((paramInt == 28) || (af[(paramInt - 1 - 28)] != false)) {
// bq = null;
System.gc();
// bq = new j();
// bq.a(true);
// d = false;
ddd = false;
bw = a6[0];
bx = a6[1];
a6[0].a(0, v[1], 180, 3);
a6[1].a(0, v[0], 180, 2);
bx.ap = false;
a6[1].ae = -1;
c(bx);
am = 0;
an = 0;
a4 = 0;
ao = 0;
ap = 1;
aq = 1;
ar = 2;
as = 1;
a6[0].ae = (35 + paramInt - 28);
aaa = 1;
au = 30;
}
else {
a(bk[8], 0);
g.a(0);
}
break;
case 0:
case 1:
case 2:
case 3:
if ((paramInt == 0) || (af[(paramInt - 1)] != false)) {
a6[0].ae = (35 + paramInt);
g.a(25);
}
else {
a(bk[8], 0);
}
break;
case 16:
case 17:
case 18:
case 19:
if ((paramInt - 16 == 0) || (af[(paramInt - 16 - 1)] != false)) {
a6[1].ae = (39 + paramInt - 16);
a6[1].u = (paramInt - 16);
a6[0].a(0, v[1], 180, 3);
a6[1].a(0, v[0], 180, 2);
as = 0;
g.a(33);
}
else {
a(bk[8], 0);
}
break;
case 23:
j = true;
aaa = 1;
au = 30;
break;
case 22:
j = false;
aaa = 1;
au = 30;
break;
case 32:
d();
break;
case 5:
g.a(41);
break;
case 4:
g.a(36);
break;
case 14:
ba = null;
bb = null;
System.gc();
aaa = 14;
p = 0;
q = -1;
case 12:
case 15:
}
}
public void e() {
if (b0 > 0) {
b0 -= 1;
return;
}
int i1 = i.a();
if (cy >= 0) {
switch (i1) {
case 10:
b(1);
cz = 0;
break;
case 11:
b(2);
cz = 0;
break;
case 16:
if (c7) {
cy = -1;
c();
}
else {
b(2);
cz = 0;
}
break;
}
return;
}
switch (aaa) {
case 11:
if (i1 == 16) {
aaa = 2;
hh = false;
}
if (i1 == 15)
a(bk[21], 0);
break;
case 12:
if (i1 == 16) {
aaa = 2;
hh = false;
}
if (i1 == 15) {
at += 1;
if (at == 3)
at = 0;
c();
}
break;
case 8:
case 9:
case 10:
if (i1 == 16) {
a();
return;
}
break;
case 5:
if (i1 != -66) {
aaa = 7;
a1 = Math.max(r, s) >> 1;
}
break;
case 3:
switch (i1) {
case 15:
hh = false;
aaa = 2;
break;
case 16:
String str = bk[3] + dx[0].toString();
str = str + bk[4];
a(dx[1].toString(), str);
hh = false;
aaa = 2;
}
if (i1 == -66)
return;
int i2 = 0;
int i3 = 666;
for (int i4 = 0; i4 != 10; i4++)
if (i1 == i4) {
i3 = i4;
i2 = 1;
break;
}
d3 = System.currentTimeMillis() - d4;
d4 = System.currentTimeMillis();
int i5 = 1050;
if (i2 == 0)
if (i1 == 19) {
i3 = 19;
}
else {
if ((i1 == 20) && (dw > 0)) {
i(dw - 1);
b1 = i3;
return;
}
if ((i1 == 21) && (dw < 1)) {
i(dw + 1);
b1 = i3;
return;
}
}
if (i3 == 666)
return;
if ((dx[dw].length() >= d0[dw]) && ((i2 == 0) || (d3 >= i5) || (b1 != i3) || (d2[dw] == 0))) {
if (i2 != 0)
return;
if (i1 != 19)
return;
}
int i6 = d2[dw];
if (i6 == 0) {
if (i2 != 0) {
dx[dw].append(i3);
du += 1;
}
else if (i1 == 19) {
du -= 1;
if (du < 0)
du = 0;
else
dx[dw].deleteCharAt(du);
}
}
else if (i2 != 0) {
if ((d3 < i5) && (b1 == i3)) {
d6 = false;
d5 = System.currentTimeMillis() + d7;
du -= 1;
dv += 1;
if (dv >= d8[i3].length)
dv = 0;
dx[dw].setCharAt(du, d8[i3][dv]);
du += 1;
}
else {
dv = 0;
dx[dw].append(d8[i3][dv]);
du += 1;
}
}
else if (i1 == 19) {
du -= 1;
if (du < 0)
du = 0;
else
dx[dw].deleteCharAt(du);
}
b1 = i3;
break;
case 2:
switch (i1) {
case 10:
g.b(0);
break;
case 11:
g.b(1);
break;
case 14:
case 15:
g.b(2);
break;
case 16:
if ((g.a != 66) && (g.a != 50))
g.a(0);
break;
case 12:
case 13:
}
c();
break;
case 1:
case 4:
if (i.c(10)) { // UP
if (ff) {
cq -= 1;
if (cq < 0)
cq = 2;
b0 = 3;
return;
}
a6[0].c();
}
if (i.c(11)) { // DOWN
if (ff) {
cq += 1;
b0 = 3;
if (cq == 3)
cq = 0;
return;
}
a6[0].d();
}
if (i.c(12)) { // LEFT
if (ff) {
switch (cq) {
case 0:
x -= 1;
if (x < 0)
x = 0;
break;
case 1:
y -= 1;
if (y < 0)
y = 0;
break;
case 2:
z -= 1;
if (z < 0)
z = 0;
break;
}
return;
}
a6[0].b(2);
}
if (i.c(13)) { // RIGHT
if (ff) {
switch (cq) {
case 0:
x += 1;
break;
case 1:
y += 1;
break;
case 2:
z += 1;
}
return;
}
a6[0].b(3);
}
if (i.c(14)) // SELECT
a6[0].a();
switch (i1) {
case 17:
a6[0].b(); // Eject
break;
case 16:
g.a(30); // Pause
aaa = 2;
}
break;
case 6:
case 7:
}
}
public void keyPressed(int paramInt) {
i.a(paramInt);
}
public void keyReleased(int paramInt) {
i.b(paramInt);
}
public void a(Graphics paramGraphics) {
if (a6[0].v == 0) {
ai = a6[0].d - (r >> 1);
aj = a6[0].e - (s >> 1);
}
else {
ai = (a6[0].w >> 6) - (r >> 1);
aj = (a6[0].x >> 6) - (s >> 1);
}
ai = ai > ak ? ak : ai < 0 ? 0 : ai;
aj = aj > al ? al : aj < 0 ? 0 : aj;
int i1 = 124;
paramGraphics.setColor(new Color(52479));
paramGraphics.fillRect(0, 0, r, i1);
paramGraphics.translate(-ai, -aj);
int i2 = 0;
while (i2 < 255) {
paramGraphics.drawImage(ba, i2, i1, null); // Anchor: 20
paramGraphics.drawImage(bb, i2, 0, null); // Anchor: 20
i2 += 128;
}
int i3 = ay >> 6;
paramGraphics.drawImage(a8[57], i3, az, null); // Anchor: 20
paramGraphics.drawImage(bd, i3 + cw, az + cx, null); // Anchor: 20
if (ee) {
ay += 16;
if (i3 > 255) {
ay = -3200;
az = c(104);
}
}
int i4 = 2;
do {
i4--;
e locale1 = a6[i4];
if (locale1.ap) {
if ((as == 0) && (i4 == 1))
locale1.e();
locale1.a(paramGraphics, (ee) && ((as == 0) || (i4 == 0)));
}
}
while (i4 > 0);
paramGraphics.drawImage(a8[1], 109, 168, null); // Anchor: 20
int i6 = 2;
do {
i6--;
int i5 = 0;
paramGraphics.drawImage(a9[0], aa[i6], ab[i6], null); // Anchor: 3
if (as == 1) {
// if(j.d && var7 < ap || !j.d && var7 >= ao) {
// var15 = true;
// }
}
else
i5 = 1;
if ((i5 != 0) && (ee) && (c(3) == 0))
if (ae[i6] != false) {
aa[i6] -= 2;
if (aa[i6] < -32) {
aa[i6] = 287;
ab[i6] = c(104);
}
}
else {
aa[i6] += 2;
if (aa[i6] > 287) {
aa[i6] = -32;
ab[i6] = c(104);
}
}
}
while (i6 > 0);
int i7 = 50;
do {
i7--;
if (bu[i7].a != -1)
bu[i7].a(paramGraphics);
}
while (i7 > 0);
paramGraphics.translate(ai, aj);
if (s < 208) {
int i8 = r * r / 255;
int i9 = ai * i8 / ak;
paramGraphics.setColor(new Color(6684672));
paramGraphics.fillRect(0, s - 2, r, 2);
paramGraphics.setColor(new Color(16711680));
paramGraphics.fillRect(i9, s - 2, i8, 2);
}
if ((aaa == 1) && ((as == 0) || (ddd))) {
e locale2;
if (as == 0)
locale2 = bx;
else
locale2 = a6[1];
int i10 = locale2.d;
int i11 = locale2.e;
if (!a(i10 - 8, i11 - 8, 16, 16)) {
e locale3 = locale2.ao;
int i12 = b(locale3.d, locale3.e, i10, i11);
int i13;
// Drawing in-game arrow pointing to opponent
if ((i12 >= 45) && (i12 < 135)) {
i13 = i11 - aj;
if (i13 < 4)
i13 = 4;
else if (i13 > s - 4)
i13 = s - 4;
paramGraphics.drawImage(a8[63], r, i13, null); // Anchor: 10
}
else if ((i12 >= 135) && (i12 < 225)) {
i13 = i10 - ai;
if (i13 < 4)
i13 = 4;
else if (i13 > r - 4)
i13 = r - 4;
paramGraphics.drawImage(a8[61], i13, s, null); // Anchor: 33
}
else if ((i12 >= 225) && (i12 < 315)) {
i13 = i11 - aj;
if (i13 < 4)
i13 = 4;
else if (i13 > s - 4)
i13 = s - 4;
paramGraphics.drawImage(a8[62], 0, i13, null); // Anchor: 6
}
else if ((i12 > 315) || (i12 < 45)) {
i13 = i10 - ai;
if (i13 < 4)
i13 = 4;
else if (i13 > r - 4)
i13 = r - 4;
paramGraphics.drawImage(a8[60], i13, 0, null); // Anchor: 17
}
}
}
if (aw > 0) {
if ((ii) && ((as == 0) || (ddd)))
if (ax == 3)
paramGraphics.drawImage(bc, 2, 2, null); // Anchor: 20
else
paramGraphics.drawImage(bc, r - 2, 2, null); // Anchor: 24
aw -= 1;
if (aw == 0)
g();
}
if (au > 0) {
a(paramGraphics, bk[38], false);
au -= 1;
}
}
public static boolean a(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
return (paramInt1 >= ai - paramInt3) && (paramInt1 <= ai + r) && (paramInt2 >= aj - paramInt4) && (paramInt2 <= aj + s);
}
public static void g() {
if ((as == 0) && (!j)) {
if (a6[0].m >= 10) {
by = a6[0];
bz = a6[1];
l = false;
m = false;
int i1 = 0;
n = by.at;
a3 = a6[1].u;
if (bz.m < ad[a3]) {
ad[a3] = bz.m;
i1 = 1;
}
if (by.af > ac[a3]) {
ac[a3] = by.af;
m = true;
}
if (n)
ag[a3] = true;
if ((a3 < 3) && (af[a3] == false)) {
j(a3);
l = true;
}
if ((l) || (m) || (n) || (i1 != 0))
c(false);
g.a(0);
aaa = 4;
if (as == 1)
bt = (byte)(bt + 128);
}
else if (a6[1].m >= 10) {
g.a(0);
aaa = 4;
by = a6[1];
bz = a6[0];
}
}
else if (as == 1)
if (a6[0].m >= 10) {
by = a6[0];
bz = a6[1];
g.a(0);
aaa = 4;
}
else if (a6[1].m >= 10) {
bz = a6[0];
by = a6[1];
g.a(0);
aaa = 4;
}
if (aaa == 4)
a1 = Math.max(r, s) >> 1;
}
public static void b(e parame) {
aw = 45;
if ((!ii) || ((as == 1) && (!ddd)) || (parame.ae == -1))
return;
av = parame.ae;
ax = parame.i;
int i1 = (av - 35) * 4;
if (parame.m < parame.ao.m)
i1 += 2;
i1 += c(2);
String[] arrayOfString = bm.a(bl[i1], t - 12 - 32);
bg.setColor(new Color(16777215));
bg.fillRect(4, 2, t - 8 + 1, u - 4);
Image localImage = a8[av];
if (ax == 3) {
bg.drawImage(localImage, 4, 4, null); // Anchor: 20
bm.a(bg, arrayOfString, 40, 4, 20);
}
else {
bg.drawImage(localImage, t - 4, 4, null); // Anchor: 24
bm.a(bg, arrayOfString, t - 8 - 32, 4, 24);
}
}
public static void b(Graphics paramGraphics) {
paramGraphics.setColor(new Color(52479));
paramGraphics.fillRect(0, 0, r, s);
bi.setColor(new Color(16751203));
bi.fillRect(2, 2, 103, 78);
bi.drawImage(a8[69], 0, 0, null); // Anchor: 20
bi.fillRect(11, 58, 77, 18);
int i1 = 8;
for (int i2 = 0; i2 < 4; i2++) {
bi.setColor(new Color(b4[i2]));
bi.fillRect(4, i1, 96, 13);
Image localImage = a8[(47 + i2)];
if ((i2 > 0) && (af[(i2 - 1)] == false))
localImage = a8[52];
bi.drawImage(localImage, 7, i1 - 1, null); // Anchor: 20
bm.a(bi, ac[i2] + "%", 65, i1 + 7, 6);
if (ad[i2] < 10)
bm.a(bi, "10-" + ad[i2], 26, i1 + 7, 6);
if (ag[i2] != false)
bi.drawImage(a8[71], 87, i1 - 1, null); // Anchor: 20
i1 += 17;
}
bi.drawImage(a8[70], 50, 8, null); // Anchor: 20
int i3 = r >> 1;
int i4 = s >> 1;
paramGraphics.drawImage(be, i3, i4, null); // Anchor: 3
bm.a(paramGraphics, bk[19], i3 - (be.getWidth(null) >> 1) + 8, i4 - (be.getHeight(null) >> 1) - 4, 20);
a(paramGraphics, bk[7], false);
a(paramGraphics, bk[20], true);
}
public static void c(Graphics paramGraphics) {
paramGraphics.setColor(new Color(52479));
paramGraphics.fillRect(0, 0, r, s);
bj.setColor(new Color(15466636));
bj.fillRect(0, 0, 128, 100);
bj.setColor(new Color(16751203));
bj.fillRect(2, 2, 124, 96);
bj.setColor(new Color(16776960));
bj.fillRect(57, 7, 12, 60);
bj.fillRect(7, 34, 114, 12);
if (at == 0)
bj.fillRect(5, 68, 12, 10);
if (at != 2)
bj.fillRect(5, 80, 12, 10);
String[] arrayOfString;
switch (at) {
case 0:
bj.drawImage(a7[17], 63, 39, null); // Anchor: 3
bm.a(bj, bk[22], 62, 14, 3);
bm.a(bj, bk[23], 62, 60, 3);
arrayOfString = bm.a(bk[25], 46);
bm.a(bj, arrayOfString, 4, 32, 20);
arrayOfString = bm.a(bk[24], 46);
bm.a(bj, arrayOfString, 124, 32, 24);
bm.a(bj, "#", 11, 73, 3);
bm.a(bj, "*", 11, 85, 3);
bm.a(bj, bk[26], 20, 73, 6);
bm.a(bj, bk[27], 20, 85, 6);
bm.a(bj, bk[23], 62, 60, 3);
break;
case 1:
bj.drawImage(a8[21], 63, 42, null); // Anchor: 3
bj.drawImage(a8[28], 63, 32, null); // Anchor: 3
arrayOfString = bm.a(bk[28], 46);
bm.a(bj, arrayOfString, 4, 32, 20);
arrayOfString = bm.a(bk[29], 46);
bm.a(bj, arrayOfString, 124, 32, 24);
bm.a(bj, "*", 11, 85, 3);
bm.a(bj, bk[30], 20, 85, 6);
break;
case 2:
bj.setClip(46, 40, 33, 16);
bj.drawImage(ba, 0, 60, null); // Anchor: 36
bj.setClip(0, 0, 128, 100);
bj.drawImage(a8[23], 63, 37, null); // Anchor: 3
arrayOfString = bm.a(bk[28], 46);
bm.a(bj, arrayOfString, 4, 32, 20);
arrayOfString = bm.a(bk[29], 46);
bm.a(bj, arrayOfString, 124, 32, 24);
bm.a(bj, bk[31], 5, 87, 6);
}
a(paramGraphics, bk[7], false);
a(paramGraphics, bk[6], true);
paramGraphics.drawImage(bf, r >> 1, s >> 1, null); // Anchor: 3
}
public static void d(Graphics paramGraphics) {
paramGraphics.setColor(new Color(52479));
paramGraphics.fillRect(0, 0, r, s);
bi.setColor(new Color(b3[(aaa - 8)]));
bi.fillRect(2, 2, 103, 78);
bi.drawImage(a8[69], 0, 0, null); // Anchor: 20
bi.setColor(new Color(16777215));
bi.fillRect(13, 60, 62, 14);
bi.drawImage(a8[(by.ae + 8)], 6, 6, null); // Anchor: 20
int i1 = bz.ae + 8;
if (aaa == 10)
i1 = 48 + a3;
bi.drawImage(a8[i1], 85, 60, null); // Anchor: 20
bm.a(bi, bk[(12 + aaa - 8)], 41, 66, 3);
String[] arrayOfString = bm.a(bk[(15 + aaa - 8)], 78);
bm.a(bi, arrayOfString, 25, 6, 20);
if (aaa == 9)
bi.drawImage(a8[68], 6, 23, null); // Anchor: 20
paramGraphics.drawImage(be, r >> 1, s >> 1, null); // Anchor: 3
a(paramGraphics, bk[7], false);
}
public static void e(Graphics paramGraphics) {
int i1 = 124;
paramGraphics.setColor(new Color(52479));
paramGraphics.fillRect(0, 0, r, i1);
paramGraphics.translate(-ce, 0);
int i2 = 0;
while (i2 < 255 + ce) {
paramGraphics.drawImage(ba, i2, i1, null); // Anchor: 20
paramGraphics.drawImage(bb, i2, 0, null); // Anchor: 20
i2 += 128;
}
paramGraphics.translate(ce, 0);
ce += 2;
if (ce > 128)
ce = 0;
int i3 = 3;
do {
i3--;
b5[i3] -= 1 + i3;
paramGraphics.drawImage(a9[0], b5[i3], b6[i3], null); // Anchor: 3
if (b5[i3] < -32) {
int i4 = s / 3;
b6[i3] = (i4 * i3 + c(i4));
b5[i3] = (r + 32);
}
}
while (i3 > 0);
int i4 = b7 >> 6;
int i5 = b9 >> 6;
int i6 = b8 >> 6;
int i7 = cb >> 6;
paramGraphics.drawImage(a8[64], i4, 20, null); // Anchor: 10
paramGraphics.drawImage(cj, i4 - 25, 17, null); // Anchor: 10
int i8 = c(3);
int i9 = ca >> 6;
paramGraphics.drawImage(a8[64], i5, 80 + i8 + i9, null); // Anchor: 10
paramGraphics.drawImage(ck, i5 - 25, 77 + i8 + i9, null); // Anchor: 10
paramGraphics.drawImage(a8[(14 + c(3))], i5 - 56, 75 + i9, null); // Anchor: 3
paramGraphics.drawImage(a8[(14 + c(3))], i5 - 14, 85 + i9, null); // Anchor: 3
paramGraphics.drawImage(a8[(14 + c(3))], i5 - 38, 93 + i9, null); // Anchor: 3
if (cf - 32 - (cd >> 1) < r >> 1)
cf = i6;
paramGraphics.drawImage(a8[65], cf - 24, 50, null); // Anchor: 10
paramGraphics.drawImage(cl, cf - 32, 50, null); // Anchor: 10
paramGraphics.drawImage(a8[66], cf - 32 - cd, 50, null); // Anchor: 10
paramGraphics.drawImage(ch, i6, 50, null); // Anchor: 10
if (cg - 32 - (cd >> 1) < r >> 1)
cg = i7;
paramGraphics.drawImage(a8[65], cg - 24, 110, null); // Anchor: 10
paramGraphics.drawImage(cm, cg - 32, 110, null); // Anchor: 10
paramGraphics.drawImage(a8[66], cg - 32 - cd, 110, null); // Anchor: 10
paramGraphics.drawImage(ci, i7, 110, null); // Anchor: 10
cc += 1;
if (cc > 350)
aaa = 7;
if ((cc > 0) && ((b7 >> 6 < (r >> 1) + (r >> 2)) || (cc > 300)))
b7 += 50;
if (cc > 70)
b8 += 120;
if (cc > 100) {
if ((b9 >> 6 < (r >> 1) + (r >> 2)) || (cc > 300))
b9 += 50;
if (i5 > (r >> 1) + (r >> 2))
ca += 60;
}
if (cc > 170)
cb += 120;
}
public static void a(e parame1, e parame2) {
aaa = 6;
a1 = 0;
b8 = b.b9 = b.cb = b.ca = b.cc = b.cf = b.cg = 0;
b7 = 1024;
if (parame1.i == 3)
ch = a7[16];
else
ch = a8[67];
if (parame2.i == 3)
ci = a7[16];
else
ci = a8[67];
cj = a8[(parame1.ae + 8)];
ck = a8[(parame2.ae + 8)];
cn.setColor(new Color(16514043));
cn.fillRect(0, 0, cd, 15);
cn.setColor(new Color(4671303));
cn.drawLine(0, 0, cd, 0);
cn.drawLine(0, 14, cd, 14);
co.setColor(new Color(16514043));
co.fillRect(0, 0, cd, 15);
co.setColor(new Color(4671303));
co.drawLine(0, 0, cd, 0);
co.drawLine(0, 14, cd, 14);
bm.a(cn, bk[11] + by.an, cd >> 1, 7, 3);
bm.a(co, bk[11] + bz.an, cd >> 1, 7, 3);
int i1 = 3;
do {
i1--;
b5[i1] = c(r);
int i2 = s / 3;
b6[i1] = (i2 * i1 + c(i2));
}
while (i1 > 0);
if (as == 1) {
bp = "";
o = 0;
ddd = false;
}
a(4, 0);
}
public static void f(Graphics paramGraphics) {
int i1 = 5;
int i2 = 130;
int i3 = 40;
int i4 = 20;
int i5 = 10;
int i6 = 20;
paramGraphics.setColor(new Color(3355545));
paramGraphics.fillRect(i1 - i5, i3 - i5 - i6, r - (i1 << 1) + (i5 << 1), i4 * 3 + (i5 << 1) + i6);
paramGraphics.setColor(new Color(16777215));
String str1 = "MASTER";
// if (!j.d)
// str1 = "SLAVE";
paramGraphics.drawString(str1, i1, i3 - i6);
for (int i7 = 0; i7 < 3; i7++) {
paramGraphics.setColor(new Color(16777215));
if (i7 == cq)
paramGraphics.fillRect(i1 - 10, i3 + i7 * i4, 8, 10);
paramGraphics.drawString(cp[i7], i1, i3 + i7 * i4);
String str2 = "";
switch (i7) {
case 0:
str2 = Integer.toString(x);
break;
case 1:
str2 = Integer.toString(y);
break;
case 2:
str2 = Integer.toString(z);
}
paramGraphics.drawString(str2, i2, i3 + i7 * i4);
}
}
public static void c(e parame) {
if (aaa == 4)
return;
int i1 = ct;
if (parame.i == 2)
i1 = cv;
bh.setColor(new Color(15131619));
bh.fillRect(i1, cu, cr, cs);
bh.setColor(new Color(16777215));
bh.fillRect(i1, cu + cs, cr, cs);
c localc = bn;
if (parame == bw)
localc = bo;
String str = Integer.toString(parame.m);
if (str.length() == 1)
str = "0" + str;
localc.a(bh, str, i1 + 2, cu, 20);
a0 = 30;
}
public static void a(Graphics paramGraphics, String paramString, boolean paramBoolean) {
int i1 = bm.a(paramString) + 4;
int i2 = bm.a + 4;
int i3 = 0;
if (!paramBoolean)
i3 = r - i1;
paramGraphics.setColor(new Color(6488245));
paramGraphics.fillRect(i3, s - i2, i1, i2);
paramGraphics.setColor(new Color(16776960));
paramGraphics.fillRect(i3 + 1, s - i2 + 1, i1 - 2, i2 - 2);
bm.a(paramGraphics, paramString, i3 + 2, s - i2 + 2, 20);
}
public void paint(Graphics paramGraphics) {
try {
if (cy >= 0) {
g(paramGraphics);
String str1 = bk[6];
if (c7)
str1 = bk[7];
a(paramGraphics, str1, false);
return;
}
int i3;
int i4;
switch (aaa) {
case 14:
if (q == -1) {
paramGraphics.setColor(new Color(39663));
paramGraphics.fillRect(0, 0, r, s);
bm.a(paramGraphics, bk[45], r >> 1, s >> 1, 3);
}
else {
ba = ImageIO.read(new File("/ad" + q + ".png"));
paramGraphics.drawImage(ba, 0, 0, null); // Anchor: 20
}
break;
case 13:
int i1 = bm.a + 2;
int i2 = s - (i1 << 2) >> 1;
paramGraphics.setColor(new Color(39663));
paramGraphics.fillRect(0, 0, r, s);
bm.a(paramGraphics, bk[32], r >> 1, i2, 17);
bm.a(paramGraphics, bk[33], r >> 1, i2 + i1, 17);
bm.a(paramGraphics, bk[34], r >> 1, i2 + (i1 << 1), 17);
bm.a(paramGraphics, bk[35], r >> 1, i2 + i1 * 3, 17);
paramGraphics.drawImage(a7[1], r - 4, s + 2, null); // Anchor: 40
break;
case 12:
c(paramGraphics);
break;
case 11:
b(paramGraphics);
break;
case 8:
case 9:
case 10:
d(paramGraphics);
break;
case 5:
e(paramGraphics);
break;
case 0:
paramGraphics.drawImage(a8[0], 0, 0, null); // Anchor: 20
break;
case 3:
break;
case 2:
if (!hh) {
ee = false;
a(paramGraphics);
hh = true;
}
g.a(paramGraphics, r, s, r, 1, 2, 4, (g.a == 14) || (g.a == 60) || (g.a == 92) || (g.a == 82) ? 16 : bm.a + 4, bm);
if ((g.a != 66) && (g.a != 50))
a(paramGraphics, bk[1], false);
a(paramGraphics, bk[39], true);
break;
case 4:
paramGraphics.setColor(new Color(0));
paramGraphics.fillRect(0, 0, r, s);
i3 = bw.d - ai;
i4 = bw.e - aj;
paramGraphics.setClip(i3 - a1, i4 - a1, a1 << 1, a1 << 1);
a1 -= 8;
if (a1 <= 0)
a(by, bz);
a(paramGraphics);
break;
case 6:
case 7:
paramGraphics.setColor(new Color(0));
paramGraphics.fillRect(0, 0, r, s);
i3 = r >> 1;
i4 = s >> 1;
paramGraphics.setClip(i3 - a1, i4 - a1, a1 << 1, a1 << 1);
e(paramGraphics);
if (aaa == 6) {
a1 += 8;
if (a1 > r << 1)
aaa = 5;
}
else {
a1 -= 8;
if (a1 < 0) {
a();
c();
}
}
break;
case 1:
a(paramGraphics);
if (ff)
f(paramGraphics);
if (a0 > 0) {
a0 -= 1;
String str2 = bw.m + " - " + bx.m;
bm.a(paramGraphics, str2, r >> 1, s >> 1, 3);
}
break;
}
if ((!ddd) && (aaa == 1))
bm.a(paramGraphics, bp, r >> 1, 0, 17);
}
catch (Exception localException) {
localException.printStackTrace();
}
}
public static void a(String paramString, int paramInt) {
cy = paramInt;
if (c2 == paramString) {
if (paramInt >= 0)
cz = 0;
else
cz = 2;
c8 = 0;
return;
}
c2 = paramString;
int i1 = bm.a(paramString);
if (i1 > 94) {
a(paramString, 94, 58);
c0 = 100;
}
else {
c0 = i1 + 4 + 2;
a(paramString, i1, 58);
}
c1 = c4 + 4 + 2;
cz = 2;
}
public static void g(Graphics paramGraphics) {
if (cz > -1) {
int i1 = h() != 0 ? 1 : 0;
int i2 = c0;
int i3 = c1;
i2 >>= cz;
i3 >>= cz;
int i4 = r - i2 >> 1;
int i5;
if (al - aj < c1)
i5 = (s >> 1) - i3 + bm.a + 8;
else
i5 = s - i3 - bm.a - 8;
paramGraphics.setColor(new Color(6724044));
int i6 = i2;
if (i1 != 0)
i6 += 9;
paramGraphics.fillRect(i4, i5, i6, i3 + 1);
i4++;
i5++;
paramGraphics.setColor(new Color(6488245));
int i7 = i4 + i2 - 2;
int i8 = i3 - 2;
paramGraphics.drawRect(i4, i5, i7 - i4, i8);
if (i1 != 0)
paramGraphics.drawRect(i7, i5, 8, i8);
if (cz == 0) {
i4 += 2;
i5 += 2;
a(paramGraphics, i4, i5);
paramGraphics.setColor(new Color(16777215));
int i9 = i4 + i2 - 2;
if ((h() & 0x1) != 0)
paramGraphics.drawImage(a8[58], i9, i5, null); // Anchor: 20
if ((h() & 0x2) != 0)
paramGraphics.drawImage(a8[59], i9, i5 + i3 - 1 - 2 - 5, null); // Anchor: 20
}
cz -= 1;
}
}
public void showNotify() {
i.b();
if (aaa == 1) {
g.a(30);
aaa = 2;
hh = false;
g.h = 2;
}
g.h = 2;
}
public static void a(String paramString, int paramInt1, int paramInt2) {
c8 = 0;
c3 = paramInt1;
c4 = paramInt2;
db = 0;
int i1 = 40;
char[] arrayOfChar = paramString.toCharArray();
int i2 = 0;
int i3 = 0;
int i4 = 0;
int i5 = 0;
int i6 = 0;
int i7 = 0;
int i8 = 0;
while (i7 == 0) {
char c10 = arrayOfChar[i2];
if (c10 == ' ') {
i5 += bm.b;
i3 = i2;
i6 = 0;
}
else if (c10 == '\n') {
i8 = 1;
i3 = i2;
i6 = 0;
}
else {
int i9 = bm.a(c10) + 0;
i6 += i9;
i5 += i9;
if (i5 > paramInt1)
i8 = 1;
}
if (i2 == arrayOfChar.length - 1) {
i3 = i2 + 1;
i8 = 1;
i7 = 1;
if (i4 > i2);
}
else if (i8 != 0) {
int i9 = i3 <= i4 ? 1 : 0;
if (i9 != 0)
i3 = i2;
dd[db] = new String(arrayOfChar, i4, i3 - i4);
if (i9 != 0) {
i4 = i3;
i5 = 0;
}
else {
i4 = i3 + 1;
i5 = i6;
}
i8 = 0;
db += 1;
}
i2++;
}
c9 = new int[12];
char c10 = '\000';
int i9 = 0;
c5 = 0;
int i10 = 0;
int i11 = 0;
while (i10 < db) {
String str = dd[i10];
int i12 = 0;
i12 = bm.a + 1;
if (i12 + i11 > c4)
i9 = 1;
i11 += i12;
if (((i9 != 0) || (i10 == db - 1)) && (i11 > c5))
c5 = i11;
if (i9 != 0) {
c9[(c10++)] = i10;
i11 = i12;
i9 = 0;
}
i10++;
}
da = c10;
c9[(c10++)] = db;
if (da > 0)
c5 -= bm.a + 1;
c4 = c5;
c7 = da == 0;
}
public static void a(Graphics paramGraphics, int paramInt1, int paramInt2) {
c6 = true;
int i1 = 0;
int i2 = 0;
while (true) {
if (i1 == c9[i2]) {
i2++;
if (i2 > c8)
break;
}
String str = dd[i1];
if (i2 == c8) {
bm.a(paramGraphics, str, paramInt1, paramInt2, 20);
paramInt2 += bm.a + 1;
}
i1++;
}
}
public static void b(int paramInt) {
if (paramInt == 2) {
if (c8 < da)
c8 += 1;
if (c8 == da)
c7 = true;
}
else if ((paramInt == 1) && (c8 > 0)) {
c8 -= 1;
}
c6 = false;
}
public static int h() {
int i1 = 0;
if (c8 > 0)
i1 |= 1;
if (c8 < da)
i1 |= 2;
return i1;
}
public static int c(int paramInt) {
return Math.abs(w.nextInt() % paramInt);
}
public static void i()
throws IOException {
a5.readFully(de);
a5.readFully(dh);
a5.readFully(di);
df = new byte[(a5.readShort() & 0xFFFF) + 13];
a5.readFully(df);
a5.readFully(dg);
}
public static byte[] j()
throws IOException {
int i1 = a5.readShort() & 0xFFFF;
byte[] arrayOfByte1 = new byte[i1];
a5.readFully(arrayOfByte1);
int i2 = df.length;
byte[] arrayOfByte2 = new byte[33 + df.length + i1 + 24];
System.arraycopy(de, 0, arrayOfByte2, 0, 8);
System.arraycopy(dh, 0, arrayOfByte2, 11, 15);
arrayOfByte2[18] = a5.readByte();
arrayOfByte2[19] = a5.readByte();
arrayOfByte2[22] = a5.readByte();
arrayOfByte2[23] = a5.readByte();
a(arrayOfByte2, 12, 17);
int i3 = 33;
System.arraycopy(df, 0, arrayOfByte2, i3, i2);
i3 += i2;
i3 += 2;
arrayOfByte2[(i3++)] = ((byte)(i1 >> 8));
arrayOfByte2[(i3++)] = ((byte)i1);
System.arraycopy(di, 0, arrayOfByte2, i3, 4);
i3 += 4;
System.arraycopy(arrayOfByte1, 0, arrayOfByte2, i3, i1);
a(arrayOfByte2, i3 - 4, i1 + 4);
i3 += i1 + 4;
System.arraycopy(dg, 0, arrayOfByte2, i3, 12);
return arrayOfByte2;
}
public static Image[] d(int paramInt)
throws IOException {
Image[] arrayOfImage = new Image[paramInt];
for (int i1 = 0; i1 < paramInt; i1++)
arrayOfImage[i1] = k();
return arrayOfImage;
}
public static Image k()
throws IOException {
byte[] arrayOfByte = j();
Image localImage = ImageIO.read(new ByteArrayInputStream(arrayOfByte));
return localImage;
}
public static Image[] e(int paramInt)
throws IOException {
Image[] arrayOfImage = new Image[paramInt];
for (int i1 = 0; i1 < paramInt; i1++)
arrayOfImage[i1] = l();
return arrayOfImage;
}
public static void a(byte[] paramArrayOfByte, int paramInt1, int paramInt2) {
long l1 = 4294967295L;
if (!dk) {
int i2 = 256;
do {
i2--;
long l2 = i2;
for (int i3 = 0; i3 < 8; i3++)
if ((l2 & 1L) != 0L)
l2 = 0xEDB88320 ^ l2 >> 1;
else
l2 >>= 1;
dj[i2] = ((int)l2);
}
while (i2 > 0);
dk = true;
}
for (int i1 = 0; i1 < paramInt2; i1++)
l1 = dj[((int)((l1 ^ paramArrayOfByte[(paramInt1 + i1)] & 0xFF) & 0xFF))] & 0xFFFFFFFF ^ l1 >> 8;
l1 ^= 4294967295L;
paramInt1 += paramInt2;
paramArrayOfByte[paramInt1] = ((byte)(int)(l1 >> 24));
paramArrayOfByte[(paramInt1 + 1)] = ((byte)(int)(l1 >> 16));
paramArrayOfByte[(paramInt1 + 2)] = ((byte)(int)(l1 >> 8));
paramArrayOfByte[(paramInt1 + 3)] = ((byte)(int)l1);
}
public static String[] b(String paramString)
throws IOException {
DataInputStream localDataInputStream = new DataInputStream(paramString.getClass().getResourceAsStream(paramString));
int i1 = localDataInputStream.readInt();
String[] arrayOfString = new String[i1];
for (int i2 = 0; i2 < i1; i2++)
arrayOfString[i2] = localDataInputStream.readUTF();
return arrayOfString;
}
public static Image l() {
try {
int i1 = a5.readInt();
byte[] arrayOfByte = new byte[i1];
a5.readFully(arrayOfByte);
return ImageIO.read(new ByteArrayInputStream(arrayOfByte));
}
catch (Exception localException) {
localException.printStackTrace();
}
return null;
}
public static byte[] m() {
try {
int i1 = a5.readInt();
byte[] arrayOfByte = new byte[i1];
a5.readFully(arrayOfByte);
return arrayOfByte;
}
catch (Exception localException) {
localException.printStackTrace();
}
return null;
}
public static int f(int paramInt) {
try {
paramInt = g(paramInt + 90);
return h(paramInt);
}
catch (Exception localException) {
System.out.println("cos: " + localException);
}
return 0;
}
public static int g(int paramInt) {
if (paramInt < 0)
return 360 + paramInt;
if (paramInt > 359)
return paramInt - 360;
return paramInt;
}
public static int h(int paramInt) {
try {
if (paramInt < 90)
return dl[paramInt];
if (paramInt == 90)
return 128;
if (paramInt < 180)
return dl[(180 - paramInt)];
if (paramInt == 180)
return 0;
if (paramInt < 270)
return -dl[(paramInt - 180)];
if (paramInt == 270)
return -128;
if (paramInt < 360)
return -dl[(360 - paramInt)];
return 1;
}
catch (Exception localException) {
System.out.println("sin: " + localException);
}
return 1;
}
public static int b(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
int i1 = 1;
int i2 = 1;
int i3 = paramInt1 - paramInt3;
int i4 = paramInt2 - paramInt4;
if (i4 < 0)
i2 = 0;
if (i3 < 0)
i1 = 0;
if (i3 == 0)
return i4 >= 0 ? 0 : 180;
if (i4 == 0)
return i3 >= 0 ? 270 : 90;
i3 = Math.abs(i3);
i4 = Math.abs(i4);
int i5 = i3 + i4;
i3 = i3 * 10 / i5;
i4 = i4 * 10 / i5;
if ((i1 == 0) && (i2 != 0))
return dm[i3][i4];
if ((i1 == 0) && (i2 == 0))
return 90 + dm[i4][i3];
if ((i1 != 0) && (i2 == 0))
return 180 + dm[i3][i4];
if ((i1 != 0) && (i2 != 0))
return 270 + dm[i4][i3];
return -1;
}
public static int b(int paramInt1, int paramInt2) {
if (Math.abs(paramInt1 - paramInt2) <= e.a0)
return 0;
if (paramInt2 >= paramInt1) {
int i1 = paramInt2 - paramInt1;
int i2 = 360 - paramInt2 + paramInt1;
if (i1 <= i2)
return 3;
return 2;
}
int i1 = paramInt1 - paramInt2;
int i2 = 360 - paramInt1 + paramInt2;
if (i1 <= i2)
return 2;
return 3;
}
public void a(String paramString1, String paramString2) {
}
public static void i(int paramInt) {
du = dx[paramInt].length();
dv = 0;
d6 = true;
d5 = System.currentTimeMillis() + d7;
dw = paramInt;
du = dx[dw].length();
dv = 0;
}
} | TheRealPinkie/BT_Biplanes_src | b.java |
1,011 |
package sidh;
/**************************************************************************************************
*
* Implements elements over finite field GF(p) and the quadratic extension GF(p^2)
*
**************************************************************************************************/
import java.math.BigInteger;
import java.util.Arrays;
import java.lang.System;
import java.lang.Math;
class InvalidFieldException extends Exception {
}
class Felm {
/* Elements of GF(p) */
// Set p to a placeholder value until the prime has been set
public static BigInteger p = BigInteger.valueOf(2);
private BigInteger value;
public static int primesize = 1; // number of bytes needed to represent the prime
// Constants of the class
public static final Felm ZERO = new Felm (BigInteger.ZERO);
public static final Felm ONE = new Felm (BigInteger.ONE);
public Felm (BigInteger v) {
value = v.mod(p);
}
public Felm (Felm a) {
value = a.fpGetValue();
}
public Felm (byte[] bytes) {
value = new BigInteger (bytes);
}
public static void setPrime (BigInteger pr) throws InvalidFieldException {
if (pr.isProbablePrime(10))
p = pr;
else
throw new InvalidFieldException();
primesize = (pr.bitLength() / 8) + 1;
}
public static BigInteger getPrime() {
return p;
}
public BigInteger fpGetValue() {
return value;
}
public Felm fpAdd (Felm y) {
return new Felm (value.add (y.value));
}
public Felm fpSub (Felm y) {
return fpAdd (y.fpNegate()); // this - y = this + (-y)
}
public Felm fpMult (Felm y) {
return new Felm (value.multiply (y.value));
}
public Felm fpSqr() {
return fpMult(this);
}
public boolean fpIsZero() {
return value.equals(BigInteger.ZERO);
}
public boolean fpIsEven() {
BigInteger c = value.and(BigInteger.ONE);
return c.equals(BigInteger.ZERO);
}
public boolean fpIsOdd() {
return !fpIsEven();
}
public boolean fpEquals (Felm y) {
return value.equals (y.value);
}
public boolean fpIsLessThan (Felm y) {
return value.compareTo (y.value) == -1;
}
public boolean fpIsGreaterThan (Felm y) {
return value.compareTo (y.value) == 1;
}
public Felm fpNegate() {
return new Felm (p.subtract(value));
}
public Felm fpInverse() {
return new Felm (value.modInverse(p));
}
public Felm fpDiv2() {
BigInteger v = value;
if (fpIsOdd())
v = v.add(p); // If this is odd, adding p makes it even
v = v.shiftRight(1); // Divide by two = right shift by one
return new Felm (v);
}
public Felm fpSwap (Felm y, BigInteger option) {
// Constant time swap regardless of whether option is 0 or 1
BigInteger temp, mask, yval;
yval = y.value;
mask = option.negate(); // option = 1 => mask = 1...1 because BigInteger
// automatically sign extends as necessary
temp = mask.and(value.xor(yval)); // temp = mask & (this.value xor y.value)
value = temp.xor(value);
yval = temp.xor(yval);
return new Felm (yval);
}
public String toString() {
return value.toString();
}
// Creates a byte[] representation of the field element. Returns the same size array regardless
// of the element so each one is the same number of bytes as needed to represent the prime.
public byte[] toByteArray() {
byte[] retval = new byte[primesize];
Arrays.fill (retval, (byte) 0);
int eltsize = (value.bitLength() / 8) + 1;
int offset = primesize - eltsize;
// The return array was filled with zeros so copy from offset to the end of the element. This
// way the zero padding is at the beginning and not the end since adding zeros to the end of a
// binary representation of a number multiplies the number by a power of 2.
System.arraycopy (value.toByteArray(), 0, retval, offset, eltsize);
return retval;
}
}
class F2elm {
/* Elements of the quadratic extension field GF(p^2): x0 + x1*i */
private final Felm x0;
private final Felm x1;
// Constants of the class
public static final F2elm ZERO = new F2elm (Felm.ZERO, Felm.ZERO);
public static final F2elm ONE = new F2elm (Felm.ONE, Felm.ZERO);
public F2elm (BigInteger a0, BigInteger a1) {
x0 = new Felm (a0);
x1 = new Felm (a1);
}
public F2elm (Felm a0, Felm a1) {
x0 = a0;
x1 = a1;
}
public F2elm (F2elm a) {
x0 = a.x0;
x1 = a.x1;
}
public F2elm (byte[] bytes) {
int len = (bytes.length) / 2;
x0 = new Felm (Arrays.copyOfRange (bytes, 0, len));
x1 = new Felm (Arrays.copyOfRange (bytes, len, 2*len));
}
public Felm f2Get0() {
return x0;
}
public Felm f2Get1() {
return x1;
}
public boolean f2Equals (F2elm y) {
return x0.fpEquals(y.x0) && x1.fpEquals(y.x1);
}
public F2elm f2Add (F2elm y) {
Felm newx0, newx1;
newx0 = x0.fpAdd(y.x0);
newx1 = x1.fpAdd(y.x1);
return new F2elm (newx0, newx1);
}
public F2elm f2Sub (F2elm y) {
Felm newx0, newx1;
newx0 = x0.fpSub(y.x0);
newx1 = x1.fpSub(y.x1);
return new F2elm (newx0, newx1);
}
public F2elm f2Negate() {
return new F2elm (x0.fpNegate(), x1.fpNegate());
}
public F2elm f2Sqr() {
// Compute c = this * this = (x0 + i*x1)^2 = x0^2 - x1^2 + i*2x0x1
Felm t1, t2, t3, c0, c1;
t1 = x0.fpAdd(x1); // t1 = x0 + x1
t2 = x0.fpSub(x1); // t2 = x0 - x1
t3 = x0.fpAdd(x0); // t3 = 2 * x0
c0 = t1.fpMult(t2); // c0 = (x0+x1)(x0-x1)
c1 = t3.fpMult(x1); // c1 = 2*x0*x1
return new F2elm (c0, c1);
}
public F2elm f2Mult (F2elm y) {
// compute c = this * y = (x0 + i*x1) * (y0 + i*y1) = x0y0 - x1y1 + i*(x0y1 + x1y0)
Felm t1, t2, c0, c1, y0, y1;
y0 = y.x0;
y1 = y.x1;
t1 = x0.fpMult(y0); // t1 = x0 * y0
t2 = x1.fpMult(y1); // t2 = x1 * y1
c0 = t1.fpSub(t2); // c0 = (x0*y0) - (x1*y1))
// Using extra additions, but fewer multiplications
t1 = t1.fpAdd(t2); // t1 = (x0*y0) + (x1*y1)
t2 = x0.fpAdd(x1); // t2 = x0 + x1
c1 = y0.fpAdd(y1); // c1 = y0 + y1
c1 = t2.fpMult(c1); // c1 = (x0+x1)(y0+y1)
c1 = c1.fpSub(t1); // c1 = (x0+x1)(y0+y1) - x0*y0 - x1*y1
// = (x0*y1) + (x1*y0)
return new F2elm (c0, c1);
}
public boolean f2IsEven() {
return x0.fpIsEven() && x1.fpIsEven();
}
public F2elm f2Div2() {
Felm c0, c1;
c0 = x0.fpDiv2();
c1 = x1.fpDiv2();
return new F2elm (c0, c1);
}
public F2elm f2Inverse() {
// Compute inverse c = (x0 - x1*i) / (x0^2 + x1^2)
Felm t0, t1, c0, c1;
t0 = x0.fpSqr(); // t0 = x0^2
t1 = x1.fpSqr(); // t1 = x1^2
t0 = t0.fpAdd(t1); // t0 = x0^2 + x1^2
t0 = t0.fpInverse(); // t0 = 1 / (x0^2 + x1^2)
t1 = x1.fpNegate(); // t1 = -x1
c0 = t0.fpMult(x0); // c0 = x0 / (x0^2 + x1^2)
c1 = t1.fpMult(t0); // c1 = -x1 / (x0^2 + x1^2)
return new F2elm (c0, c1);
}
public static F2elm[] inv4Way (F2elm z0, F2elm z1, F2elm z2, F2elm z3) {
// Computes simultaneous inversion of 4 elements
F2elm res[] = new F2elm[4];
res[0] = z0.f2Mult(z1); // res0 = z0*z1
res[1] = z2.f2Mult(z3); // res1 = z2*z3
res[2] = res[0].f2Mult(res[1]); // res2 = z0*z1*z2*z3
res[3] = res[2].f2Inverse(); // res3 = 1/(z0*z1*z2*z3)
res[2] = res[1].f2Mult(res[3]); // res2 = 1/(z2*z3)
res[3] = res[0].f2Mult(res[3]); // res3 = 1/(z0*z1)
res[0] = res[2].f2Mult(z1); // res0 = 1/z0
res[1] = res[2].f2Mult(z0); // res1 = 1/z1
res[2] = res[3].f2Mult(z3); // res2 = 1/z2
res[3] = res[3].f2Mult(z2); // res3 = 1/z3
return res;
}
public F2elm f2Swap (F2elm y, BigInteger option) {
// Constant time swap regardless of whether option is 0 or 1
Felm y0, y1;
y0 = x0.fpSwap(y.x0, option);
y1 = x1.fpSwap(y.x1, option);
return new F2elm (y0, y1);
}
public F2elm f2Select (F2elm y, BigInteger option) {
// Return this if option = 0 and y if option = 1
BigInteger y0, y1, z0, z1, mask, bix0, bix1;
mask = option.negate(); // if option = 1 then mask = 1...1 because BigInteger
// automatically sign extends as necessary
// Get x0, x1, y0, y1 as their BigInteger representations
y0 = (y.x0).fpGetValue();
y1 = (y.x1).fpGetValue();
bix0 = x0.fpGetValue();
bix1 = x1.fpGetValue();
z0 = bix0.xor(y0); // z0 = x0 xor y0
z1 = bix1.xor(y1); // z1 = x1 xor y1
z0 = z0.and(mask); // if mask = 0 then z0 = 0 else z0 = x0 xor y0
z1 = z1.and(mask); // if mask = 0 then z1 = 0 else z1 = x1 xor y1
z0 = bix0.xor(z0); // if mask = 0 then z0 = x0
// else z0 = x0 xor x0 xor y0 = y0
z1 = bix1.xor(z1); // if mask = 0 then z1 = x1
// else z1 = x1 xor x1 xor y1 = y1
return new F2elm (z0, z1);
}
public String toString() {
return x1 + "*i + " + x0;
}
public byte[] toByteArray() {
byte[] retval = new byte[2*Felm.primesize];
System.arraycopy (x0.toByteArray(), 0, retval, 0, Felm.primesize);
System.arraycopy (x1.toByteArray(), 0, retval, Felm.primesize, Felm.primesize);
return retval;
}
}
| dconnolly/sidh-java | Fp.java |
1,012 | class Solution {
public int[] sortItems(int n, int m, int[] group, List<List<Integer>> beforeItems) {
// If an item belongs to zero group, assign it a unique group id.
int groupId = m;
for (int i = 0; i < n; i++) {
if (group[i] == -1) {
group[i] = groupId;
groupId++;
}
}
// Sort all item regardless of group dependencies.
Map<Integer, List<Integer>> itemGraph = new HashMap<>();
int[] itemIndegree = new int[n];
for (int i = 0; i < n; ++i) {
itemGraph.put(i, new ArrayList<>());
}
// Sort all groups regardless of item dependencies.
Map<Integer, List<Integer>> groupGraph = new HashMap<>();
int[] groupIndegree = new int[groupId];
for (int i = 0; i < groupId; ++i) {
groupGraph.put(i, new ArrayList<>());
}
for (int curr = 0; curr < n; curr++) {
for (int prev : beforeItems.get(curr)) {
// Each (prev -> curr) represents an edge in the item graph.
itemGraph.get(prev).add(curr);
itemIndegree[curr]++;
// If they belong to different groups, add an edge in the group graph.
if (group[curr] != group[prev]) {
groupGraph.get(group[prev]).add(group[curr]);
groupIndegree[group[curr]]++;
}
}
}
// Topological sort nodes in the graph, return an empty array if a cycle exists.
List<Integer> itemOrder = topologicalSort(itemGraph, itemIndegree);
List<Integer> groupOrder = topologicalSort(groupGraph, groupIndegree);
if (itemOrder.isEmpty() || groupOrder.isEmpty()) {
return new int[0];
}
// Items are sorted regardless of groups, we need to differentiate them by the groups they belong to.
Map<Integer, List<Integer>> orderedGroups = new HashMap<>();
for (Integer item : itemOrder) {
orderedGroups.computeIfAbsent(group[item], k -> new ArrayList<>()).add(item);
}
// Concatenate sorted items in all sorted groups.
// [group 1, group 2, ... ] -> [(item 1, item 2, ...), (item 1, item 2, ...), ...]
List<Integer> answerList = new ArrayList<>();
for (int groupIndex : groupOrder) {
answerList.addAll(orderedGroups.getOrDefault(groupIndex, new ArrayList<>()));
}
return answerList.stream().mapToInt(Integer::intValue).toArray();
}
private List<Integer> topologicalSort(Map<Integer, List<Integer>> graph, int[] indegree) {
List<Integer> visited = new ArrayList<>();
Stack<Integer> stack = new Stack<>();
for (Integer key : graph.keySet()) {
if (indegree[key] == 0) {
stack.add(key);
}
}
while (!stack.isEmpty()) {
Integer curr = stack.pop();
visited.add(curr);
for (Integer prev : graph.get(curr)) {
indegree[prev]--;
if (indegree[prev] == 0) {
stack.add(prev);
}
}
}
return visited.size() == graph.size() ? visited : new ArrayList<>();
}
}
| sumeetskd/LeetCode-DailyChallenge | August/1203. Sort Items by Groups Respecting Dependencies |
1,013 | class divisibleBy5and18 {
public static void main(String[] args) {
public void divisibleBy5and18(double a)
{
if(a%5==0)
{
if(a%18==0)
{
System.out.print(a+" is divisible by 5 and 18.");
}
else
{
System.out.print(a+" is divisible by 5.");
}
}
else
{
if(a%18==0){
System.out.print(a+" is divisible by 18.");
}
else
{
System.out.print(a+" is neither divisible by 5 nor by 18.");
}
}
}
}
}
| AnjulGupta12/Basic_Of_Coding | 12.java |
1,015 | class Solution {
//follow-up with merge K sorted array
public void merge(int[] nums1, int m, int[] nums2, int n) {
//FBIP 2R
//using three pointers i, j, k to record current nums1 and nums2 and merged nums1 index
//cannot start from 0 cause that will override nums1 exsited value. START FROM BACK
int i = m - 1, j = n - 1, k = m + n - 1;
while (i >= 0 && j >= 0){
if (nums1[i] > nums2[j])
nums1[k--] = nums1[i--];
else nums1[k--] = nums2[j--];
}
//only check if nums2 still have unmerged value since nums1 value exsited in nums1 anyway
while (j >= 0)
nums1[k--] = nums2[j--];
}
}
//follow-up problem can be solved by divide and conquer method just like merge K sorted list | EdwardHXu/FBIP-LC | 88.java |
1,016 | /*
Copyright (c) 6/23/2014, Dylan Kobayashi
Version: 2/1/2018
Laboratory for Advanced Visualization and Applications, University of Hawaii at Manoa.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsEnvironment;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
//import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
//import java.awt.geom.Ellipse2D.Double;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
//import java.security.acl.LastOwnerException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.KeyStroke;
import javax.swing.event.MouseInputListener;
/**
* Interaction with the EZ class should be done through the public static methods. EZ extends a JPanel which are among
* the few things that can be put into the JApplet. They way they work and how to interact with them is significantly
* different from JFrames.
*
* The standard usage of EZ will involve EZ.initialize() to create a window. Then usage of the add methods to place
* elements on it. The EZ.refreshScreen() method must be called in order to update the visuals. The standard update rate
* is 60fps.
*
* Majority of the EZ methods will not work unless EZ has been initialized.
*
* @author Dylan Kobayashi
*
*/
@SuppressWarnings("serial")
public class EZ extends JPanel {
/** Used for external referencing. */
public static EZ app;
private static ArrayList<JFrame> openWindows = new ArrayList<>();
private static ArrayList<Boolean> openWindowsStatus = new ArrayList<>();
private static ArrayList<EZ> openWindowEz = new ArrayList<>();
/** Width. This needs to match the values given in the applet properties or there may be visual chopping. */
private static int WWIDTH;
/** Height. This needs to match the values given in the applet properties or there may be visual chopping. */
private static int WHEIGHT;
/** Background color. */
private static Color backgroundColor = Color.WHITE;
/** Time tracker for updates. */
private static long lastUpdate = System.currentTimeMillis();
/** Time tracker for updates. */
private static long timeDelta;
/** Used for tracking visual elements. */
protected ArrayList<EZElement> elements = new ArrayList<EZElement>();
/** Used for frame tracking. */
private static int currentFrameRate = 60;
private static long sleepTime = (long) (1000.0 / currentFrameRate); // default is 60fps.
private static boolean updateASAP = false;
/**Used for silent error tracking.*/
private static int errorCounter = 0;
private static String errorMsg = "";
/** Used for scale tracking on JDKv9. Some cases where starting scale is 2. */
private static volatile double startingPaintScaleX = 1;
private static volatile double startingPaintScaleY = 1;
/**
* This frustrating variable is necessary to get keyboard input detection working. Determined through trial and error.
* There doesn't seem to be any documentation why and really it could have been for any other button. Clarification:
* key binders are necessary if there are multiple JPanels or subcomponents. But even if there is only one, this does
* something that inits the listeners "correctly".
*/
private Action xPress = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
// System.out.print("VisualControl: the x button was pressed");
}
};
// **Used as a work around to the applet deadlock on init or start.*/
// private boolean runOnce = true;
/**
* Calling the constructor for the EZ class should never be done manually. You should be using EZ.initialize().
* Creates an instance of EZ and sets it as primary content pane and initiates values as necessary.
*
* @param w value in pixels of how large to make the width of the inner content area.
* @param h value in pixels of how large to make the height of the inner content area.
*/
public EZ(int w, int h) {
WWIDTH = w;
WHEIGHT = h;
this.setPreferredSize(new Dimension(WWIDTH, WHEIGHT));
app = this;
lastUpdate = System.currentTimeMillis();
// setup the input handlers.
EZInteraction ih = new EZInteraction();
this.addKeyListener(ih);
this.addMouseListener(ih);
this.addMouseMotionListener(ih);
// Note: difference between input handler and input/action map
// The below lines are used to "activate the input handler, and I have no clue how or why.
this.getInputMap().put(KeyStroke.getKeyStroke("pressed X"), "pressed");
this.getActionMap().put("pressed", xPress);
} // end constructor
/**
* Used to get the window width not including the frames.
*
* @return int value equal to the number of pixels between the frames horizontally.
*/
public static int getWindowWidth() {
return WWIDTH;
}
/**
* Used to get the window height not including the frames.
*
* @return int value equal to the number of pixels between the frames vertically.
*/
public static int getWindowHeight() {
return WHEIGHT;
}
/**
* Used to get the difference in time since the last refresh. Time is in milliseconds. 1 second == 1000 milliseconds.
* If you want to change the time between updates setFrameRate() may be what you are looking for.
*
* @return int value of the difference in time. Note: Standard system time counters are usually longs. However for
* ICS111 int is the most commonly used datatype of that family tree, and should be more than enough for delta time.
*/
public static int getDeltaTime() {
return (int) timeDelta;
}
/**
* This method is in charge of painting the screen. But do note that each of the individual elements are in charge of
* painting themselves. This method should not be called manually. Use EZ.refreshScreen() instead.
*/
@Override public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setColor(backgroundColor); // wash the background with specified bg color to prevent ghosting.
g2.fillRect(0, 0, WWIDTH + 100, WHEIGHT + 100);
// Track the scale the canvas originally starts at
startingPaintScaleX = g2.getTransform().getScaleX();
startingPaintScaleY = g2.getTransform().getScaleY();
for (int i = 0; i < elements.size(); i++) {
if(!elements.get(i).hasParent()){
elements.get(i).paint(g2);
}
}
} // end paint
/**
* Retrieves the canvas' starting x scale.
* @return double value of the starting x scale.
*/
public static double getStartingPaintScaleX() {
return startingPaintScaleX;
}
/**
* Retrieves the canvas' starting y scale.
* @return double value of the starting x scale.
*/
public static double getStartingPaintScaleY() {
return startingPaintScaleY;
}
/**
* This method will set the background color to the given color. Don't forget to import the Color when using this.
* While standard Colors like Color.WHITE or Color.BLUE are available, it is possible to specify an rgb value using:
* EZ.setBackgroundColor( new Color( r, g, b) ); where r,g,b are int values.
*
* @param c Color to use.
*/
public static void setBackgroundColor(Color c) {
backgroundColor = c;
}
/**
* Will pause the program for the specified amount of milliseconds.
* Mechanically this is just an encapsulated sleep.
*
* @param msToPauseFor how many milliseconds to pause for.
*/
public static void pause(long msToPauseFor) {
//The try/catch is strictly by requirement. Realistically no error should result from the sleep.
try { Thread.sleep(msToPauseFor); }
catch (InterruptedException e) {}
}
/**
* Used to repaint the application. Without this call, any changes made to the elements will not be visibly seen. This
* will also control the speed of the program updates. By default it is set to 60fps. This can be modified by using
* setFrameRate().
*/
public static void refreshScreen() {
timeDelta = System.currentTimeMillis() - lastUpdate;
lastUpdate = System.currentTimeMillis();
app.repaint();
if (!updateASAP) {
try {
if(timeDelta > sleepTime){
Thread.sleep(sleepTime * 2 - timeDelta);
}
else {
Thread.sleep(sleepTime);
}
}
catch (Exception e) {
errorCounter++;
errorMsg += "EZ.refreshScreen() error with sleep:" + e.getMessage() + "\n";
}
}
closeWindowWithIndex(-9999);
}// end refresh screen.
/**
*
*/
public static void refreshScreenOfAllActiveWindows(){
refreshScreen();
for(int i = 0; i < openWindows.size(); i++) {
if( openWindowsStatus.get(i) ) {
openWindowEz.get(i).repaint();
}
}
}
/**
* Sets the frame rate, which controls how fast the program will attempt to update itself. Note: it is very rarely
* possible to get an exact match of frames per second due to the time statements take to execute in addition to the
* fact that the division of time may not be equally distributed for that particular value of fps. Also possible to
* request a speed that cannot be done due to processing time of other components or hardware limitations. Will not
* change current fps if given value is 0 or less. A value of 1000 is the same as setting the program to update as
* quickly as possible, it doesn't guarantee that frame rate.
*
* @param fr an int value specifying the desired frames(updates) per second.
*/
public static void setFrameRate(int fr) {
if (fr > 0) {
sleepTime = (long) (1000.0 / fr);
currentFrameRate = fr;
}
}
/**
* Will return the current frame rate that EZ is updating at.
*
* @return int value of the current frame rate.
*/
public static int getCurrentFrameRate() {
return currentFrameRate;
}
/**
* Calling this method will tell EZ whether or not it should be updating As Soon As Possible(ASAP). Passing true will
* bypass the given frame rate values causing updates to occur ASAP. There will be no CPU rest, which for most
* programs is not necessary. Passing false will revert back to the last passed frame rate value. If none has been
* given, 60fps is the EZ default.
*
* @param b value true means update ASAP. false means use last specified frame rate.
*/
public static void setFrameRateASAP(boolean b) {
updateASAP = b;
}
/**
* Returns whether or not the program will update ASAP.
*
* @return true means it is. false means it is using the specified frame rate. 60fps is the default.
*/
public static boolean isFrameRateASAP() {
return updateASAP;
}
/**
* Adds an element for EZ to track. Generally you should not be using this. Use the more specific add methods instead.
*
* @param ve The element to add.
* @return true or false based on whether or not the element was successfully added.
*/
public static boolean addElement(EZElement ve) {
return EZ.app.elements.add(ve);
}
/**
* Adds an element for EZ to track at a specific draw layer. Lower numbers are on lower layers. Generally you should
* not be using this. Use the more specific add methods instead. The given layer must be valid and within the current
* range of layers.
*
* @param ve The element to add.
* @param index where the element should be placed.
* @return true or false based on whether or not the element was successfully added.
*/
public static boolean addElement(EZElement ve, int index) {
if (index < 0 || index > EZ.app.elements.size()) {
System.out.println("ERROR: attempting to add an element into an invalid index.");
return false;
}
EZ.app.elements.add(index, ve);
return true;
}
/**
* Adds a rectangle to the window. Returns the rectangle for later manipulation. If not immediately assigned to a
* variable, chances are you will have this element stuck on screen which cannot be removed. As result in most cases
* you will want to assign it to a variable.
*
* Color must be specified. Don't forget to import Color. The filled parameter will determine whether or not the
* element will be a solid of the given color. If it is not filled, the inner parts will be fully transparent.
*
* Example usage: EZRectangle r; r = EZ.addRectangle( 200, 200, 30, 10, Color.BLACK, true);
*
* @param x center.
* @param y center.
* @param w width.
* @param h height.
* @param c color.
* @param filled true will make the element a solid color. false will outline with the given color.
* @return the rectangle.
*/
public static EZRectangle addRectangle(int x, int y, int w, int h, Color c, boolean filled) {
EZRectangle vr = new EZRectangle(x, y, w, h, c, filled);
EZ.app.elements.add(vr);
refreshScreen();
return vr;
}
/**
* Adds a circle to the window. Returns the circle for later manipulation. If not immediately assigned to a variable,
* chances are you will have this element stuck on screen which cannot be removed. As result in most cases you will
* want to assign it to a variable.
*
* Color must be specified. Don't forget to import Color. The filled parameter will determine whether or not the
* element will be a solid of the given color. If it is not filled, the inner parts will be fully transparent.
*
* Example usage: EZCircle c; c = EZ.addCircle( 200, 200, 30, 10, Color.BLACK, true);
*
* @param x center.
* @param y center.
* @param w width.
* @param h height.
* @param c color.
* @param filled true will make the element a solid color. false will outline with the given color.
* @return the circle.
*/
public static EZCircle addCircle(int x, int y, int w, int h, Color c, boolean filled) {
EZCircle vc = new EZCircle(x, y, w, h, c, filled);
EZ.app.elements.add(vc);
refreshScreen();
return vc;
}
/**
* Adds text to the window. Returns the text for later manipulation. If not immediately assigned to a variable,
* chances are you will have this element stuck on screen which cannot be removed. As result in most cases you will
* want to assign it to a variable.
*
* It might not be easy to calculate left or right bound until after creation since the x,y values are where the
* text's center will be placed.
*
* Text cannot have their width and height manually set, that will depend on the content of the text. Using this
* addText() method will default the text size to 10px.
*
* Color must be specified. Don't forget to import Color.
*
* Example usage: EZText t; t = EZ.addText( 200, 200, "Hello World");
*
* @param x center.
* @param y center.
* @param msg that will be displayed.
* @return the text.
*/
public static EZText addText(int x, int y, String msg) {
return addText(x, y, msg, Color.BLACK, 10);
}
/**
* Adds text to the window. Returns the text for later manipulation. If not immediately assigned to a variable,
* chances are you will have this element stuck on screen which cannot be removed. As result in most cases you will
* want to assign it to a variable.
*
* It might not be easy to calculate left or right bound until after creation since the x,y values are where the
* text's center will be placed.
*
* Text cannot have their width and height manually set, that will depend on the content of the text. Using this
* addText() method will default the text size to 10px.
*
* Color must be specified. Don't forget to import Color.
*
* Example usage: EZText t; t = EZ.addText( 200, 200, "Hello World", Color.BLACK);
*
* @param x center.
* @param y center.
* @param msg that will be displayed.
* @param c color of the text
* @return the text.
*/
public static EZText addText(int x, int y, String msg, Color c) {
return addText(x, y, msg, c, 10);
}
/**
* Adds text to the window. Returns the text for later manipulation. If not immediately assigned to a variable,
* chances are you will have this element stuck on screen which cannot be removed. As result in most cases you will
* want to assign it to a variable.
*
* It might not be easy to calculate left or right bound until after creation since the x,y values are where the
* text's center will be placed.
*
* Text cannot have their width and height manually set, that will depend on the content of the text.
*
* Color must be specified. Don't forget to import Color.
*
* Example usage: EZText t; t = EZ.addText( 200, 200, "Hello World", Color.BLACK, 20);
*
* @param x center.
* @param y center.
* @param msg that will be displayed.
* @param c color of the text
* @param fs size of the font in pixels.
* @return the text.
*/
public static EZText addText(int x, int y, String msg, Color c, int fs) {
EZText vc = new EZText(x, y, msg, c, fs);
EZ.app.elements.add(vc);
refreshScreen();
return vc;
}
/**
* Adds text to the window. Returns the text for later manipulation. If not immediately assigned to a variable,
* chances are you will have this element stuck on screen which cannot be removed. As result in most cases you will
* want to assign it to a variable.
*
* It might not be easy to calculate left or right bound until after creation since the x,y values are where the
* text's center will be placed.
*
* Text cannot have their width and height manually set, that will depend on the content of the text.
*
* Color must be specified. Don't forget to import Color.
*
* Example usage: EZText t; t = EZ.addText("Arial", 200, 200, "Hello World", Color.BLACK, 20);
*
* @param fontName to display the msg in. Must be available to the system. A nonexistent font will output a console error, but will not halt the program.
* @param x center.
* @param y center.
* @param msg that will be displayed.
* @param c color of the text
* @param fs size of the font in pixels.
* @return the text.
*/
public static EZText addText(String fontName, int x, int y, String msg, Color c, int fs) {
EZText vc = new EZText(x, y, msg, c, fs);
vc.setFont(fontName);
EZ.app.elements.add(vc);
refreshScreen();
return vc;
}
/**
* Adds an image to the window. Returns the image for later manipulation. If not immediately assigned to a variable,
* chances are you will have this element stuck on screen which cannot be removed. As result in most cases you will
* want to assign it to a variable.
*
* The size(width and height) of the image will be based upon the original attributes of the image file.
*
* Example usage: EZImage i; i = EZ.addImage( "Smile.png", 200, 300);
*
* @param filename of image
* @param x center.
* @param y center.
* @return the image.
*/
public static EZImage addImage(String filename, int x, int y) {
EZImage vc = new EZImage(filename, x, y);
EZ.app.elements.add(vc);
refreshScreen();
return vc;
}
/**
* Adds a line to the window. Returns the line for later manipulation. If not immediately assigned to a variable,
* chances are you will have this element stuck on screen which cannot be removed. As result in most cases you will
* want to assign it to a variable.
*
* The line must be created with two points. A start and end point. The line itself will then be drawn to connect the
* two points. By default this method will make the line thickness 1px.
*
* Color must be specified. Don't forget to import Color.
*
* Example usage: EZLine l; l = EZ.addLine( 200, 300, 600, 100, Color.BLACK);
*
* @param x1 The x value of point 1.
* @param y1 The y value of point 1.
* @param x2 The x value of point 2.
* @param y2 The y value of point 2.
* @param c color to make the line.
* @return the line.
*/
public static EZLine addLine(int x1, int y1, int x2, int y2, Color c) {
return addLine(x1, y1, x2, y2, c, 1);
}
/**
* Adds a line to the window. Returns the line for later manipulation. If not immediately assigned to a variable,
* chances are you will have this element stuck on screen which cannot be removed. As result in most cases you will
* want to assign it to a variable.
*
* The line must be created with two points. A start and end point. The line itself will then be drawn to connect the
* two points. Thickness less than 1 will be automatically increased to 1.
*
* Color must be specified. Don't forget to import Color.
*
* Example usage: EZLine l; l = EZ.addLine( 200, 300, 600, 100, Color.BLACK);
*
* @param x1 The x value of point 1.
* @param y1 The y value of point 1.
* @param x2 The x value of point 2.
* @param y2 The y value of point 2.
* @param c Color to make the line.
* @param thickness to make the line.
* @return the line.
*/
public static EZLine addLine(int x1, int y1, int x2, int y2, Color c, int thickness) {
EZLine vl = new EZLine(x1, y1, x2, y2, c, thickness);
EZ.app.elements.add(vl);
refreshScreen();
return vl;
}
/**
* Adds a polygon to the window. Returns the polygon for later manipulation. If not immediately assigned to a
* variable, chances are you will have this element stuck on screen which cannot be removed. As result in most cases
* you will want to assign it to a variable.
*
* The polygon must be created with two arrays. One holding a list of x values while the other holds a list of y
* value. Each index of the arrays refer to a specific point. The order of points matter, as the polygon will be drawn
* starting from index 0 to the end of the array. The last point will be automatically connected to the first point.
*
* Color must be specified. Don't forget to import Color.
*
* Example usage: EZPolygon p; int[] xp, yp; xp = new int[3]; yp = new int[3]; xp[0] = 100; xp[1] = 150; xp[2] = 200;
* yp[0] = 100; yp[1] = 200; yp[2] = 100;
*
* p = EZ.addPolygon( xp, yp, Color.BLACK, true);
*
* @param xp int array containing the x values for the points.
* @param yp int array containing the y values for the points.
* @param c color.
* @param filled true will make the element a solid color. false will outline with the given color.
* @return the polygon.
*/
public static EZPolygon addPolygon(int[] xp, int[] yp, Color c, boolean filled) {
EZPolygon vp = new EZPolygon(xp, yp, c, filled);
EZ.app.elements.add(vp);
refreshScreen();
return vp;
}
public static EZPolygon addPolygon(Integer[] xp, Integer[] yp, Color c, Boolean filled) {
return addPolygon(convertToIntArray(xp), convertToIntArray(yp), c, filled);
}
private static int[] convertToIntArray(Integer[] array){
return java.util.Arrays.stream(array)
.mapToInt(Integer::intValue)
.toArray();
}
/**
* Adds a sound to the window. Returns the sound for later manipulation.
*
* You NEED to assign this to a variable otherwise you will not be able to play the sound.
*
* Currently the sound file must be in .wav format to work.
*
* Example usage: EZSound s; s = EZ.addSound("YouGotMail.wav");
*
* @param file name of the sound file including extension.
* @return the sound.
*/
public static EZSound addSound(String file) {
EZSound s = new EZSound(file);
return s;
}
/**
* Adds a group to the window. Will always start at coordinate 0,0.
*
* You NEED to assign this to a variable otherwise the group will not be accessible.
*
* A group by itself will not do anything. The usage is to add other elements to a group so they can maintain their
* relative positions and be manipulated as one element.
*
* Example usage: EZGroup g; g = EZ.addGroup();
*
* @return the group.
*/
public static EZGroup addGroup() {
EZGroup n = new EZGroup();
EZ.app.elements.add(n);
refreshScreen();
return n;
}
/** Clears out all visual elements that EZ is tracking. */
public static void removeAllEZElements() {
EZ.app.elements.clear();
}
/**
* Remove one visual element that EZ is tracking.
*
* @param ve the element to remove from EZ.
*/
public static void removeEZElement(EZElement ve) {
EZ.app.elements.remove(ve);
}
/**
* Returns the topmost element that contains the point. Will not return an element which is not visible. The topmost
* element is the one which has been drawn last making it visually appear on top others. Will not ever return an
* EZGroup, since technically the group itself is comprised of multiple elements. If you want the EZGroup which the
* given element is apart, crawl up the ancestry using getParent().
*
* Polymorphism knowledge may be needed to use this method.
*
* @param x coordinate of the point.
* @param y coordinate of the point.
* @return the top most EZElement that is not a group.
*/
public static EZElement getTopElementContainingPoint(int x, int y) {
ArrayList<EZElement> elems = getAllElementsContainingPoint(x, y);
if (elems.size() > 0) {
return elems.get(elems.size() - 1);
}
return null;
}
/**
* Collects and returns all elements containing the specified point. Will not return an element which is not visible.
* Will not return an EZGroup. See getTopElementContainingPoint() for explanation.
*
* Polymorphism knowledge may be needed to use this method.
*
* @param x coordinate of the point.
* @param y coordinate of the point.
* @return an array containing all EZElements.
*/
public static ArrayList<EZElement> getAllElementsContainingPoint(int x, int y) {
ArrayList<EZElement> containingElems = new ArrayList<EZElement>();
for (int i = 0; i < EZ.app.elements.size(); i++) {
if (EZ.app.elements.get(i) instanceof EZGroup) {
ArrayList<EZElement> allGroupChildren = new ArrayList<EZElement>();
recurseGroupAddingToArrayList((EZGroup) EZ.app.elements.get(i), allGroupChildren);
for (EZElement child : allGroupChildren) {
if (child.isShowing() && child.isPointInElement(x, y)) {
containingElems.add(child);
}
}
}
else if (EZ.app.elements.get(i).isShowing() && EZ.app.elements.get(i).isPointInElement(x, y)) {
containingElems.add(EZ.app.elements.get(i));
}
}
return containingElems;
} // end
/**
* Designed as a recursive method to collect all children and add them to the given arraylist. This will not add
* groups to the ArrayList, but instead will search those groups for elements adding those elements to the ArrayList.
*
* @param group from which to start the downward search
* @param elems the ArrayList to add all non-EZGroup children to.
*/
public static void recurseGroupAddingToArrayList(EZGroup group, ArrayList<EZElement> elems) {
ArrayList<EZElement> children = group.getChildren();
for (EZElement c : children) {
if (c instanceof EZGroup) {
recurseGroupAddingToArrayList((EZGroup) c, elems);
}
else {
elems.add(c);
}
}
}
/**
* Given an x and y coordinate, will check if that point is within the given element. This is done with respect to
* world space. If the element is not showing, will always return false.
*
* @param x coordinate of the point.
* @param y coordinate of the point.
* @param ve the element to check if the point is within.
* @return true if the point is within the element. Otherwise false. Always returns false if the element is not
* showing.
*/
public static boolean isElementAtPoint(int x, int y, EZElement ve) {
if (!ve.isShowing()) {
return false;
}
return ve.isPointInElement(x, y);
}
/**
* Will check if the given element is the top most element at the specified point. Top most is refers to the highest
* draw layer meaning nothing is visually in front of it. If it is not showing, will always return false. Will not
* work with EZGroup.
*
* @param x coordinate of the point.
* @param y coordinate of the point.
* @param ve element to check if the point is within.
* @return true if the element is the top point. Otherwise false. Always returns false if the element is not showing.
*/
public static boolean isTopElementAtPoint(int x, int y, EZElement ve) {
ArrayList<EZElement> elems = getAllElementsContainingPoint(x, y);
if (elems.size() > 0) {
return (elems.get(elems.size() - 1) == ve);
}
return false;
}
/**
* Will push the given element to the back of the drawing layer. If the Element is in a group, the element will be
* pushed to the back of that group's drawing layer.
*
* @param ve element to push back.
* @return false if the element doesn't exist. Otherwise true.
*/
public boolean pushToBack(EZElement ve) {
if (!elements.contains(ve) && !ve.hasParent()) {
System.out.println("ERROR: attempting to change layer of element not tracked by EZ or part of a group.");
return false;
}
if (ve.hasParent()) {
ve.getParent().getChildren().remove(ve); // only works because the getChildren returns an editable arraylist.
ve.getParent().getChildren().add(0, ve); // and will not influence either elements.
}
else {
elements.remove(ve);
elements.add(0, ve);
}
return true;
} // end visual push to back
/**
* Will push the given element back one drawing layer. If the element is in a group, the element will be pushed back
* once on that group's drawing layer.
*
* @param ve element to push back.
* @return false if the element doesn't exist. Otherwise true.
*/
public boolean pushBackOneLayer(EZElement ve) {
if (!elements.contains(ve) && !ve.hasParent()) {
System.out.println("ERROR: attempting to change layer of element not tracked by EZ or part of a group.");
return false;
}
if(ve.hasParent()){
int pos = ve.getParent().getChildren().indexOf(ve);
if (pos > 0) {
ve.getParent().getChildren().remove(ve);
ve.getParent().getChildren().add(pos - 1, ve);
} // only works because the getChildren returns an editable arraylist.
// and will not influence either elements.
}
else {
int pos = elements.indexOf(ve);
if (pos > 0) {
elements.remove(ve);
elements.add(pos - 1, ve);
}
}
return true;
} // end push back one layer
/**
* Will pull the given element to the front of the drawing layer. If the element is in a group, the element will be
* pulled to the front of that group's drawing layer.
*
* @param ve the element to pull.
* @return false if the element doesn't exist. Otherwise true.
*/
public boolean pullToFront(EZElement ve) {
if (!elements.contains(ve) && !ve.hasParent()) {
System.out.println("ERROR: attempting to change layer of element not tracked by EZ or part of a group.");
return false;
}
if(ve.hasParent()){
ve.getParent().getChildren().remove(ve); // only works because the getChildren returns an editable arraylist.
ve.getParent().getChildren().add(ve); // and will not influence either elements.
}
else {
elements.remove(ve);
elements.add(ve);
}
return true;
} // end visual pull to front
/**
* Will pull the given element to the front of the drawing layer. If the element is in a group, the element will be
* pulled forward once on that group's drawing layer.
*
* @param ve the element to pull.
* @return false if the element doesn't exist. Otherwise true.
*/
public boolean pullForwardOneLayer(EZElement ve) {
if (!elements.contains(ve) && !ve.hasParent() ) {
System.out.println("ERROR: attempting to change layer of element not tracked by EZ or part of a group.");
return false;
}
if(ve.hasParent()){
int pos = ve.getParent().getChildren().indexOf(ve);
if (pos < elements.size() - 1) {
elements.remove(ve);
elements.add(pos + 1, ve);
}// only works because the getChildren returns an editable arraylist.
// and will not influence either elements.
}
else {
int pos = elements.indexOf(ve);
if (pos < elements.size() - 1) {
elements.remove(ve);
elements.add(pos + 1, ve);
}
}
return true;
} // end pull forward one layer.
/**
* Will return the highest layer occupied by an element.
* @return highest layer occupied by an element.
*/
public int getHighestLayerOfAllElements() {
return elements.size() -1;
}
/**
* Will return the index of the given element. Lower numbers have least visibility.
* If the element is part of a group, then it will return the position in the group.
*
* @param ve the element to get the index of.
* @return index of the element. -1 if it is not a tracked object.
*/
public int getLayerPosition(EZElement ve) {
if (!elements.contains(ve) && !ve.hasParent() ) {
System.out.println("ERROR: element not being tracked by EZ and as result does not have layer.");
return -1;
}
if( ve.hasParent() ) {
return ve.getParent().getChildren().indexOf(ve);
}
else {
return elements.indexOf(ve);
}
} //end getLayerPosition
/**
* Sets the layer of the given element to the specified layer if possible.
* The layer must be zero or greater.
* If the provided layer higher than possible, it will just be set to highest layer.
* Moving from a low index to higher index will cause the element at destination to shift left.
* However, moving from a high index to lower index will cause the element at destination to shift right.
* Layer values that match the current, will not change anything.
*
* @param ve the element to change layer.
* @param layer index to move to.
*/
public void setLayerOfElement(EZElement ve, int layer) {
if (!elements.contains(ve) && !ve.hasParent() && layer < 0 ) {
System.out.println("ERROR: element not being tracked by EZ and as result does not have layer.");
return;
}
if ( ve.hasParent() && ve.getParent().getChildren().indexOf(ve) != layer) {
EZGroup p = ve.getParent();
p.getChildren().remove(ve);
if( layer <= p.getChildren().size() ) {
p.getChildren().add(layer, ve);
}
else {
p.getChildren().add(ve);
}
} //end if had parent.
else if ( elements.indexOf(ve) != layer ) {
elements.remove(ve);
if( layer <= elements.size() ) {
elements.add(layer, ve);
}
else {
elements.add(ve);
}
} //end else did not have parent.
} //end setLayerOfElement
/**
* Given two elements, will place the first below the second.
* This will most likely change the index of other elements.
* Will not work if they are not in the same container.
* @param moving object that will be extracted from container then placed below the second.
* @param above will not be extracted, but the first object will be placed below this one.
*/
public void setLayerBelow(EZElement moving, EZElement above) {
if( elements.contains(moving) && elements.contains(above) ) {
elements.remove(moving);
elements.add( elements.indexOf(above), moving );
}
else if ( moving.hasParent() && above.hasParent() && ( moving.getParent() == above.getParent() ) ) {
above.getParent().getChildren().remove(moving);
above.getParent().getChildren().add( above.getParent().getChildren().indexOf(above), moving);
}
else {
System.out.println("ERROR: element not being tracked by EZ and as result does not have layer.");
return;
}
} //setLayerBelow
/**
* Given two elements, will place the first above the second.
* This will most likely change the index of other elements.
* Will not work if they are not in the same container.
* @param moving object that will be extracted from container then placed above the second.
* @param below will not be extracted, but the first object will be placed above this one.
*/
public void setLayerAbove( EZElement moving, EZElement below ) {
if( elements.contains(moving) && elements.contains(below) ) {
elements.remove(moving);
elements.add( elements.indexOf(below) + 1, moving );
}
else if ( moving.hasParent() && below.hasParent() && ( moving.getParent() == below.getParent() ) ) {
below.getParent().getChildren().remove(moving);
below.getParent().getChildren().add( below.getParent().getChildren().indexOf(below) + 1, moving);
}
else {
System.out.println("ERROR: element not being tracked by EZ and as result does not have layer.");
return;
}
} //setLayerAbove
/**
* This will setup EZ for usage. Without calling this method first, none of the other EZ methods will work correctly.
* Parameters will be used to determine width and height of window. Do not call this method more than once in a
* program run.
*
* @param width for the content area of the window.
* @param height for the content area of the window.
*/
public static int initialize(int width, int height) {
// First time
String osName = System.getProperty("os.name").toLowerCase();
if(osName.indexOf("mac") >= 0){
try {
Runtime.getRuntime().exec("defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false");
} catch (IOException e) {
System.out.println("Unable to perform Mac keyboard change");
}
}
String windowName = "ICS111";
JFrame frame = new JFrame(windowName);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create and set up the content pane.
EZ newContentPane = new EZ(width, height);
newContentPane.setOpaque(true); // content panes must be opaque
frame.setContentPane(newContentPane);
// Size the frame according to largest element, then display the window.
frame.setResizable(false);
frame.pack();
frame.setVisible(true);
timeDelta = 0;
lastUpdate = System.currentTimeMillis();
//account for number of windows
openWindows.add(frame);
openWindowsStatus.add(true);
openWindowEz.add(newContentPane);
int wIndex = openWindows.size() - 1;
openWindows.get( wIndex ).setTitle("ICS 111 - Window index:" + wIndex);
return wIndex;
}
/**
* This will setup EZ for usage. Without calling this method first, none of the other EZ methods will work correctly.
* Window will default to use the full dimensions of the screen. Do not call this method more than once in a program
* run.
*/
public static int initialize() {
return initialize((int) Toolkit.getDefaultToolkit().getScreenSize().getWidth(), (int) Toolkit.getDefaultToolkit()
.getScreenSize().getHeight());
}
/**
*
*/
public static void setCurrentWindow(int windowIndex) {
if( windowIndex > -1 && windowIndex < openWindows.size() && openWindowsStatus.get(windowIndex) ) {
app = openWindowEz.get(windowIndex);
}
}
/**
* Will close the specified window. Numbers may change when windows close. This will depend on their order of creation.
*/
public static void closeWindowWithIndex(int windowIndex) {
if ( (windowIndex >= 0) && (windowIndex < openWindows.size()) && openWindowsStatus.get(windowIndex) ) {
//get the window to close, remove from open windows, then dispose of it
//JFrame windowToClose = openWindows.get(windowIndex);
//openWindows.remove(windowToClose);
//windowToClose.dispose();
openWindows.get(windowIndex).dispose();
openWindowsStatus.set(windowIndex, false);
}
else if( windowIndex != -9999) {
System.out.println("Invalid window index given:" + windowIndex + ". Not closing a window.");
}
// //window checks: close if no windows. 1 window gets the close app on close. Renumber windows.
// if(openWindows.size() == 0) { System.exit(0); System.out.println("Closing program, no open windows."); }
// else if(openWindows.size() == 1) { openWindows.get(0).setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
// else {
// for(int i = 0; i < openWindows.size(); i++) {
// openWindows.get(i).setTitle("ICS 111 - Window index:" + i);
// openWindows.get(i).setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
// }
// }
} //end closeWindowWithoutClosingApplication
/**
* Will return the number of open windows.
*/
public static int getNumberOfOpenWindows() {
int count = 0;
for(int i = 0; i < openWindows.size(); i++) {
if(openWindowsStatus.get(i)) { count++; }
}
return count;
}
public static void trackedErrorPrint() {
System.out.println("Errors tracked:" + EZ.errorCounter);
System.out.println("====\nErrors\n====\n:" + EZ.errorMsg + "\n====\nEnd\n====\n");
}
} // end visual control class
/**
* The EZElement is the parent class of each of the types of elements that can be added to the window. Contains a set of
* methods that are standard for all inheriting classes. Some methods do not have the same functionality. For example,
* while the EZImage class does have getColor() and setColor() methods, they do not have any practical usage for the
* EZImage class.
*
* @author Dylan Kobayashi
*/
abstract class EZElement {
protected boolean isShowing = true;
/**
* The paint method controls how the element draws itself on the screen. You should not be calling this method, it
* will be handled by EZ.refreshScreen().
*
* @param g2 is the graphics reference to draw to the screen.
*/
public abstract void paint(Graphics2D g2);
/**
* Returns the height of this element with respect to local space.
*
* @return height in pixels.
*/
public abstract int getHeight();
/**
* Returns the width of this element with respect to local space.
*
* @return width in pixels.
*/
public abstract int getWidth();
/**
* Returns the x center of this element with respect to local space.
*
* @return x coordinate.
*/
public abstract int getXCenter();
/**
* Returns the y center of this element with respect to local space.
*
* @return y coordinate.
*/
public abstract int getYCenter();
/**
* Will return this element's x coordinate with respect to world space(After all transformations have been applied).
*
* @return x coordinate on the world space.
*/
public int getWorldXCenter() {
return (int) (this.getBounds().getBounds().getCenterX());
}
/**
* Will return this element's y coordinate with respect to world space(After all transformations have been applied).
*
* @return y coordinate on the world space.
*/
public int getWorldYCenter() {
return (int) (this.getBounds().getBounds().getCenterY());
}
/**
* Returns the width of the object with respect to the world. This can differ from getWidth() if scale has been
* applied and if any groups this element resides in has been affected by scale.
*
* @return width in pixels with respect to world space.
* */
public int getWorldWidth() {
double tscale = this.scaleWith1AsOriginal;
EZElement temp = this;
while (this.hasParent()) {
temp = this.getParent();
tscale *= temp.getScale();
}
return (int) (tscale * this.getWidth());
} // end get world width
/**
* Returns the height of the object with respect to the world. This can differ from getHeight() if scale has been
* applied and if any groups this element resides in has been affected by scale.
*
* @return height in pixels with respect to world space.
* */
public int getWorldHeight() {
double tscale = this.scaleWith1AsOriginal;
EZElement temp = this;
while (this.hasParent()) {
temp = this.getParent();
tscale *= temp.getScale();
}
return (int) (tscale * this.getHeight());
} // end get world height
/**
* Sets the color of this element.
*
* @param c color to set this element to.
*/
public abstract void setColor(Color c);
/**
* Returns the color of this element.
*
* @return color of this element.
*/
public abstract Color getColor();
/**
* Will return whether or not this element is set to be filled.
*
* @return true if it is. false if it isn't.
*/
public abstract boolean isFilled();
/**
* Will set the filled status of this element.
*
* @param f fill status that will be set.
*/
public abstract void setFilled(boolean f);
/**
* Sets the center of the element to given x and y coordinate. Only affects local coordinate location.
*
* @param x center coordinate this element will be set to.
* @param y center coordinate this element will be set to.
*/
public abstract void translateTo(double x, double y);
/**
* Moves the center of the element by given x and y coordinate. Only affects local coordinate location.
*
* @param x amount this element's center will be shifted by.
* @param y amount this element's center will be shifted by.
*/
public abstract void translateBy(double x, double y);
/**
* Will move the element forward by the given distance. Forward is determined by the current rotation of the object.
* For example:<br>
* a rotation of 0 means forward is to the right side of the screen.<br>
* a rotation of 90 means forward is to the bottom of the screen.<br>
* a rotation of -90 means forward is to the top of the screen.<br>
*
* @param distance to shift the element forward by.
*/
public void moveForward(double distance) {
double dx = Math.cos(Math.toRadians(this.getRotation())) * distance;
double dy = Math.sin(Math.toRadians(this.getRotation())) * distance;
this.translateBy(dx, dy);
}
/*
* Will move with respect to the rotation and scale. Only affects local coordinate location. Commented out for now.
* final public void translate(int x, int y) { AffineTransform at = EZElement.transformHelper(this); at.translate(x,
* y); Point atCenter = new Point(0,0); at.transform(atCenter, atCenter); this.moveTo(atCenter.x, atCenter.y); } //end
* translate
*/
/**
* This will ensure the element is painted. If the object is already showing, this has no effect. By default objects
* are showing.
*/
public abstract void show(); // while the effect is simple some elements need this filled out differently.
/**
* This will prevent the element from being painted. An additional effect is that the isPointInElement() will return
* false if the element is hidden. If the object is already hidden, this has no effect.
*/
public abstract void hide(); // the intention is to ensure additions take this into account.
/**
* Returns whether or not the element is being painted.
* This has nothing to do with whether or not the object is on screen.
*
* @return true if this object is being painted. false if not.
* */
public boolean isShowing() {
return isShowing;
}
/**
* Will push the given element to the back of the drawing layer. If the Element is in a group, the element will be
* pushed to the back of that group's drawing layer.
*
*/
public void pushToBack() {
EZ.app.pushToBack(this);
} // end push to back
/**
* Will push the given element to the back one drawing layer. If the Element is in a group, the element will be
* pushed back once on that group's drawing layer.
*/
public void pushBackOneLayer() {
EZ.app.pushBackOneLayer(this);
} // end push back one
/**
* Will pull the given element to the front of the drawing layer. If the Element is in a group, the element will be
* pulled to the front of that group's drawing layer.
*/
public void pullToFront() {
EZ.app.pullToFront(this);
} // end pull to front
/**
* Will pull the given element forward once on the drawing layer. If the Element is in a group, the element will be
* pulled forward once on that group's drawing layer.
*/
public void pullForwardOneLayer() {
EZ.app.pullForwardOneLayer(this);
} // end pull forward one
/** Returns the current draw layer this object is one.
* Lower index will be visibly covered by higher index.
* @return layer index.
*/
public int getLayer() {
return EZ.app.getLayerPosition(this);
}
/**
* Sets the draw layer of this. No change if the specified layer matches the current.
* If moving to a higher index, the elements above will shift lower.
* If moving to a lower index, the elements will shift higher.
*
* @param layer to move to.
*/
public void setLayer(int layer) {
EZ.app.setLayerOfElement(this, layer);
}
/**
* Move this element below the specified element in the draw layer.
* The placement is done by extraction and insert.
* Will not work if they do not share the same container.
*
* @param reference element to place this below.
*/
public void placeBelow(EZElement reference) {
EZ.app.setLayerBelow(this, reference);
}
/**
* Move this element above the specified element in the draw layer.
* The placement is done by extraction and insert.
* Will not work if they do not share the same container.
*
* @param reference element to place above.
*/
public void placeAbove(EZElement reference) {
EZ.app.setLayerAbove(this, reference);
}
/**
* Given a string figures out how long a string is.
*
* @param s the string to calculate the width of.
* @return int width in pixels.
*/
protected static int getWidthOf(String s) {
return EZ.app.getFontMetrics(EZ.app.getFont()).stringWidth(s);
}
/**
* Used to calculated height of a given string.
*
* @param s string to calculate height of.
* @return int height in pixels.
*/
protected static int getHeightOf(String s) {
return EZ.app.getFontMetrics(EZ.app.getFont()).getHeight();
}
protected double rotationInDegrees = 0.0;
protected double scaleWith1AsOriginal = 1.0;
/**
* Calling this will reset rotation and scale back to normal values, 0 and 1.0 respectively and
* local coordinates will be set to 0,0.
* */
public abstract void identity();
/**
* This will rotate the image by specified degrees. Additive, doesn't override previous degree value. Positive
* rotation is clockwise. Negative is counter clockwise. Values of 360 and beyond are as though it were degree % 360.
*
* @param degrees to rotate. Positive is clockwise. Negative is counter clockwise.
*/
public void rotateBy(double degrees) {
rotationInDegrees += degrees;
}
/**
* This will rotate the image to specified degree. Overrides previous degree value. Positive rotation is clockwise.
* Negative is counter clockwise. Values of 360 and beyond are as though it were degree % 360.
*
* @param degrees to rotate. Positive is clockwise. Negative is counter clockwise.
* */
public void rotateTo(double degrees) {
rotationInDegrees = degrees;
}
/**
* Will adjust the rotation of the element by turning to the left(counter clockwise) by the specified degrees. Note: if given a negative,
* will have the opposite effect, will turn right(clockwise) instead.
* @param degrees to rotate. Positive is left. Negative is right.
*/
public void turnLeft(double degrees) {
rotationInDegrees -= degrees;
}
/**
* Will adjust the rotation of the element by turning to the right(clockwise) by the specified degrees. Note: if given a negative,
* will have the opposite effect, will turn left(counter clockwise) instead.
* @param degrees to rotate. Positive is right. Negative is left.
*/
public void turnRight(double degrees) {
rotationInDegrees += degrees;
}
/**
* This will return the current rotation in degrees, a double value.
* @return the rotation in degrees.
* */
public double getRotation() {
return rotationInDegrees;
}
/**
* Will scale by given value. Multiplicative over the current scale value. For example, if getScale() returns 2.0 and
* then scale(3.0) the resulting scale value is 2.0 * 3.0 = 6.0.
* @param s how much to scale the element by.
* */
public void scaleBy(double s) {
scaleWith1AsOriginal *= s;
}
/**
* Will set the scale to given value. This will replace previous scale value. For example, if getScale() returns 2.0
* and then scaleTo(3.0) the resulting scale value is 3.0.
* @param s value to set the scale at.
* */
public void scaleTo(double s) {
scaleWith1AsOriginal = s;
}
/**
* Returns the current scaling value. 1.0 means original scale value.
* @return the current scale value.
* */
public double getScale() {
return scaleWith1AsOriginal;
}
/** Used to store the parent of a Node. */
private EZGroup parent = null;
/**
* Will set the parent to the given group ONLY if it doesn't already have a parent.
* Generally you should not use this, it will be handled automatically by EZGroup.
*
* @param g group to set the parent as.
* @return true if successful. Otherwise false.
* */
public boolean setParent(EZGroup g) {
if (parent == null) {
parent = g;
return true;
}
return false;
}
/**
* Will remove the group parent from this element only if it already has one.
* Generally you should not use this, it will be handled automatically by EZGroup.
*
* @return true if successful removal. Otherwise false.
*/
public boolean removeParent() {
if (parent == null) {
return false;
}
parent = null;
return true;
}
/**
* If this element has a parent returns true, otherwise false.
* @return true if has a parent. Otherwise false.
*/
public boolean hasParent() {
if (parent == null) {
return false;
}
return true;
}
/**
* Will return the group which this element is located within.
*
* @return EZGroup that this is part of.
*/
public EZGroup getParent() {
return parent;
}
/**
* This will return a Shape of the bounds of this element with respect to the world space.
* This is not a bounding box. This is the shape itself after transformations have been applied.
*
* @return Shape instance of the bounds for this Element.
*/
public abstract Shape getBounds();
/**
* This method will return a Shape which holds the bounds of the given shape that has all of the transformations of
* the given EZElement applied to it. The transformations will take into account each of the groups that the given
* EZElement is a part of. In brief, returns the bounds of the shape with respect to the world space.
*
* @param os original shape before transformations.
* @param oe EZElement which to pull transformations from to calculate bounds.
* @return Shape which holds the final bounds with respect to world space.
*/
public static Shape boundHelper(Shape os, EZElement oe) {
Shape bs = os;
bs = transformHelper(oe).createTransformedShape(bs);
return bs;
} // end boundHelper
/**
* Returns the transform before being applied to the shape. The transform is affected by all groups this element is
* contained in.
*
* @param oe The EZElement which to get the affine transform of.
* @return the final AffineTransform that will be applied to the shape.
*/
public static AffineTransform transformHelper(EZElement oe) {
return transformHelper(oe, false);
}
/**
* Returns the transform before being applied to the shape. The transform is affected by all groups this element is
* contained in.
*
* @param oe The EZElement which to get the affine transform of.
* @param scaleAdjust Whether or not original scale adjustment should be taken into account.
* @return the final AffineTransform that will be applied to the shape.
*/
public static AffineTransform transformHelper(EZElement oe, boolean scaleAdjust) {
AffineTransform af = new AffineTransform();
ArrayList<EZElement> ancestors = new ArrayList<EZElement>();
EZElement temp;
temp = oe;
while (temp.hasParent()) {
ancestors.add(temp.getParent());
temp = temp.getParent();
}
for (int i = ancestors.size() - 1; i >= 0; i--) {
temp = ancestors.get(i);
af.translate(temp.getXCenter(), temp.getYCenter());
af.scale(temp.getScale(), temp.getScale());
af.rotate(Math.toRadians(temp.getRotation()));
}
/* Original code
// af.translate(oe.getXCenter(), oe.getYCenter());
// af.scale(oe.getScale(), oe.getScale());
*/
// As of version 9, the canvas has a starting scale of 2.0 which messes with transform calculations
if (scaleAdjust) {
af.translate(oe.getXCenter() * EZ.getStartingPaintScaleX(), oe.getYCenter() * EZ.getStartingPaintScaleX());
} else {
af.translate(oe.getXCenter(), oe.getYCenter());
}
if (scaleAdjust) {
af.scale(oe.getScale() * EZ.getStartingPaintScaleX(), oe.getScale() * EZ.getStartingPaintScaleX());
} else {
af.scale(oe.getScale(), oe.getScale());
}
af.rotate(Math.toRadians(oe.getRotation()));
return af;
} // end boundHelper
/**
* Checks if the given x,y coordinates(point) are within the shape of this element.
* The check is made with respect to world space.
*
* @param x coordinate of the point to check.
* @param y coordinate of the point to check.
* @return true if the specified point is within this element. Otherwise returns false.
*/
public boolean isPointInElement(int x, int y) {
return this.getBounds().contains(x, y);
} // end is point in element.
} // end visual element class
/**
* The EZCircle is used to create an Ellipse type of shape. A perfect circle isn't required and is
* calculated based upon given width and height. When creating a circle, the given center coordinate, width and height
* will specify a bounding box for the cirlce. From there, the circle drawn will attempt to make the most usage of the
* given bounding box ensuring that should a line be placed along the vertical or horizontal axis the opposite sides
* will be symmetrical.
*
* @author Dylan Kobayashi
*
*/
class EZCircle extends EZElement {
/** Used for circle drawing, sizing and positioning. */
protected Ellipse2D.Double circle;
protected Ellipse2D.Double tempCircle;
protected Shape transformCircle;
/** Determines whether or not shape will be a solid color. */
protected Boolean filled = false;
/** Color of shape outline/fill. */
protected Color color;
/** Variables used for the center tracking to allow decimal translations. */
private double xcd, ycd;
/**
* Creates a circle with the given specifications.
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addCircle() method which will perform additional background actions to get the circle to display
* on the window properly.
*
* @param x center coordinate.
* @param y center coordinate.
* @param width of the circle.
* @param height of the circle.
* @param color to use when drawing.
* @param filled status of whether the drawn circle should be a solid of the given color.
*/
public EZCircle(int x, int y, int width, int height, Color color, boolean filled) {
circle = new Ellipse2D.Double(x - width / 2, y - height / 2, width, height);
// transformCircle = new Ellipse2D.Double(-width/2,-height/2,width,height);
this.color = color;
this.filled = filled;
xcd = x;
ycd = y;
} // end constructor
@Override public void paint(Graphics2D g2) {
if (this.isShowing) {
g2.setColor(color);
if (filled) {
g2.fill(this.getBounds());
}
else {
g2.draw(this.getBounds());
}
/*
* Commented out, unsure which is faster, affine transforms or moving of the g2 plane. g2.setColor(Color.RED);
* tempCircle = (Ellipse2D.Double) circle.clone(); tempCircle.width = (int) (tempCircle.width *
* scaleWith1AsOriginal); tempCircle.height = (int) (tempCircle.height * scaleWith1AsOriginal); tempCircle.x =
* -(tempCircle.width/2); tempCircle.y = -(tempCircle.height/2); transformCircle =
* AffineTransform.getRotateInstance(Math.toRadians(rotationInDegrees)).createTransformedShape(tempCircle);
* transformCircle = AffineTransform.getTranslateInstance(circle.x + circle.width/2, circle.y +
* circle.height/2).createTransformedShape(transformCircle); g2.draw(transformCircle); //
*/
} // end if visible
}// end paint
@Override public void show() {
isShowing = true;
}
@Override public void hide() {
isShowing = false;
}
@Override public int getXCenter() {
return (int) (circle.x + circle.width / 2);
}
/**
* This will set the x center coordinate of the circle to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param x coordinate the center will be set to.
*/
private void setXCenter(double x) {
xcd = x;
circle.x = (int) xcd - circle.width / 2;
}
@Override public int getYCenter() {
return (int) (circle.y + circle.height / 2);
}
/**
* This will set the y center coordinate of the circle to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param y coordinate the center will be set to.
*/
private void setYCenter(double y) {
ycd = y;
circle.y = (int) y - circle.height / 2;
}
@Override public void identity() {
setXCenter(0);
setYCenter(0);
rotationInDegrees = 0;
scaleWith1AsOriginal = 1.0;
}
@Override public void translateTo(double x, double y) {
xcd = x;
ycd = y;
circle.x = (int) x - circle.width / 2;
circle.y = (int) y - circle.height / 2;
}
@Override public void translateBy(double x, double y) {
xcd += x;
ycd += y;
circle.x = (int) xcd - circle.width / 2;
circle.y = (int) ycd - circle.height / 2;
}
@Override public int getHeight() {
return (int) circle.height;
}
/**
* The circle can have its height changed. Does not affect width.
* When applied, the center coordinate will not be affected.
*
* @param h new height for the circle.
*/
public void setHeight(int h) {
circle.y = (circle.y + circle.height / 2) - h / 2;
circle.height = h;
}
@Override public int getWidth() {
return (int) circle.width;
}
/**
* The circle can have its width changed. Does not affect height.
* When applied, the center coordinate will not be affected.
*
* @param w new width for the circle.
*/
public void setWidth(int w) {
circle.x = circle.x + circle.width / 2 - w / 2;
circle.width = w;
}
@Override public Color getColor() {
return color;
}
@Override public void setColor(Color c) {
this.color = c;
}
@Override public boolean isFilled() {
return filled;
}
@Override public void setFilled(boolean f) {
filled = f;
}
@Override public Shape getBounds() {
return EZElement.boundHelper(new Ellipse2D.Double(-circle.width / 2, -circle.height / 2, circle.width,
circle.height), this);
} // end get bounds
} // end visual circle class
/**
* The EZRectangle is used to create an rectangle calculated off center coordinates, width, and height.
*
* @author Dylan Kobayashi
*
*/
class EZRectangle extends EZElement {
/** Used for the dimensions of drawing. */
protected Rectangle rect;
protected Rectangle temprect;
protected Shape transformRect;
/** Determines whether or not shape will be a solid color. */
protected Boolean filled = false;
/** Color of shape outline/fill. */
protected Color color;
/** Used for tracking center with decimals. */
private double xcd, ycd;
/**
* Creates a rectangle with the given specifications.
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addRectangle() method which will perform additional background actions to get the rectangle to display
* on the window properly.
*
* @param x center coordinate.
* @param y center coordinate.
* @param width of the rectangle.
* @param height of the rectangle.
* @param color to use when drawing.
* @param filled status of whether the drawn rectangle should be a solid of the given color.
*/
public EZRectangle(int x, int y, int width, int height, Color color, boolean filled) {
rect = new Rectangle(x - width / 2, y - height / 2, width, height);
this.color = color;
this.filled = filled;
xcd = x;
ycd = y;
} // end constructor
@Override public void paint(Graphics2D g2) {
if (this.isShowing) {
g2.setColor(color);
if (filled) {
g2.fill(this.getBounds());
}
else {
g2.draw(this.getBounds());
}
}// end if visible
}// end paint
@Override public void show() {
isShowing = true;
}
@Override public void hide() {
isShowing = false;
}
@Override public int getXCenter() {
return rect.x + rect.width / 2;
}
/**
* This will set the x center coordinate of the rectangle to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param x coordinate the center will be set to.
*/
private void setXCenter(double x) {
xcd = x;
rect.x = (int) x - rect.width / 2;
}
@Override public int getYCenter() {
return rect.y + rect.height / 2;
}
/**
* This will set the y center coordinate of the rectangle to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param y coordinate the center will be set to.
*/
private void setYCenter(double y) {
ycd = y;
rect.y = (int) y - rect.height / 2;
}
@Override public void translateTo(double x, double y) {
xcd = x;
ycd = y;
rect.x = (int) x - rect.width / 2;
rect.y = (int) y - rect.height / 2;
}
@Override public void translateBy(double x, double y) {
xcd += x;
ycd += y;
rect.x = (int) xcd - rect.width / 2;
rect.y = (int) ycd - rect.height / 2;
}
@Override public void identity() {
setXCenter(0);
setYCenter(0);
rotationInDegrees = 0;
scaleWith1AsOriginal = 1.0;
}
@Override public int getHeight() {
return rect.height;
}
/**
* The rectangle can have its height changed. Does not affect width.
* When applied, the center coordinate will not be affected.
*
* @param h new height for the rectangle.
*/
public void setHeight(int h) {
rect.y = rect.y + rect.height / 2 - h / 2;
rect.height = h;
}
@Override public int getWidth() {
return rect.width;
}
/**
* The rectangle can have its width changed. Does not affect height.
* When applied, the center coordinate will not be affected.
*
* @param w new width for the rectangle.
*/
public void setWidth(int w) {
rect.x = rect.x + rect.width / 2 - w / 2;
rect.width = w;
}
@Override public Color getColor() {
return color;
}
@Override public void setColor(Color c) {
this.color = c;
}
@Override public boolean isFilled() {
return filled;
}
@Override public void setFilled(boolean f) {
filled = f;
}
@Override public Shape getBounds() {
return EZElement.boundHelper(new Rectangle(-rect.width / 2, -rect.height / 2, rect.width, rect.height), this);
}
} // end class rectangle
/**
* Used to "paint" text on the screen.
* The following should be taken into consideration when using EZText:<br>
* -to change the displayed text use setMsg().<br>
* -width and height cannot be directly set, it is a derivative of the message and text size.<br>
* -center coordinates will not be influenced when the message is changed.<br>
* -in order for left alignment to be applied to a text, you must calculate the offset after changing the message.
* -text is always "filled", using the setFilled() method will not do anything.<br>
* -text cannot be locally scaled. Use setFontSize() instead. However, text will be affected by group scales.<br>
*
* @author Dylan Kobayashi
*/
class EZText extends EZElement {
/** What will be displayed. */
protected String msg;
/** Color of text. */
protected Color color;
/** Used to specify x center. */
protected double xCenter;
/** Used to specify y center. */
protected double yCenter;
protected int fontSize = 20;
/**
* Creates text with the given specifications.
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addText() method which will perform additional background actions to get the text to display
* on the window properly.
*
* @param x center coordinate for the text.
* @param y center coordinate for the text.
* @param msg to display.
* @param color of the text.
* @param fSize pixel size that the text will be drawn at.
*/
public EZText(int x, int y, String msg, Color color, int fSize) {
this.setXCenter(x);
this.setYCenter(y);
this.msg = msg;
this.color = color;
this.fontSize = fSize;
this.fontName = EZ.app.getFont().getName();
this.dFont = EZ.app.getFont();
} // end constructor
@Override public void paint(Graphics2D g2) {
if (this.isShowing) {
//g2.setFont(new Font(fontName, Font.PLAIN, fontSize));
g2.setFont( dFont.deriveFont( (float) fontSize) );
g2.setColor(color);
// only print if the message has visible characters.
if (msg.trim().length() > 0) {
AffineTransform tmp = g2.getTransform();
g2.setTransform(EZElement.transformHelper(this, true));
g2.drawString(msg, -getWidth() / 2, getHeight() / 3);
g2.setTransform(tmp);
}
}
}// end paint
@Override public void show() {
isShowing = true;
}
@Override public void hide() {
isShowing = false;
}
/**
* This will return what text is currently being displayed
* @return String containing the text currently being displayed.
*/
public String getMsg() {
return msg;
}
/**
* Will set the displayed text to the given parameter.
* This will not render escape character. For example \n does not result in a new line.
* If you want a new line, you need to create another EZText.
* @param m String containing text to display.
*/
public void setMsg(String m) {
this.msg = m;
}
@Override public int getXCenter() {
return (int) xCenter;
}
/**
* This will set the x center coordinate of the text to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param x coordinate the center will be set to.
*/
private void setXCenter(double x) {
this.xCenter = x;
}
@Override public int getYCenter() {
return (int) yCenter;
}
/**
* This will set the y center coordinate of the text to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param y coordinate the center will be set to.
*/
private void setYCenter(double y) {
this.yCenter = y;
}
@Override public void translateTo(double x, double y) {
this.xCenter = x;
this.yCenter = y;
}
@Override public void translateBy(double x, double y) {
this.xCenter += x;
this.yCenter += y;
}
@Override public int getHeight() {
//EZ.app.setFont(new Font(fontName, Font.PLAIN, fontSize));
EZ.app.setFont( dFont.deriveFont( (float) fontSize) );
return EZElement.getHeightOf(msg);
}
@Override public int getWidth() {
//EZ.app.setFont(new Font(fontName, Font.PLAIN, fontSize));
EZ.app.setFont( dFont.deriveFont( (float) fontSize) );
return EZElement.getWidthOf(msg);
}
@Override public Color getColor() {
return color;
}
@Override public void setColor(Color c) {
this.color = c;
}
/**
* Text is always "filled" as result this will always return true.
* @return always returns true.*/
@Override public boolean isFilled() {
return true;
}
/**
* Text cannot be set to unfilled. This method will not do anything.
* @param f value will be discarded.
* */
@Override public void setFilled(boolean f) { }
@Override public Shape getBounds() {
return EZElement.boundHelper(
new Rectangle(-this.getWidth() / 2, -this.getHeight() / 2, this.getWidth(), this.getHeight()), this);
}
@Override public void identity() {
this.xCenter = 0;
this.yCenter = 0;
this.scaleWith1AsOriginal = 1.0;
this.rotationInDegrees = 0;
}
/**
* Text cannot be scaled. Use setFontSize() instead.
* @param s will be discarded.
* */
@Override public void scaleBy(double s) { }
/**
* Text cannot be scalled. Use setFontSize() instead.
* @param s will be discarded.
* */
@Override public void scaleTo(double s) { }
/**
* Changes the size of the font.
* @param f size in pixels.
* */
public void setFontSize(int f) {
this.fontSize = f;
}
/**
* Returns the size of the font.
* @return size in pixels.*/
public int getFontSize() {
return this.fontSize;
}
/**Stores the name of the font used.*/
private String fontName;
/**Contains the Font object used for display.*/
private Font dFont;
/**Holds the loaded fonts from files.*/
private static ArrayList<Font> loadedFonts = new ArrayList<Font>();
/**Holds the loaded file names.*/
private static ArrayList<String> loadedFiles = new ArrayList<String>();
/**The font item itself which should be displayed.*/
/**
* Will print all available fonts to console.
* Usage would be done before the program is complete so the use can verify available fonts and choose from among them.
*/
public static void printAvailableFontsToConsole() {
String[] names = getAllFontNames();
for(String s : names){
System.out.println(s);
}
}
/**
* Will return a String array containing all names of fonts available for usage specific to this machine.
* While specific to this machine, unless you have tampered with java settings, the font set should the same
* for other machines.
* @return String[] containing names of available fonts.
*/
public static String[] getAllFontNames() {
return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
}
/**
* Will attempt to set the font to the specified parameter. If the font is not available on the machine, an error
* will be output to the console, but the program will not halt.
*
* @param name of the font to use.
*/
public void setFont(String name) {
if(name.contains(".ttf") || name.contains(".TTF")){
if( !checkIfAlreadyLoaded(name) ) {
tryLoadFontFromFile(name);
}
}
else {
String[] allNames = getAllFontNames();
boolean match = false;
for(String n : allNames) {
if(n.equals(name)){
match = true;
break;
}
}
if(match){
fontName = name;
dFont = new Font(fontName, Font.PLAIN, fontSize);
}
else {
System.out.println("ERROR: EZText is unable to use the specified font because it not on this system:" + name);
System.out.println(" The change will not be applied.");
}
} //end else try look up a system font
} //end setfont to
/**
* Will return the name of the font currently being used.
* @return String containing the name of the font being used.
*/
public String getFont() {
return fontName;
}
/**
* Checks if the specified ttf file has already been loaded.
* If it has will assign fontName and dFont correct value.
* @param fName ttf file name to check if was already loaded.
* @return true if it was and able to set the value, otherwise false.
*/
private boolean checkIfAlreadyLoaded(String fName) {
for(int i = 0; i < loadedFiles.size(); i++) {
if( loadedFiles.get(i).equals(fName)){
fontName = fName;
dFont = loadedFonts.get(i);
return true;
}
}//end for each loaded file name
return false;
}
/**
* Will try to load a font from the specified ttf file.
* If successful, will correctly set drawing attributes.
* Otherwise will output an error, but will not halt the program.
* @param fName ttf file to load from.
*/
private void tryLoadFontFromFile(String fName) {
try {
Font temp = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream(fName));
fontName = fName;
dFont = temp;
loadedFonts.add(temp);
loadedFiles.add(fName);
}
catch (Exception e) {
e.printStackTrace();
System.out.println("ERROR: EZText was unable to load a text from the specified file:" + fName);
System.out.println(" The change will not be applied.");
}
}
} // end visual text class
/**
* The VisualImage is designed to draw an image from a file.
* The following should be taken into consideration when using EZImage:<br>
* -the image file associated on creation cannot be changed.<br>
* -width and height cannot be directly set, it is based upon the image file itself.<br>
* -getWidth() and getHeight() will return the values from the image file.<br>
* -images are always "filled", using the setFilled() method will not do anything.<br>
* -images cannot have color assigned to them, setColor() will not do anything and getColor() will always return black.<br>
* -if the image has transparencies, they will work.<br>
* <br>
* Mechanical considerations: it is possible to create multiple EZImages that refer to the same image file. But for the sake of
* memory and efficiency, they will all share the same loaded image data. One major reason for this is say you wanted to use a 1MB image.
* Then you wanted to tile the image. You need to make one EZImage for each of the tiles. If each EZImage had to load the data
* you would have 1MB * # of tiles memory usage. This can get very costly in memory very quickly. While there are some
* negative aspects to this method, it is unlikely they will be encountered in the context of ICS111.
*
* @author Dylan Kobayashi
*
*/
class EZImage extends EZElement {
//used for drawing.
protected double xCenter;
protected double yCenter;
//reference to the image file.
protected BufferedImage img;
protected boolean imgHasFocus;
protected int xtlf, ytlf, xbrf, ybrf; //x y t(op) or b(ottom) l(eft) or r(ight) f(ocus) values
// Images are using static values to reduce memory usage. Otherwise, each time something was created there would be
// memory set for each object using the image equal to the image size.
protected static ArrayList<String> usedImageNames = new ArrayList<String>();
protected static ArrayList<BufferedImage> loadedImages = new ArrayList<BufferedImage>();
/**
* This will check if the given image name has already been loaded into memory. If so, it will return that
* BufferedImage, otherwise null.
*
* @param imgName to check if was loaded.
* @return corresponding BufferedImage or null.
*/
protected static BufferedImage checkLoadedImages(String imgName) {
for (int i = 0; i < usedImageNames.size(); i++) {
if (usedImageNames.get(i).equals(imgName)) {
return loadedImages.get(i);
}
}
return null;
} // end checkLoaded Images
/**
* Try load image will automatically search opened images before trying to allocate memory for an image. Will return a
* BufferedImage or null.
*
* @param imgName to try to open.
* @return the BufferedImage or null.
*/
protected static BufferedImage tryLoadImage(String imgName) {
BufferedImage tempImg = checkLoadedImages(imgName);
if (tempImg == null) {
try {
tempImg = ImageIO.read(new File(imgName));
}
catch (IOException e) {
System.out.println("ERROR: Unable to open specified imagefile:" + imgName);
}
}
return tempImg;
} // end tryloadimage
/**
* Creates a visual image with the specifications.
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addImage() method which will perform additional background actions to get the image to display
* on the window properly.
*
* @param filename of the image to use.
* @param x center coordinate.
* @param y center coordinate.
*/
public EZImage(String filename, int x, int y) {
img = tryLoadImage(filename);
xCenter = x;
yCenter = y;
} // end constructor
@Override public void paint(Graphics2D g2) {
if (this.isShowing) {
if (img == null) {
g2.setColor(Color.BLACK);
String err = "Failed to load image";
int wos = EZElement.getWidthOf(err);
int hos = EZElement.getHeightOf(err);
g2.drawRect((int) xCenter - wos / 2 - 10, (int) yCenter - hos / 2 - 10, wos + 20, hos + 20);
g2.drawString(err, (int) xCenter - wos / 2, (int) yCenter);
}
else {
AffineTransform originalG2 = g2.getTransform();
AffineTransform thisObjectTransform = EZElement.transformHelper(this, true);
// System.out.printf("Starting scale: x: %s, y: %s%n", EZ.getStartingPaintScaleX(), EZ.getStartingPaintScaleY());
// thisObjectTransform.setToScale(
// thisObjectTransform.getScaleX() * EZ.getStartingPaintScaleX(),
// thisObjectTransform.getScaleY() * EZ.getStartingPaintScaleY());
// thisObjectTransform.setToTranslation(
// thisObjectTransform.getTranslateX() * EZ.getStartingPaintScaleX(),
// thisObjectTransform.getTranslateY() * EZ.getStartingPaintScaleY());
// System.out.printf("Starting rotation: x: %s, y: %s%n",
// thisObjectTransform.rota.getStartingPaintScaleX(), EZ.getStartingPaintScaleY());
// thisObjectTransform.rotation
g2.setTransform(thisObjectTransform);
// adjust scale
if(imgHasFocus) {
g2.drawImage(img,
-(xbrf - xtlf)/2, -(ybrf-ytlf)/2,
(xbrf - xtlf)/2, (ybrf-ytlf)/2,
xtlf, ytlf,
xbrf, ybrf, null);
}
else {
g2.drawImage(img, -img.getWidth() / 2, -img.getHeight() / 2, null);
}
g2.setTransform(originalG2);
}
}
}// end paint
@Override public void show() {
isShowing = true;
}
@Override public void hide() {
isShowing = false;
}
@Override public int getXCenter() {
return (int) xCenter;
}
/**
* This will set the x center coordinate of the image to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param x coordinate the center will be set to.
*/
private void setXCenter(double x) {
xCenter = x;
}
@Override public int getYCenter() {
return (int) yCenter;
}
/**
* This will set the y center coordinate of the image to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param y coordinate the center will be set to.
*/
private void setYCenter(double y) {
yCenter = y;
}
/**
* The color of an image cannot be set.
* @param c will be discarded.
*/
@Override public void setColor(Color c) { }
/**
* Images do not have one color. It is determined by the contents of image file. Will return BLACK by default.
* @return always Color.BLACK.
* */
@Override public Color getColor() {
return Color.BLACK;
}
/**
* Images are technically always filled with their specified image.
* @return always true.
*/
@Override public boolean isFilled() {
return true;
}
/**
* Images cannot have their fill status changed. This method won't do anything.
* @param f will be discarded.
*/
@Override public void setFilled(boolean f) { }
@Override public void translateTo(double x, double y) {
xCenter = x;
yCenter = y;
}
@Override public void translateBy(double x, double y) {
xCenter += x;
yCenter += y;
}
@Override public void identity() {
setXCenter(0);
setYCenter(0);
rotationInDegrees = 0;
scaleWith1AsOriginal = 1.0;
}
@Override public int getHeight() {
if(imgHasFocus) { return (ybrf - ytlf); }
return img.getHeight();
}
@Override public int getWidth() {
if(imgHasFocus) { return (xbrf - xtlf); }
return img.getWidth();
}
@Override public Shape getBounds() {
return EZElement.boundHelper(
new Rectangle(-getWidth() / 2, -getHeight() / 2, getWidth(), getHeight()), this);
}
/**
* Will set a focus area on the image that will be displayed instead of the entire image. The focus
* area is determined by a rectangle shape formed by two points. The first two parameters
* represent the top left corner of the rectangle while the last two parameters represent the bottom right
* corner of the rectangle.
* <br>
* There are NO restricts on the values given. This allows points which do not exist on the image.
* If the focus area includes coordinates which are not part of the image, they are assumed to be fully transparent.
* Swapping the coordinates will flip the image.
* @param xTopLeftCorner
* @param yTopLeftCorner
* @param xBottomRightCorner
* @param yBottomRightCorner
*/
public void setFocus(int xTopLeftCorner, int yTopLeftCorner, int xBottomRightCorner, int yBottomRightCorner) {
xtlf = xTopLeftCorner;
ytlf = yTopLeftCorner;
xbrf = xBottomRightCorner;
ybrf = yBottomRightCorner;
imgHasFocus = true;
}
/**
* If a focus area has been set, it will be released and the entire image will be shown.
* Otherwise no effect.
*/
public void releaseFocus() {
imgHasFocus = false;
}
/**
* Returns whether or not the image has a focus area set.
* @return true if a focus area has been set, otherwise false.
*/
public boolean hasFocus() { return imgHasFocus; }
} // end visual image class
/**
* The EZLine is used to draw a line between two specified points.
* The following should be taken into consideration when using EZLine:<br>
* -width and height cannot be directly set, it is based upon the points that define the line.<br>
* -getWidth() and getHeight() do not return the "length" or thickness of the line. Instead, width returns the difference between the x coordinates of the two points, while height returns the difference between the y coordinates of the two points.<br>
* -getXCenter() and getYCenter() will give the center coordinate of the line.
* -line rotation is base upon the idea that the line starts off horizontal at that center x,y coordinate. Rotation is the amount necessary to make the line connect the two points pivoting around the center coordinate.
* -lines are always "filled", using the setFilled() method will not do anything.<br>
* -lines cannot be locally scaled. To change the size use setThickness(), setPoint1() and setPoint2().<br>
* <br>
*
*
* @author Dylan Kobayashi
*
*/
class EZLine extends EZElement {
private Rectangle rsub;
private int hypot, x1, x2, y1, y2;
private double originalDegrees;
protected Color color;
private double cx, cy;
/**
* Creates a line with the specifications. Thickness less than 1 will be automatically increased to 1.
*
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addLine() method which will perform additional background actions to get the line to display
* on the window properly.
*
* @param x1 coordinate of point 1.
* @param y1 coordinate of point 1.
* @param x2 coordinate of point 2.
* @param y2 coordinate of point 2.
* @param thickness of the line.
* @param color to draw the line in.
*/
public EZLine(int x1, int y1, int x2, int y2, Color color, int thickness) {
int dx, dy;
dx = x2 - x1;
dy = y2 - y1;
this.cx = dx / 2 + x1;
this.cy = dy / 2 + y1;
this.hypot = (int) Math.hypot(dx, dy);
if (thickness < 1) {
thickness = 1;
} // cannot have a thickness less than 1.
rsub = new Rectangle(-hypot / 2, -thickness / 2, hypot, thickness);
rotationInDegrees = originalDegrees = Math.toDegrees(Math.atan2(dy, dx));
this.color = color;
this.x1 = x1; // used for get methods();
this.x2 = x2;
this.y1 = y1;
this.y2 = y2;
} // end constructor
@Override public void paint(Graphics2D g2) {
if (this.isShowing) {
g2.setColor(color);
g2.fill(this.getBounds());
}
}// end paint
@Override public void show() {
isShowing = true;
}
@Override public void hide() {
isShowing = false;
}
/**
* Returns the x coordinate of point 1.
* @return the x coordinate of point 1.
*/
public int getX1() {
return x1;
}
/**
* Returns the y coordinate of point 1.
* @return the y coordinate of point 1.
*/
public int getY1() {
return y1;
}
/**
* Returns the x coordinate of point 2.
* @return the x coordinate of point 2.
*/
public int getX2() {
return x2;
}
/**
* Returns the y coordinate of point 2.
* @return the y coordinate of point 2.
*/
public int getY2() {
return y2;
}
/**
* Changes the coordinate of point 1, which will probably result in a change of center and rotation.
* @param x coordinate point 1 will be set to.
* @param y coordinate point 1 will be set to.
*/
public void setPoint1(int x, int y) {
x1 = x;
y1 = y;
int dx = x2 - x1;
int dy = y2 - y1;
this.cx = dx / 2 + x1;
this.cy = dy / 2 + y1;
this.hypot = (int) Math.hypot(dx, dy);
rsub.width = hypot;
rotationInDegrees = originalDegrees = Math.toDegrees(Math.atan2(dy, dx));
} // end set point 1
/**
* Changes the position of point 2, which will probably result in a change of length, center and rotation.
* @param x coordinate point 2 will be set to.
* @param y coordinate point 2 will be set to.
* */
public void setPoint2(int x, int y) {
x2 = x;
y2 = y;
int dx = x2 - x1;
int dy = y2 - y1;
this.cx = dx / 2 + x1;
this.cy = dy / 2 + y1;
this.hypot = (int) Math.hypot(dx, dy);
rsub.width = hypot;
rotationInDegrees = originalDegrees = Math.toDegrees(Math.atan2(dy, dx));
} // end set point 1
/**
* Will increase the thickness of the line to given parameter.
* @param t new thickness in pixels.
*/
public void setThickness(int t) {
this.rsub.height = t;
}
/**
* Returns the current thickness of the line.
* @return thickness in pixels.
*/
public int getThickness() {
return this.rsub.height;
}
@Override public Color getColor() {
return color;
}
@Override public void setColor(Color nv) {
this.color = nv;
}
/**
* Lines are technically always filled.
* @return always true.
*/
public boolean isFilled() {
return true;
}
/**
* Lines cannot have their fill status changed. This method won't do anything.
* @param f will be discarded.
*/
public void setFilled(boolean f) { }
/**
* The value returned is actually the difference between the x coordinates of the two points.
* The returned value will always be positive, even if point 2 has an x value that is less than point 1.
*
* @return difference between the two point's x coordinate as a positive value.
*/
@Override public int getWidth() {
return (Math.abs(x1 - x2) + 1);
}
/**
* The value returned is actually the difference between the y coordinates of the two points.
* The returned value will always be positive, even if point 2 has an y value that is less than point 1.
*
* @return difference between the two point's y coordinate as a positive value.
*/
@Override public int getHeight() {
return (Math.abs(y1 - y2) + 1);
}
/**
* This returns the x coordinate of the center of the line.
* @return x coordinate.
*/
@Override public int getXCenter() {
return (int) cx;
}
/**
* This returns the y coordinate of the center of the line.
* @return y coordinate.
*/
@Override public int getYCenter() {
return (int) cy;
}
/**
* Translations will alter both point locations that the line connects while preserving the rotation.
* @param x coordinate the center will be set to.
* @param y coordinate the center will be set to.
*/
@Override public void translateTo(double x, double y) {
cx = x;
cy = y;
int dx = (int) (Math.sin(Math.toRadians(rotationInDegrees)) * rsub.width);
int dy = (int) (Math.cos(Math.toRadians(rotationInDegrees)) * rsub.width);
this.x1 = (int) x - dx / 2;
this.x2 = (int) x + dx / 2;
this.y1 = (int) y + dy / 2;
this.y2 = (int) y - dy / 2;
}
/**
* Translations will alter both point locations that the line connects while preserving the rotation.
* @param x coordinate the center will be shifted by.
* @param y coordinate the center will be shifted by.
*/
@Override public void translateBy(double x, double y) {
cx += x;
cy += y;
this.x1 += x;
this.x2 += x;
this.y1 += y;
this.y2 += y;
}
@Override public Shape getBounds() {
return EZElement.boundHelper(new Rectangle(-rsub.width / 2, -rsub.height / 2, rsub.width, rsub.height), this);
}
/**
* Lines cannot be scaled. Use the set point methods.
* @param s will be discarded.
* */
@Override public void scaleBy(double s) { }
/**
* Lines cannot be scaled. Use the set point methods.
* @param s will be discarded.
* */
@Override public void scaleTo(double s) { }
@Override public void identity() {
this.cx = 0;
this.cy = 0;
this.rotationInDegrees = originalDegrees;
int dx = (int) (Math.sin(Math.toRadians(rotationInDegrees)) * rsub.width);
int dy = (int) (Math.cos(Math.toRadians(rotationInDegrees)) * rsub.width);
this.x1 = -dx / 2;
this.x2 = dx / 2;
this.y1 = dy / 2;
this.y2 = -dy / 2;
}
} // end visual line class
/**
* The EZPolygon is used to draw a polygon. The shape of a polygon is defined by a series of points. When drawn, lines
* will be made to connect each of the points. The last point will have a line connecting it to the first point.
*
* @author Dylan Kobayashi
*
*/
class EZPolygon extends EZElement {
/** The polygon used to draw the shape and do calculations. */
protected Polygon drawShape;
protected Polygon tempShape;
protected Shape transformShape;
protected Color color;
protected boolean filled;
protected boolean error = false;
/** Used to track center with decimal values. */
private double xcd, ycd;
/**
* Creates a polygon with the specifications.
*
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addPolygon() method which will perform additional background actions to get the polygon to display
* on the window properly.
*
* @param xp an array containing each of the point's x coordinates in sequence.
* @param yp an array containing each of the point's y coordinates in sequence.
* @param c color to draw the polygon in.
* @param f whether or not the polygon will be filled.
*/
public EZPolygon(int[] xp, int[] yp, Color c, boolean f) {
color = c;
filled = f;
xcd = ycd = 0;
try {
drawShape = new Polygon(xp, yp, xp.length);
xcd = drawShape.getBounds().getCenterX();
ycd = drawShape.getBounds().getCenterY();
}
catch (Exception e) {
error = true;
e.printStackTrace();
}
if (xp.length < 3) {
error = true;
System.out.println("Polygon creation needs at least 3 points.");
}
} // end constructor
@Override public void paint(Graphics2D g2) {
if (this.isShowing) {
g2.setColor(color);
if (!error) {
if (filled) {
g2.fill(this.getBounds());
}
else {
g2.draw(this.getBounds());
}
}
else {
g2.drawString("Error with polygon, see console for more details", 100, 100);
}
}
}// end paint
@Override public void show() {
isShowing = true;
}
@Override public void hide() {
isShowing = false;
}
@Override public Color getColor() {
return color;
}
@Override public void setColor(Color c) {
color = c;
}
@Override public boolean isFilled() {
return filled;
}
@Override public void setFilled(boolean c) {
filled = c;
}
@Override public int getXCenter() {
return (int) xcd;
}
@Override public int getYCenter() {
return (int) ycd;
}
@Override public int getWidth() {
return (int) drawShape.getBounds().getWidth();
}
@Override public int getHeight() {
return (int) drawShape.getBounds().getHeight();
}
/**
* Sets the center of the polygon to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param cx coordinate the x center will be set to.
*/
private void setXCenter(double cx) {
xcd = cx;
drawShape.translate(-1 * (int) (drawShape.getBounds().getCenterX()), -1
* (int) (drawShape.getBounds().getCenterY()));
drawShape.translate((int) xcd, (int) ycd);
}
/**
* Sets the center of the polygon to the given value.
* Made a private method since the user should be using translateBy and translateTo instead.
* @param cy coordinate the y center will be set to.
*/
private void setYCenter(double cy) {
ycd = cy;
drawShape.translate(-1 * (int) (drawShape.getBounds().getCenterX()), -1
* (int) (drawShape.getBounds().getCenterY()));
drawShape.translate((int) xcd, (int) ycd);
}
@Override public void translateTo(double x, double y) {
this.setXCenter(x);
this.setYCenter(y);
}
@Override public void translateBy(double x, double y) {
xcd += x;
ycd += y;
this.setXCenter(xcd);
this.setYCenter(ycd);
}
@Override public void identity() {
this.setXCenter(0);
this.setYCenter(0);
rotationInDegrees = 0;
scaleWith1AsOriginal = 1.0;
}
@Override public Shape getBounds() {
tempShape = new Polygon(drawShape.xpoints, drawShape.ypoints, drawShape.xpoints.length);
tempShape.translate(-1 * (tempShape.getBounds().x + tempShape.getBounds().width/2), -1 * (tempShape.getBounds().y + tempShape.getBounds().height/2));
return EZElement.boundHelper(tempShape, this);
}
} // end visual polygon class
/**
* This class is designed to collect keyboard and mouse input for the window.
* The methods will not work unless EZ.initialize() has been called.
*
* @author Dylan Kobayashi
*
*/
class EZInteraction implements KeyListener, MouseInputListener {
/** Used as for external referencing. */
public static EZInteraction app;
// /** Used for tracking keys down. */
// protected ArrayList<Character> keysDown = new ArrayList<Character>();
// /** Used for tracking key releases. */
// protected ArrayList<Character> keysReleased = new ArrayList<Character>();
// /** Used for tracking key presses. */
// protected ArrayList<Character> keysPressed = new ArrayList<Character>();
/** Used for tracking keys down. */
protected Map<String, Integer> keysDown = new HashMap<>();
/** Used for tracking key releases. */
protected Map<String, Integer> keysReleased = new HashMap<>();
/** Used for tracking key presses. */
protected Map<String, Integer> keysPressed = new HashMap<>();
/** Used for indexing. */
protected int keysDownIndex = 0;
/**
* Used for tracking mouse clicks. This is not very efficient and currently just used as a means to get click
* detection that the students can call from an outside location.
*/
private static int mMoveX;
private static int mMoveY;
private static long keyrLastUpdate;
private static long keypLastUpdate;
private static boolean keyrCheckInitiated = false;
private static boolean keypCheckInitiated = false;
private static long TIMEOUT = 1; // 1 ms storage for clicks.
private static boolean mlbPressed = false;
private static boolean mlbDown = false;
private static boolean mlbReleased = false;
private static boolean mrbPressed = false;
private static boolean mrbDown = false;
private static boolean mrbReleased = false;
private static long mlbPTime = 0; //used to store their press and release time.
private static long mlbRTime = 0;
private static long mrbPTime = 0;
private static long mrbRTime = 0;
/**
* Constructor's job is to associate external public reference.
* You should not be using this. EZ.initialize() will take care of this in the background.
* */
public EZInteraction() {
app = this;
}
@Override public void keyPressed(KeyEvent e) {
keypCheckInitiated = false;
String keyToUse;
int valueToUse;
try {
if ( e.getKeyCode() == KeyEvent.VK_UP ) { keyToUse = "VK_UP"; valueToUse = e.getKeyCode(); }
else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) { keyToUse = "VK_DOWN"; valueToUse = e.getKeyCode(); }
else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) { keyToUse = "VK_LEFT"; valueToUse = e.getKeyCode(); }
else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) { keyToUse = "VK_RIGHT"; valueToUse = e.getKeyCode(); }
else if ( ! Character.isLetterOrDigit( e.getKeyChar() ) ) { keyToUse = "kc" + e.getKeyCode(); valueToUse = e.getKeyCode(); }
else {
keyToUse = "" + e.getKeyChar();
valueToUse = e.getKeyCode();
}
keysDown.put(keyToUse, valueToUse);
keysPressed.put(keyToUse, valueToUse);
}
catch (Exception ex) {
System.out
.println("Unexpected thread sync conflict in key detection.\n---Problem has been handled, but may have lost key input in the process.");
ex.printStackTrace();
}
} // end keypressed
@Override public void keyReleased(KeyEvent e) {
keyrCheckInitiated = false;
String keyToUse;
int valueToUse;
try {
if ( e.getKeyCode() == KeyEvent.VK_UP ) { keyToUse = "VK_UP"; valueToUse = e.getKeyCode(); }
else if ( e.getKeyCode() == KeyEvent.VK_DOWN ) { keyToUse = "VK_DOWN"; valueToUse = e.getKeyCode(); }
else if ( e.getKeyCode() == KeyEvent.VK_LEFT ) { keyToUse = "VK_LEFT"; valueToUse = e.getKeyCode(); }
else if ( e.getKeyCode() == KeyEvent.VK_RIGHT ) { keyToUse = "VK_RIGHT"; valueToUse = e.getKeyCode(); }
else if ( ! Character.isLetterOrDigit( e.getKeyChar() ) ) { keyToUse = "kc" + e.getKeyCode(); valueToUse = e.getKeyCode(); }
else { keyToUse = "" + e.getKeyChar(); valueToUse = e.getKeyCode(); }
keysReleased.put(keyToUse, valueToUse);
keysDown.remove(keyToUse);
}// end try
catch (Exception ex) {
System.out
.println("Unexpected thread sync conflict in key detection.\n---Problem has been handled, but may have lost key input in the process.");
ex.printStackTrace();
}
} // end key released
/**
* Used for actively checking if a key is down(being pressed).
*
* @param key to check for.
* @return true if the key is down. Otherwise false.
*/
public static boolean isKeyDown(String key) {
try {
return app.keysDown.containsKey(key);
}
catch (Exception e) {
/*
* this try catch is for the rare case where the key might start off "down" but then becomes "up" while in the
* process of going through the map. The error is result of the size starting off "larger" but because a key
* get's released, the map decreases in size resulting in an error that may crash the thread that calls this
* method, because thread timing is concurrent.
*
* Anyone reading this, yes the code actually utilizes multiple threads.
*/
}
return false;
} // end is key down
/** Overload command to backwards compatible char call. */
public static boolean isKeyDown(char c) { return isKeyDown("" + c); }
/** Overload command to allow keycode checks. */
public static boolean isKeyDown(int code) { return app.keysDown.containsValue(code); }
/**
* Checks if a key was just released. See description for getXMouseClick(), uses the same timing ideology.
* */
public static boolean wasKeyReleased(String key) {
if (!keyrCheckInitiated) {
keyrCheckInitiated = true;
keyrLastUpdate = System.currentTimeMillis();
}
if (keyrLastUpdate + TIMEOUT < System.currentTimeMillis()) {
app.keysReleased.clear();
}
try {
return app.keysReleased.containsKey(key);
}// end try
catch (Exception e) {
}
return false;
} // end waskey released
/** Overload command to backwards compatible char call. */
public static boolean wasKeyReleased(char c) { return wasKeyReleased("" + c); }
/** Overload command to allow keycode checks. */
public static boolean wasKeyReleased(int code) { wasKeyReleased(""); return app.keysReleased.containsValue(code); }
/**
* Checks if a key was just pressed. See description for getXMouseClick(), uses the same timing ideology.
* */
public static boolean wasKeyPressed(String key) {
try {
if (!keypCheckInitiated) {
keypCheckInitiated = true;
keypLastUpdate = System.currentTimeMillis();
}
if (keypLastUpdate + TIMEOUT < System.currentTimeMillis()) {
app.keysPressed.clear();
}
return app.keysPressed.containsKey(key);
}// end try
catch (Exception e) {
}
return false;
} // end waskey released
/** Overload command to backwards compatible char call. */
public static boolean wasKeyPressed(char c) { return wasKeyPressed("" + c); }
/** Overload command to allow keycode checks. */
public static boolean wasKeyPressed(int code) { wasKeyPressed(""); return app.keysPressed.containsValue(code); }
@Override public void mousePressed(MouseEvent me) {
// System.out.println("Mouse pressed");
if (me.getButton() == 1) {
mlbPressed = true;
mlbDown = true;
mlbReleased = false;
mlbPTime = -1;
}
else if(me.getButton() == 3) {
mrbPressed = true;
mrbDown = true;
mrbPTime = -1;
mrbReleased = false;
}
}
@Override public void mouseReleased(MouseEvent me) {
if (me.getButton() == 1) { //left
mlbPressed = false;
mlbDown = false;
mlbReleased = true;
mlbRTime = -1;
}
else if(me.getButton() == 3) { //right
mrbPressed = false;
mrbDown = false;
mrbReleased = true;
mrbRTime = -1;
}
}// System.out.println("Mouse released"); }
/**
* Updated version of left button click status.
* Used to detect if the left button was pressed.
* There is a TIMEOUT associated to allow multiple calls within a particular update.
* @return true if the left mouse button was just pressed, otherwise false.
*/
public static boolean wasMouseLeftButtonPressed() {
if(mlbPTime == -1 && mlbDown) { mlbPTime = System.currentTimeMillis(); }
if(mlbPTime + TIMEOUT <= System.currentTimeMillis() ) {
mlbPressed = false;
}
return mlbPressed;
}
/**
* Updated version of right button click status.
* Used to detect if the right button was pressed.
* There is a TIMEOUT associated to allow multiple calls within a particular update.
* @return true if the right mouse button was just pressed, otherwise false.
*/
public static boolean wasMouseRightButtonPressed() {
if(mrbPTime == -1 && mrbDown) { mrbPTime = System.currentTimeMillis(); }
if(mrbPTime + TIMEOUT <= System.currentTimeMillis() ) {
mrbPressed = false;
}
return mrbPressed;
}
/**
* Used to detect if the left button is down.
* @return true if the left mouse button is down, otherwise false.
*/
public static boolean isMouseLeftButtonDown() {
return mlbDown;
}
/**
* Used to detect if the right button is down.
* @return true if the right mouse button is down, otherwise false.
*/
public static boolean isMouseRightButtonDown() {
return mrbDown;
}
/**
* Used to detect if the left button was released.
* There is a TIMEOUT associated to allow multiple calls within a particular update.
* @return true if the left mouse button was just pressed, otherwise false.
*/
public static boolean wasMouseLeftButtonReleased() {
if(mlbRTime == -1 && !mlbDown) { mlbRTime = System.currentTimeMillis(); }
if(mlbRTime + TIMEOUT <= System.currentTimeMillis() ) {
mlbReleased = false;
}
return mlbReleased;
}
/**
* Used to detect if the right button was released.
* There is a TIMEOUT associated to allow multiple calls within a particular update.
* @return true if the right mouse button was just pressed, otherwise false.
*/
public static boolean wasMouseRightButtonReleased() {
if(mrbRTime == -1 && !mrbDown) { mrbRTime = System.currentTimeMillis(); }
if(mrbRTime + TIMEOUT <= System.currentTimeMillis() ) {
mrbReleased = false;
}
return mrbReleased;
}
@Override public void mouseExited(MouseEvent arg0) {
mMoveX = -1;
mMoveY = -1;
}
@Override public void mouseMoved(MouseEvent me) {
mMoveX = me.getX();
mMoveY = me.getY();
}
@Override public void mouseDragged(MouseEvent me) {
mMoveX = me.getX();
mMoveY = me.getY();
}// System.out.println("Mouse drag"); }
/**
* Returns the x coordinate of the mouse if it is over the window.
* @return x coordinate of the mouse if over the window. Otherwise -1.
*/
public static int getXMouse() {
return mMoveX;
}
/**
* Returns the y coordinate of the mouse if it is over the window.
* @return y coordinate of the mouse if over the window. Otherwise -1.
*/
public static int getYMouse() {
return mMoveY;
}
@Override public void mouseClicked(MouseEvent arg0) {
}
@Override public void mouseEntered(MouseEvent arg0) {
}
@Override public void keyTyped(KeyEvent e) {
// System.out.println("key typed");
}
} // end input handler class
/**
* The EZ is designed to draw an image from a file.
* The following should be taken into consideration when using EZSound:<br>
* -ONLY works with .wav files.<br>
* -the associated sound cannot be changed once created, but that is ok due to storage type the overhead is relatively low. <br>
* -while the sound is managed by EZ, EZSound is not an EZElement, as it is not draw.<br>
* -sound files are stored in a static history with the AudioInputStream to reduce memory usage. A process similar to EZImage.<br>
*
* @author Dylan Kobayashi
*/
class EZSound {
protected static ArrayList<AudioInputStream> aisList = new ArrayList<AudioInputStream>();
protected static ArrayList<String> aisFile = new ArrayList<String>();
//protected Clip sound;
protected Clip sound;
protected String filename;
/**
* Creates a new sound out of the given file. Must be a .wav file.
*
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addSound() method which will perform additional background actions to bind the sound to the window.
*
* @param file of the sound to load.
* */
public EZSound(String file) {
/*
filename = file;
sound = tryLoadSound(file);
if (sound == null) {
System.out.println("Error loading sound file");
System.exit(1);
}
if (sound == null) {
reloadClip();
}
*/
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(new File(file).getAbsoluteFile());
sound = AudioSystem.getClip();
sound.open(ais);
}
catch (Exception e) {
e.printStackTrace();
System.out.println("Error loading sound file, it may not exist or another program has a lock on it.");
System.exit(1);
}
}// end constructor
/**
* This will play the sound file from wherever the current position is.
*
*/
public void play() {
if( sound.getFramePosition() == sound.getFrameLength() ||
(sound.getFramePosition() != 0 && sound.isRunning()) ) {
sound.setFramePosition(0);
}
sound.start();
}
/**
* This will stop the sound and reset back to the start.
*/
public void stop() {
sound.stop();
sound.setFramePosition(0);
} // end stop()
/**
* Will pause the sound at it's current position. Using play() will resume from this point.
*/
public void pause() {
sound.stop();
}
/**
* Will play from the start and loop the sound... again... and again... and again...
*
*/
public void loop() {
sound.setFramePosition(0);
sound.loop(Clip.LOOP_CONTINUOUSLY);
}
/**
* Will return true if this EZSound is playing. Otherwise false.
* @return true if playing. Otherwise false.
*
*/
public boolean isPlaying() {
return sound.isRunning();
}
/**
* Returns how many frames are held within this sound file.
* @return Positive int value including zero indicating number of frames.
* Otherwise -1 to indicate that the file's length cannot be determined.
*/
public int getFrameLength() {
return sound.getFrameLength();
}
/**
* Returns the current frame of the sound file.
* @return Positive int value including zero indicating the current frame.
*/
public int getFramePosistion() {
return sound.getFramePosition();
}
/**
* Returns the total length of the sound file in microseconds.
* @return Positive long value including zero indicating the length of the sound file.
* Otherwise -1 to indicate the file's length cannot be determined.
*/
public long getMicroSecondLength() {
return sound.getMicrosecondLength();
}
/**
* Returns the current position in microseconds.
* @return Positive long value including zero indicating the position in the sound file.
* Otherwise -1 to indicate the file's position cannot be determined.
*/
public long getMicroSecondPosition() {
return sound.getMicrosecondPosition();
}
/**
* Sets the position in frames from which to continue playing.
* This will be overridden if stop() or loop() is called after this(they reset back to start).
* @param pos frame of the file to start from.
*/
public void setFramePosition(int pos) {
sound.setFramePosition(pos);
}
/**
* Sets the position in microseconds from which to continue playing.
* This will be overridden if stop() or loop() is called after this(they reset back to start).
* Note: the level of precision is based upon ms per frame.
* @param pos milliseconds of the file to start from.
*/
public void setMicrosecondPosition(int pos) {
sound.setMicrosecondPosition(pos);
}
} // end class
/**
* A means to group EZElements together and manipulate them as one element.
*
* Adding an element to a group does the following effects:<br>
* |-Element center coordinates use the group's center as origin.<br>
* |-This may cause the elements coordinates to change.<br>
* |-The element will no longer be tracked by EZ. It will now tracked by the group.<br>
* |-Adjusting draw layer will be limited to the group's draw layer.<br>
* |-pushToBack, pushBackOneLayer,pullToFront,pullForwardOneLayer will be limited to the group.<br>
*
*
* @author Dylan Kobayashi
*
*/
class EZGroup extends EZElement {
/** The x center value of this node. */
private double xCurrent = 0;
/** The y center value of this node. */
private double yCurrent = 0;
/** This will hold all children which are considered to be part of this node. */
private ArrayList<EZElement> children = new ArrayList<EZElement>();
/**
* Creates a group. Center position starts at 0,0. Rotations will be made around center location.
*
* While this constructor is available for usage, it is highly recommended that you do not use this.
* Instead call EZ.addGroup() method which will perform additional background actions to get the group to display
* on the window properly.
*/
public EZGroup() {
this.rotationInDegrees = 0;
this.scaleWith1AsOriginal = 1.0;
}
@Override public void identity() {
this.xCurrent = 0;
this.yCurrent = 0;
this.rotationInDegrees = 0;
this.scaleWith1AsOriginal = 1.0;
} // end identity
@Override public void paint(Graphics2D g2) {
if (this.isShowing) {
for (EZElement e : children) {
e.paint(g2);
}
}
} // end paint
/**
* EZGroups themselves do not have height, the elements they hold have such values.
* If there are no children, will return 0.
* If there are children, will return the difference between the top most point and bottom most point.
*
* @return 0 if no children. Otherwise the positive difference between the top most and bottom most point of all the elements within this group.
*/
@Override public int getHeight() {
int topMost, bottomMost;
if(children.size() == 0){ return 0; }
topMost = children.get(0).getYCenter() - children.get(0).getHeight()/2;
bottomMost = children.get(0).getYCenter() + children.get(0).getHeight()/2;
for(EZElement e : children) {
if( e.getYCenter() - e.getHeight()/2 < topMost ) {
topMost = e.getYCenter() - e.getHeight()/2;
}
if( e.getYCenter() + e.getHeight()/2 > bottomMost ) {
bottomMost = e.getYCenter() + e.getHeight()/2;
}
}
return Math.abs(bottomMost - topMost);
}
/**
* EZGroups themselves do not have width, the elements they hold have such values.
* If there are no children, will return 0.
* If there are children, will return the difference between the left most point and right most point regardless if the child is showing or not.
*
* @return 0 if no children. Otherwise the positive difference between the left most and right most point of all the elements within this group.
*/
@Override public int getWidth() {
int leftMost, rightMost;
if(children.size() == 0){ return 0; }
leftMost = children.get(0).getXCenter() - children.get(0).getWidth()/2;
rightMost = children.get(0).getXCenter() + children.get(0).getWidth()/2;
for(EZElement e : children) {
if( e.getXCenter() - e.getWidth()/2 < leftMost ) {
leftMost = e.getXCenter() - e.getWidth()/2;
}
if( e.getXCenter() + e.getWidth()/2 > rightMost ) {
rightMost = e.getXCenter() + e.getWidth()/2;
}
}
return Math.abs(rightMost - leftMost);
}
@Override public int getXCenter() {
return (int) xCurrent;
}
@Override public int getYCenter() {
return (int) yCurrent;
}
/**
* Groups cannot have color. This doesn't do anything.
* @param c will be discarded.
* */
@Override public void setColor(Color c) { }
/**
* Groups cannot have color. This returns BLACK by default.
* @return Color.BLACK always.
* */
@Override public Color getColor() {
return Color.BLACK;
}
/**
* Groups do not have a "filled" status. Always returns true by default.
* Perhaps you were looking for isShowing()?
* @return true always.
* */
@Override public boolean isFilled() {
return true;
}
/**
* Groups do not have a "filled" status. This method does nothing. Perhaps you were looking for show() or hide()?
* @param f will be discarded.
* */
@Override public void setFilled(boolean f) { }
@Override public void translateTo(double x, double y) {
xCurrent = x;
yCurrent = y;
}
@Override public void translateBy(double x, double y) {
xCurrent += x;
yCurrent += y;
}
/**
* The bounds of a group is determined by the rectangle needed to contain all children, regardless if the child is showing or not. The
* rectangle will always be aligned with the axis. The returned shape will be with respect to the world space.
* This is much different from the other EZElements where the getBounds methods will return the shape after all
* transformations including parent groups have been applied.
*
* @return the shape which is a bounding box containing all elements of this group.
*/
@Override public Shape getBounds() {
ArrayList<EZElement> allChildren = new ArrayList<EZElement>();
EZ.recurseGroupAddingToArrayList(this, allChildren);
int top, bottom, left, right, temp;
top = bottom = left = right = 0;
if (allChildren.size() > 0) {
top = allChildren.get(0).getBounds().getBounds().y;
bottom = top + allChildren.get(0).getBounds().getBounds().height;
left = allChildren.get(0).getBounds().getBounds().x;
right = left + allChildren.get(0).getBounds().getBounds().width;
for (EZElement c : allChildren) {
temp = c.getBounds().getBounds().y;
if (temp < top) {
top = temp;
}
temp = temp + c.getBounds().getBounds().height;
if (temp > bottom) {
bottom = temp;
}
temp = c.getBounds().getBounds().x;
if (temp < left) {
left = temp;
}
temp = temp + c.getBounds().getBounds().width;
if (temp > right) {
right = temp;
}
} // end for each child
}// end if there was at least 1 child.
Rectangle r = new Rectangle(left, top, right - left, bottom - top);
return r;
} // end get bounds.
/**
* Will search all children and their children(if a group) to see if the point is within the elements.
* This is different from checking if the point is within the bound of a group because this doesnβt go by the containing
* rectangle for all elements which may include spaces that are not covered by a child.
*
* Assumes the given point is on world space.
*
* @param x coordinate of the point.
* @param y coordinate of the point.
* @return true if the point is within an element of this group. Otherwise false.
*/
@Override public boolean isPointInElement(int x, int y) {
for (EZElement child : children) {
if (child.isPointInElement(x, y)) {
return true;
}
}
return false;
} // end is point in element
/**
* Will apply a cascading effect of show() calls on all elements in this group.
*/
@Override public void show() {
for (EZElement e : children) {
e.show();
}
}
/**
* Will apply a cascading effect of hide() calls on all elements part of this node.
* */
@Override public void hide() {
for (EZElement e : children) {
e.hide();
}
}
/**
* Adds an element to the group. Since the element would have had an arbitrary coordinate, that element's coordinate
* values will be adjusted such that it will be with relation to the distance from this node's center. Visually
* this will not move the element. When an element is added to the group, the group will attempt to retain the
* element's current draw layer relations with the other elements. Once the element is within a group, the draw
* layer manipulation methods will be restricted to the draw layers within the group.
*
* @param e, the element to add.
* @return true if it was able to add the element. Otherwise false, meaning the element was already part of a group.
*/
public boolean addElement(EZElement e) {
if (e.setParent(this)) {
// Correctly position the element's center with relation to the node's center
e.translateTo(e.getXCenter() - xCurrent, e.getYCenter() - yCurrent);
int addindex = -1;
for(int i = 0; i < children.size(); i++){
if( EZ.app.elements.indexOf(e) < EZ.app.elements.indexOf( children.get(i) ) ){
addindex = i;
break;
}
}
if(addindex > -1) { children.add(addindex, e); }
else { children.add(e); }
return true;
}
return false;
} // end add element
/**
* Will attempt to remove the specified element.
* The element will have coordinates, scale and rotation adjusted such that visually it will not look like anything has changed.
*
* When an element is removed from a group, it will go back to the draw layer it was at before being added to the group.
* Any changes to the draw layer that the element received while in the group will be discarded when it is
* removed from the group.
*
* @param e, the element to attempt to remove.
* @return true if successful, otherwise false.
*/
public boolean removeElement(EZElement e) {
if (children.contains(e)) {
ArrayList<EZElement> ancestors = new ArrayList<EZElement>();
EZElement temp;
temp = e;
while (temp.hasParent()) {
ancestors.add(temp.getParent());
temp = temp.getParent();
}
double fRotation, fScale, fcx, fcy;
fRotation = 0;
fScale = 1.0;
for (EZElement anc : ancestors) {
fRotation += anc.getRotation();
fScale *= anc.getScale();
}
fcx = e.getBounds().getBounds().getCenterX();
fcy = e.getBounds().getBounds().getCenterY();
if(e instanceof EZGroup){
AffineTransform at = EZElement.transformHelper(e);
fcx = at.getTranslateX();
fcy = at.getTranslateY();
}
e.removeParent();
children.remove(e);
e.translateTo(fcx, fcy);
e.scaleTo(fScale);
e.rotateTo(fRotation);
return true;
}
System.out.println("Unable to remove specified Element of " +
Thread.currentThread().getStackTrace()[2].getFileName() + ":" +
Thread.currentThread().getStackTrace()[2].getLineNumber()
);
return false;
} // end remove element
/**
* Returns an ArrayList of EZElements containing all children of this element.
* Will not search out sub children. For example, if an EZGroup contains EZGroups with elements, those groups
* will be part of the ArrayList, not the children of the those groups.
*
* Note: knowledge of polymorphism may be necessary to use this method.
*
* @return an ArrayList of the children of this group.
*/
public ArrayList<EZElement> getChildren() {
return children;
}
} // end EZGroup
| RyogaYamauchi/java_spring | EZ.java |
1,017 |
/* Class for implementing md4 and md5 hash algorithms.
* There are constructors for prepping the hash algorithm (doing the
* padding, mainly) for a String or a byte[], and an mdcalc() method
* for generating the hash. The results can be accessed as an int array
* by getregs(), or as a String of hex digits with toString().
*
* Written for jotp, by Harry Mantakos [email protected]
*
* Feel free to do whatever you like with this code.
* If you do modify or use this code in another application,
* I'd be interested in hearing from you!
*/
class md4 extends md {
md4(String s) {
super(s);
}
md4(byte in[]) {
super(in);
}
static int F(int x, int y, int z) {
return((x & y) | (~x & z));
}
static int G(int x, int y, int z) {
return((x & y) | (x & z) | (y & z));
}
static int H(int x, int y, int z) {
return(x ^ y ^ z);
}
void round1(int blk) {
A = rotintlft((A + F(B, C, D) + d[0 + 16 * blk]), 3);
D = rotintlft((D + F(A, B, C) + d[1 + 16 * blk]), 7);
C = rotintlft((C + F(D, A, B) + d[2 + 16 * blk]), 11);
B = rotintlft((B + F(C, D, A) + d[3 + 16 * blk]), 19);
A = rotintlft((A + F(B, C, D) + d[4 + 16 * blk]), 3);
D = rotintlft((D + F(A, B, C) + d[5 + 16 * blk]), 7);
C = rotintlft((C + F(D, A, B) + d[6 + 16 * blk]), 11);
B = rotintlft((B + F(C, D, A) + d[7 + 16 * blk]), 19);
A = rotintlft((A + F(B, C, D) + d[8 + 16 * blk]), 3);
D = rotintlft((D + F(A, B, C) + d[9 + 16 * blk]), 7);
C = rotintlft((C + F(D, A, B) + d[10 + 16 * blk]), 11);
B = rotintlft((B + F(C, D, A) + d[11 + 16 * blk]), 19);
A = rotintlft((A + F(B, C, D) + d[12 + 16 * blk]), 3);
D = rotintlft((D + F(A, B, C) + d[13 + 16 * blk]), 7);
C = rotintlft((C + F(D, A, B) + d[14 + 16 * blk]), 11);
B = rotintlft((B + F(C, D, A) + d[15 + 16 * blk]), 19);
}
void round2(int blk) {
A = rotintlft((A + G(B, C, D) + d[0 + 16 * blk] + 0x5a827999), 3);
D = rotintlft((D + G(A, B, C) + d[4 + 16 * blk] + 0x5a827999), 5);
C = rotintlft((C + G(D, A, B) + d[8 + 16 * blk] + 0x5a827999), 9);
B = rotintlft((B + G(C, D, A) + d[12 + 16 * blk] + 0x5a827999), 13);
A = rotintlft((A + G(B, C, D) + d[1 + 16 * blk] + 0x5a827999), 3);
D = rotintlft((D + G(A, B, C) + d[5 + 16 * blk] + 0x5a827999), 5);
C = rotintlft((C + G(D, A, B) + d[9 + 16 * blk] + 0x5a827999), 9);
B = rotintlft((B + G(C, D, A) + d[13 + 16 * blk] + 0x5a827999), 13);
A = rotintlft((A + G(B, C, D) + d[2 + 16 * blk] + 0x5a827999), 3);
D = rotintlft((D + G(A, B, C) + d[6 + 16 * blk] + 0x5a827999), 5);
C = rotintlft((C + G(D, A, B) + d[10 + 16 * blk] + 0x5a827999), 9);
B = rotintlft((B + G(C, D, A) + d[14 + 16 * blk] + 0x5a827999), 13);
A = rotintlft((A + G(B, C, D) + d[3 + 16 * blk] + 0x5a827999), 3);
D = rotintlft((D + G(A, B, C) + d[7 + 16 * blk] + 0x5a827999), 5);
C = rotintlft((C + G(D, A, B) + d[11 + 16 * blk] + 0x5a827999), 9);
B = rotintlft((B + G(C, D, A) + d[15 + 16 * blk] + 0x5a827999), 13);
}
void round3(int blk) {
A = rotintlft((A + H(B, C, D) + d[0 + 16 * blk] + 0x6ed9eba1), 3);
D = rotintlft((D + H(A, B, C) + d[8 + 16 * blk] + 0x6ed9eba1), 9);
C = rotintlft((C + H(D, A, B) + d[4 + 16 * blk] + 0x6ed9eba1), 11);
B = rotintlft((B + H(C, D, A) + d[12 + 16 * blk] + 0x6ed9eba1), 15);
A = rotintlft((A + H(B, C, D) + d[2 + 16 * blk] + 0x6ed9eba1), 3);
D = rotintlft((D + H(A, B, C) + d[10 + 16 * blk] + 0x6ed9eba1), 9);
C = rotintlft((C + H(D, A, B) + d[6 + 16 * blk] + 0x6ed9eba1), 11);
B = rotintlft((B + H(C, D, A) + d[14 + 16 * blk] + 0x6ed9eba1), 15);
A = rotintlft((A + H(B, C, D) + d[1 + 16 * blk] + 0x6ed9eba1), 3);
D = rotintlft((D + H(A, B, C) + d[9 + 16 * blk] + 0x6ed9eba1), 9);
C = rotintlft((C + H(D, A, B) + d[5 + 16 * blk] + 0x6ed9eba1), 11);
B = rotintlft((B + H(C, D, A) + d[13 + 16 * blk] + 0x6ed9eba1), 15);
A = rotintlft((A + H(B, C, D) + d[3 + 16 * blk] + 0x6ed9eba1), 3);
D = rotintlft((D + H(A, B, C) + d[11 + 16 * blk] + 0x6ed9eba1), 9);
C = rotintlft((C + H(D, A, B) + d[7 + 16 * blk] + 0x6ed9eba1), 11);
B = rotintlft((B + H(C, D, A) + d[15 + 16 * blk] + 0x6ed9eba1), 15);
}
void round4(int blk) {
System.out.println(" must be md5, in round4!");
}
}
class md5 extends md {
md5(String s) {
super(s);
}
md5(byte in[]) {
super(in);
}
static int F(int x, int y, int z) {
return((x & y) | (~x & z));
}
static int G(int x, int y, int z) {
return((x & z) | (y & ~z));
}
static int H(int x, int y, int z) {
return(x ^ y ^ z);
}
static int I(int x, int y, int z) {
return(y ^ (x | ~z));
}
void round1(int blk) {
A = rotintlft(A + F(B, C, D) + d[0 + 16 * blk] +
0xd76aa478, 7) + B;
D = rotintlft(D + F(A, B, C) + d[1 + 16 * blk] +
0xe8c7b756, 12) + A;
C = rotintlft(C + F(D, A, B) + d[2 + 16 * blk] +
0x242070db, 17) + D;
B = rotintlft(B + F(C, D, A) + d[3 + 16 * blk] +
0xc1bdceee, 22) + C;
A = rotintlft(A + F(B, C, D) + d[4 + 16 * blk] +
0xf57c0faf, 7) + B;
D = rotintlft(D + F(A, B, C) + d[5 + 16 * blk] +
0x4787c62a, 12) + A;
C = rotintlft(C + F(D, A, B) + d[6 + 16 * blk] +
0xa8304613, 17) + D;
B = rotintlft(B + F(C, D, A) + d[7 + 16 * blk] +
0xfd469501, 22) + C;
A = rotintlft(A + F(B, C, D) + d[8 + 16 * blk] +
0x698098d8, 7) + B;
D = rotintlft(D + F(A, B, C) + d[9 + 16 * blk] +
0x8b44f7af, 12) + A;
C = rotintlft(C + F(D, A, B) + d[10 + 16 * blk] +
0xffff5bb1, 17) + D;
B = rotintlft(B + F(C, D, A) + d[11 + 16 * blk] +
0x895cd7be, 22) + C;
A = rotintlft(A + F(B, C, D) + d[12 + 16 * blk] +
0x6b901122, 7) + B;
D = rotintlft(D + F(A, B, C) + d[13 + 16 * blk] +
0xfd987193, 12) + A;
C = rotintlft(C + F(D, A, B) + d[14 + 16 * blk] +
0xa679438e, 17) + D;
B = rotintlft(B + F(C, D, A) + d[15 + 16 * blk] +
0x49b40821, 22) + C;
}
void round2(int blk) {
A = rotintlft(A + G(B, C, D) + d[1 + 16 * blk] +
0xf61e2562, 5) + B;
D = rotintlft(D + G(A, B, C) + d[6 + 16 * blk] +
0xc040b340, 9) + A;
C = rotintlft(C + G(D, A, B) + d[11 + 16 * blk] +
0x265e5a51, 14) + D;
B = rotintlft(B + G(C, D, A) + d[0 + 16 * blk] +
0xe9b6c7aa, 20) + C;
A = rotintlft(A + G(B, C, D) + d[5 + 16 * blk] +
0xd62f105d, 5) + B;
D = rotintlft(D + G(A, B, C) + d[10 + 16 * blk] +
0x02441453, 9) + A;
C = rotintlft(C + G(D, A, B) + d[15 + 16 * blk] +
0xd8a1e681, 14) + D;
B = rotintlft(B + G(C, D, A) + d[4 + 16 * blk] +
0xe7d3fbc8, 20) + C;
A = rotintlft(A + G(B, C, D) + d[9 + 16 * blk] +
0x21e1cde6, 5) + B;
D = rotintlft(D + G(A, B, C) + d[14 + 16 * blk] +
0xc33707d6, 9) + A;
C = rotintlft(C + G(D, A, B) + d[3 + 16 * blk] +
0xf4d50d87, 14) + D;
B = rotintlft(B + G(C, D, A) + d[8 + 16 * blk] +
0x455a14ed, 20) + C;
A = rotintlft(A + G(B, C, D) + d[13 + 16 * blk] +
0xa9e3e905, 5) + B;
D = rotintlft(D + G(A, B, C) + d[2 + 16 * blk] +
0xfcefa3f8, 9) + A;
C = rotintlft(C + G(D, A, B) + d[7 + 16 * blk] +
0x676f02d9, 14) + D;
B = rotintlft(B + G(C, D, A) + d[12 + 16 * blk] +
0x8d2a4c8a, 20) + C;
}
void round3(int blk) {
A = rotintlft(A + H(B, C, D) + d[5 + 16 * blk] +
0xfffa3942, 4) + B;
D = rotintlft(D + H(A, B, C) + d[8 + 16 * blk] +
0x8771f681, 11) + A;
C = rotintlft(C + H(D, A, B) + d[11 + 16 * blk] +
0x6d9d6122, 16) + D;
B = rotintlft(B + H(C, D, A) + d[14 + 16 * blk] +
0xfde5380c, 23) + C;
A = rotintlft(A + H(B, C, D) + d[1 + 16 * blk] +
0xa4beea44, 4) + B;
D = rotintlft(D + H(A, B, C) + d[4 + 16 * blk] +
0x4bdecfa9, 11) + A;
C = rotintlft(C + H(D, A, B) + d[7 + 16 * blk] +
0xf6bb4b60, 16) + D;
B = rotintlft(B + H(C, D, A) + d[10 + 16 * blk] +
0xbebfbc70, 23) + C;
A = rotintlft(A + H(B, C, D) + d[13 + 16 * blk] +
0x289b7ec6, 4) + B;
D = rotintlft(D + H(A, B, C) + d[0 + 16 * blk] +
0xeaa127fa, 11) + A;
C = rotintlft(C + H(D, A, B) + d[3 + 16 * blk] +
0xd4ef3085, 16) + D;
B = rotintlft(B + H(C, D, A) + d[6 + 16 * blk] +
0x04881d05, 23) + C;
A = rotintlft(A + H(B, C, D) + d[9 + 16 * blk] +
0xd9d4d039, 4) + B;
D = rotintlft(D + H(A, B, C) + d[12 + 16 * blk] +
0xe6db99e5, 11) + A;
C = rotintlft(C + H(D, A, B) + d[15 + 16 * blk] +
0x1fa27cf8, 16) + D;
B = rotintlft(B + H(C, D, A) + d[2 + 16 * blk] +
0xc4ac5665, 23) + C;
}
void round4(int blk) {
A = rotintlft(A + I(B, C, D) + d[0 + 16 * blk] +
0xf4292244, 6) + B;
D = rotintlft(D + I(A, B, C) + d[7 + 16 * blk] +
0x432aff97, 10) + A;
C = rotintlft(C + I(D, A, B) + d[14 + 16 * blk] +
0xab9423a7, 15) + D;
B = rotintlft(B + I(C, D, A) + d[5 + 16 * blk] +
0xfc93a039, 21) + C;
A = rotintlft(A + I(B, C, D) + d[12 + 16 * blk] +
0x655b59c3, 6) + B;
D = rotintlft(D + I(A, B, C) + d[3 + 16 * blk] +
0x8f0ccc92, 10) + A;
C = rotintlft(C + I(D, A, B) + d[10 + 16 * blk] +
0xffeff47d, 15) + D;
B = rotintlft(B + I(C, D, A) + d[1 + 16 * blk] +
0x85845dd1, 21) + C;
A = rotintlft(A + I(B, C, D) + d[8 + 16 * blk] +
0x6fa87e4f, 6) + B;
D = rotintlft(D + I(A, B, C) + d[15 + 16 * blk] +
0xfe2ce6e0, 10) + A;
C = rotintlft(C + I(D, A, B) + d[6 + 16 * blk] +
0xa3014314, 15) + D;
B = rotintlft(B + I(C, D, A) + d[13 + 16 * blk] +
0x4e0811a1, 21) + C;
A = rotintlft(A + I(B, C, D) + d[4 + 16 * blk] +
0xf7537e82, 6) + B;
D = rotintlft(D + I(A, B, C) + d[11 + 16 * blk] +
0xbd3af235, 10) + A;
C = rotintlft(C + I(D, A, B) + d[2 + 16 * blk] +
0x2ad7d2bb, 15) + D;
B = rotintlft(B + I(C, D, A) + d[9 + 16 * blk] +
0xeb86d391, 21) + C;
}
}
class md {
int A,B,C,D;
int d[];
int numwords;
/* For verification of a modicum of sanity, run a few
* test strings through
*/
public static void main(String argv[]) {
boolean doinmd4;
String mdtype;
/* Test cases, mostly taken from rfc 1320 */
String str[] = { "" , "a", "abc", "message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
"01234567890123456789012345678901234567890123456789012345"};
if (argv.length == 0) {
mdtype = "md4";
doinmd4 = true;
} else if (argv.length > 1) {
System.err.println("Usage: md [4|5|md4|md5]");
return;
} else if ((argv[0].equals("4")) || (argv[0].equals("md4"))) {
mdtype = "md4";
doinmd4 = true;
} else if ((argv[0].equals("5")) || (argv[0].equals("md5"))) {
mdtype = "md5";
doinmd4 = false;
} else {
System.err.println("Usage: md [4|5|md4|md5]");
return;
}
for(int i = 0; i < str.length; i++) {
if (doinmd4) {
md4 mdc = new md4(str[i]);
mdc.calc();
System.out.println(mdtype + "(\"" + str[i] + "\") = " + mdc);
} else {
md5 mdc = new md5(str[i]);
mdc.calc();
System.out.println(mdtype + "(\"" + str[i] + "\") = " + mdc);
}
}
}
md (String s) {
byte in[] = new byte[s.length()];
int i;
for(i=0; i < s.length(); i++) {
in[i] = (byte) (s.charAt(i) & 0xff);
}
mdinit(in);
}
md (byte in[]) {
mdinit(in);
}
void mdinit (byte in[]) {
int newlen, endblklen, pad, i;
long datalenbits;
datalenbits = in.length * 8;
endblklen = in.length % 64;
if (endblklen < 56) {
pad = 64 - endblklen;
} else {
pad = (64 - endblklen) + 64;
}
newlen = in.length + pad;
byte b[] = new byte[newlen];
for(i=0; i < in.length; i++) {
b[i] = in[i];
}
b[in.length] = (byte) 0x80;
for (i = b.length + 1; i < (newlen - 8); i++) {
b[i] = 0;
}
for (i = 0; i < 8; i++) {
b[newlen - 8 + i] = (byte) (datalenbits & 0xff);
datalenbits >>= 8;
}
/* init registers */
A = 0x67452301;
B = 0xefcdab89;
C = 0x98badcfe;
D = 0x10325476;
this.numwords = newlen/4;
this.d = new int[this.numwords];
for (i = 0; i < newlen; i += 4) {
this.d[i/4] = (b[i] & 0xff) + ((b[i+1] & 0xff) << 8) +
((b[i+2] & 0xff) << 16) + ((b[i+3] & 0xff) << 24);
}
}
public String toString() {
String s;
return(tohex(A) + tohex(B) + tohex(C) + tohex(D));
}
int[] getregs() {
int regs[] = {this.A, this.B, this.C, this.D};
return regs;
}
void calc() {
int AA, BB, CC, DD, i;
for(i=0; i < numwords/16; i++) {
AA = A; BB = B; CC = C; DD = D;
round1(i);
round2(i);
round3(i);
if (this instanceof md5) {
round4(i);
}
A += AA; B+= BB; C+= CC; D+= DD;
}
}
/* Dummy round*() methods. these are overriden in the md4 and md5
* subclasses
*/
void round1(int blk) {
System.err.println("Danger! Danger! Someone called md.round1()!");
}
void round2(int blk) {
System.err.println("Danger! Danger! Someone called md.round2()!");
}
void round3(int blk) {
System.err.println("Danger! Danger! Someone called md.round3()!");
}
void round4(int blk) {
System.err.println("Danger! Danger! Someone called md.round4()!");
}
static int rotintlft(int val, int numbits) {
return((val << numbits) | (val >>> (32 - numbits)));
}
static String tohex(int i) {
int b;
String tmpstr;
tmpstr = "";
for(b = 0; b < 4; b++) {
tmpstr += Integer.toString((i >> 4) & 0xf, 16)
+ Integer.toString(i & 0xf, 16);
i >>= 8;
}
return tmpstr;
}
}
| janfrode/j2me-otp | md.java |
1,018 |
import java.net.InetAddress;
import java.net.SocketAddress;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.ServerSocket;
import java.io.OutputStream;
import java.io.InputStream;
import java.io.PrintStream;
/* -- end of imports -- */
import java.io.PrintWriter;
class S3 {
private byte [] HOST;
private byte [] URL;
private int PORT;
private InetAddress Addr;
private byte [] FileName;
private int Offset = 0;
private int Length = 0;
private int IsLocalOrRemote = -1;
//private byte [] remoteURL;
private byte[] httpSuccess = {72, 84, 84, 80, 47, 49, 46, 49, 32, 50, 48, 48, 32, 79, 75};
private byte[] httpBadRequest = {72, 84, 84, 80, 47, 49, 46, 49, 32, 52, 48, 48, 32, 66, 65, 68, 32, 82, 69, 81, 85, 69, 83, 84};
private byte[] allContentType = {67, 111, 110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 42, 47, 42};
private byte[] contentLength = {67, 111, 110, 116, 101, 110, 116, 45, 76, 101, 110, 103, 116, 104, 58, 32};
public static void main(String [] a) {
S3 bucket = new S3(Integer.parseInt("1200"));
bucket.run(0);
}
public S3 (int port) { PORT = port; }
int parse(byte[] buf) {
try{
int j = 0;
int index = 1;
int [] indexes = new int[5];
indexes[0] = 0;
for (int i = 0; i < buf.length; i++) {
if (j == 2){
break;
}
if(buf[i]== 13 && buf[i+1]==10)
{
indexes[index] = i - 1;
index +=1;
indexes[index] = i + 2;
index +=1;
j +=1;
}
}
byte[] requestFirstLine = sliceArray(buf, indexes[0], indexes[1]);
System.out.println(byte2str(requestFirstLine));
byte[] requestSecondLine = sliceArray(buf, indexes[2], indexes[3]);
System.out.println(byte2str(requestSecondLine));
//Check weather request local or remote
if(checkRequestLocalOrRemote(requestFirstLine) == 0){
IsLocalOrRemote = 0;
//Extract FileName
FileName = extractFileName(requestFirstLine);
System.out.println(FileName);
}
else if(checkRequestLocalOrRemote(requestFirstLine) == 1){
//Extract URL
IsLocalOrRemote = 1;
URL = extractUrl(requestFirstLine);
System.out.println(byte2str(URL));
}
else{
IsLocalOrRemote = -1;
}
//Extract Offset o=111 and &&=38
byte [] Offst = extractOffsetOrLength(requestFirstLine, 111, 38);
Offset = Integer.parseInt(byte2str(Offst));
System.out.println(Offset);
//Extract Length l=108 " "= 32
byte [] Len = extractOffsetOrLength(requestFirstLine, 108, 32);
Length = Integer.parseInt(byte2str(Len));
System.out.println(Length);
return 1;
}
catch(Exception e){
System.out.println(e);
return 0;
}
}
int dns(int X) {
//Setting host from URL
int end_index = 0;
for (int i = 0; i < URL.length; i++) {
if(URL[i] == 47){
end_index = i - 1;
break;
}
}
HOST = sliceArray(URL,0,end_index);
System.out.println(byte2str(HOST));
return 0;
}
int run(int X) {
ServerSocket s0 = null;
Socket s1 = null;
byte[] b0 = new byte[1024];
try {
s0 = new ServerSocket(PORT);
while (true) {
s1 = s0.accept();
InputStream inputStream = s1.getInputStream();
inputStream.read(b0);
Offset = Length = 0;
FileName = null;
HOST = null;
IsLocalOrRemote = -1;
if (parse(b0) == 1){
System.out.println("Data parsed... FileName, Offset & Lenght extracted ");
}
else{
System.out.println("Error in parsing data");
}
//Set host
dns(0);
//Handle user request
handleRequest(s1);
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
private void handleRequest(Socket socket) {
try {
OutputStream outputStream = socket.getOutputStream();
if(IsLocalOrRemote == 0){
handleLocalRequest(outputStream);
}
else if(IsLocalOrRemote == 1){
handleRemoteRequest(outputStream);
}
else{
System.out.println("Invalid Request");
}
socket.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void handleLocalRequest(OutputStream outputStream){
try {
PrintStream printStream = new PrintStream(outputStream);
File file = new File(byte2str(FileName));
if (file.exists()) {
FileInputStream fileInputStream = new FileInputStream(file);
byte[] buffer = new byte[1024];
int bytesRead;
if(Offset + Length > file.length() ) {
printStream.println(byte2str(httpBadRequest));
printStream.println(byte2str(allContentType));
String errorMessage = "Invalid Offset or Length or both";
printStream.println(byte2str(contentLength) + errorMessage.length());
printStream.println();
outputStream.write(errorMessage.getBytes());
}
else if(Offset >= 0 && Length > 0 ){
printStream.println(byte2str(httpSuccess));
printStream.println(byte2str(allContentType));
byte[] slicedArray = new byte[Length];
printStream.println(byte2str(contentLength) + slicedArray.length);
printStream.println();
fileInputStream.skip(Offset);
while ((bytesRead = fileInputStream.read(slicedArray)) != -1) {
outputStream.write(slicedArray, 0, bytesRead);
}
}
else{
printStream.println(byte2str(httpSuccess));
printStream.println(byte2str(allContentType));
printStream.println(byte2str(contentLength) + file.length());
printStream.println();
while ((bytesRead = fileInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
fileInputStream.close();
}
} else {
String errorMessage = "File not found";
outputStream.write(errorMessage.getBytes());
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void handleRemoteRequest(OutputStream outputStream) {
try {
PrintStream printStream = new PrintStream(outputStream);
Socket remoteSocket = new Socket(byte2str(HOST),443);
InputStream remoteInputStream = remoteSocket.getInputStream();
printStream.println(byte2str(httpSuccess));
printStream.println(byte2str(allContentType));
printStream.println("GET /wiresharklabs/alice.txt HTTP/1.1");
printStream.println("Host: gaia.cs.umass.edu");
printStream.println("Transfer-Encoding: chunked");
printStream.println();
byte[] buffer = new byte[1024];
int bytesRead;
remoteInputStream.read(buffer);
System.out.println(byte2str(buffer));
remoteSocket.close();
} catch (IOException e) {
System.out.println(e);
System.out.println("-------------------------------------");
e.printStackTrace();
}
}
private byte[] extractUrl(byte[] requestLine){
if(requestLine.length == 0){
return requestLine;
}
int start_index = 0;
int end_index = 0;
int c = 0;
for (int i = 0; i < requestLine.length; i++) {
if(c == 1 && (requestLine[i] == 32 || requestLine[i]==38)){
end_index = i - 1;
break;
}
if(i==requestLine.length){
break;
}
if(requestLine[i]== 104 && requestLine[i+1] == 120 && requestLine[i+2]==58 && requestLine[i+3]==47&&requestLine[i+4]==47){
start_index = i + 5;
c +=1;
}
}
return sliceArray(requestLine,start_index, end_index);
}
private static byte[] extractOffsetOrLength(byte [] requestLine,int a, int b){
if(requestLine.length == 0){return requestLine;}
//Extract Length
int start_index = 0;
int end_index = 0;
int c = 0;
for (int i = 0; i < requestLine.length; i++) {
if(requestLine[i]== a && requestLine[i+1] == 120 && requestLine[i+2] == 61){
start_index = i + 3;
c +=1;
}
if(c == 1 && requestLine[i] == b){
end_index = i - 1;
break;
}
}
return sliceArray(requestLine,start_index, end_index);
}
private static byte[] extractFileName(byte[] requestLine){
if(requestLine.length == 0){
return requestLine;
}
int start_index = 0;
int end_index = 0;
int c = 0;
for (int i = 0; i < requestLine.length; i++) {
if(c == 1 && (requestLine[i] == 32 || requestLine[i]==38)){
end_index = i - 1;
break;
}
if(i==requestLine.length){
break;
}
if(requestLine[i]== 47 && requestLine[i+1] == 47 ){
start_index = i + 2;
c +=1;
}
}
return sliceArray(requestLine,start_index, end_index);
}
private static int checkRequestLocalOrRemote(byte [] b){
for (int i = 0; i < b.length; i++) {
if(b[i] == 47 && b[i+1] == 102 && b[i+2] == 120 && b[i+3] == 58){
System.out.println("Request is local");
return 0;
}
else if(b[i] == 47 && b[i+1] == 104 && b[i+2] == 120 && b[i+3] == 58){
System.out.println("Request is remote");
return 1;
}
}
return -1;
}
private static byte[] sliceArray(byte[] b, int i, int j){
if(b.length == 0){
return b;
}
byte [] slicedArray = new byte[j - i + 1];
int c = 0;
for(int a = i; a <= j; a++){
slicedArray[c] = b[a];
c += 1;
}
return slicedArray;
}
private static String byte2str(byte[] b){return byte2str(b,0,0);}
private static String byte2str(byte[] b, int i, int j) {
if(i == 0 && j == 0){
return new String(b);
}
else{
return new String(sliceArray(b, i, j));
}
}
}
| omkarhadawale/BucketStorageService | S3.java |
1,021 | import java.util.PriorityQueue;
class Hobby {
String name;
int rating;
public Hobby(String name, int rating) {
this.name = name;
this.rating = rating;
}
public String toString() {
return "Name: " + name + ", Rating: " + rating;
}
}
class HobbyComparator implements Comparator<Hobby> {
public int compare(Hobby h1, Hobby h2) {
return h1.rating - h2.rating;
}
}
public class PQ {
public static void main(String[] args) {
PriorityQueue<Hobby> pq2 = new PriorityQueue<Hobby>(new HobbyComparator());
pq2.add(new Hobby("Reading", 10));
pq2.add(new Hobby("Writing", 9));
pq2.add(new Hobby("Coding", 8));
pq2.add(new Hobby("Singing", 7));
System.out.println("Using default comparator:");
for (Hobby h : pq2) {
System.out.println(h);
}
}
}
| rishabhguptajs/JCP | PQ.java |
1,023 | package com.xuhong.smarthome.utils;
import android.util.Log;
/**
* Created by Administrator on 2017/8/16 0016.
*/
public class L {
private static boolean isLog = true;
private static final String TAG = "smarthomeLog";
public static void i(String tag, String msg) {
if (isLog) {
Log.i(tag, msg);
}
}
public static void i(String msg) {
if (isLog) {
Log.i(TAG, msg);
}
}
public static void d(String tag, String msg) {
if (isLog) {
Log.d(tag, msg);
}
}
public static void d(String msg) {
if (isLog) {
Log.d(TAG, msg);
}
}
public static void e(String tag, String msg) {
if (isLog) {
Log.e(tag, msg);
}
}
public static void e(String msg) {
if (isLog) {
Log.e(TAG, msg);
}
}
}
| xuhongv/SmartHome | app/src/main/java/com/xuhong/smarthome/utils/L.java |
1,025 | import java.sql.*;
import java.net.*;
import java.io.*;
import java.util.*;
public class GP
{
private static String myclass = "GP";
public static boolean debug = false;
public static String externalSchema = "ext";
public static String getVersion(Connection conn) throws SQLException
{
String method = "getVersion";
int location = 1000;
try
{
location = 2000;
String value = "";
location = 2100;
Statement stmt = conn.createStatement();
String strSQL = "SELECT CASE " +
"WHEN POSITION ('HAWQ' in version) > 0 THEN 'HAWQ' " +
"WHEN POSITION ('HAWQ' in version) = 0 AND POSITION ('Greenplum Database' IN version) > 0 THEN 'GPDB' " +
"ELSE 'OTHER' END " +
"FROM version()";
if (debug)
Logger.printMsg("Getting Variable: " + strSQL);
location = 2200;
ResultSet rs = stmt.executeQuery(strSQL);
while (rs.next())
{
value = rs.getString(1);
}
location = 2300;
return value;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void customStartAll(Connection conn) throws SQLException
{
String method = "customStartAll";
int location = 1000;
try
{
Statement stmt = conn.createStatement();
int id = 0;
int gpfdistPort = 0;
String strSQL = "SELECT id\n";
strSQL += "FROM os.custom_sql";
ResultSet rs = stmt.executeQuery(strSQL);
while (rs.next())
{
id = rs.getInt(1);
gpfdistPort = GpfdistRunner.customStart(OSProperties.osHome);
strSQL = "INSERT INTO os.ao_custom_sql\n";
strSQL += "(id, table_name, columns, column_datatypes, sql_text, source_type, source_server_name, source_instance_name, source_port, source_database_name, source_user_name, source_pass, gpfdist_port)\n";
strSQL += "SELECT id, table_name, columns, column_datatypes, sql_text, source_type, source_server_name, source_instance_name, source_port, source_database_name, source_user_name, source_pass, " + gpfdistPort + "\n";
strSQL += "FROM os.custom_sql\n";
strSQL += "WHERE id = " + id;
stmt.executeUpdate(strSQL);
}
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void failJobs(Connection conn) throws SQLException
{
String method = "failJobs";
int location = 1000;
try
{
Statement stmt = conn.createStatement();
String strSQL = "INSERT INTO os.ao_queue (queue_id, status, queue_date, start_date, end_date, " +
"error_message, num_rows, id, refresh_type, target_schema_name, target_table_name, target_append_only, " +
"target_compressed, target_row_orientation, source_type, source_server_name, source_instance_name, " +
"source_port, source_database_name, source_schema_name, source_table_name, source_user_name, " +
"source_pass, column_name, sql_text, snapshot) " +
"SELECT queue_id, 'failed' as status, queue_date, start_date, now() as end_date, " +
"'Outsourcer stop requested' as error_message, num_rows, id, refresh_type, target_schema_name, " +
"target_table_name, target_append_only, target_compressed, target_row_orientation, source_type, " +
"source_server_name, source_instance_name, source_port, source_database_name, source_schema_name, " +
"source_table_name, source_user_name, source_pass, column_name, sql_text, snapshot " +
"FROM os.queue WHERE status = 'queued'";
stmt.executeUpdate(strSQL);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void emailAlert(Connection conn, String errorMsg) throws SQLException
{
String method = "emailAlert";
int location = 1000;
try
{
Statement stmt = conn.createStatement();
String strSQL = "SELECT gp_elog('" + errorMsg + "',true)";
ResultSet rs = stmt.executeQuery(strSQL);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void cancelJobs(Connection conn) throws SQLException
{
String method = "cancelJobs";
int location = 1000;
try
{
List<String> jobIdList = new ArrayList<String>();
Statement stmt = conn.createStatement();
String strSQL = "SELECT id FROM os.queue WHERE status = 'processing'";
ResultSet rs = stmt.executeQuery(strSQL);
while (rs.next())
{
jobIdList.add(rs.getString(1));
}
for (String jobId : jobIdList)
{
strSQL = "SELECT os.fn_cancel_job(" + jobId + ")";
rs = stmt.executeQuery(strSQL);
}
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static int executeSQL(Connection conn, String strSQL) throws SQLException
{
String method = "executeSQL";
int location = 1000;
if (strSQL == null)
strSQL = "";
try
{
location = 2000;
int numRows = 0;
location = 2100;
String SQL = "";
location = 2150;
strSQL = strSQL.trim();
location = 2200;
int endPosition = strSQL.indexOf(";");
location = 2300;
Statement stmt = conn.createStatement();
location = 2400;
if (endPosition > -1)
{
location = 2500;
while (endPosition > - 1)
{
location = 2600;
SQL = strSQL.substring(0, endPosition);
if (debug)
Logger.printMsg("Executing sql: " + SQL);
//if select, execute query else execute update
if ( (strSQL.toUpperCase()).startsWith("SELECT") )
{
location = 2700;
stmt.execute(SQL);
}
else
{
location = 2900;
numRows = numRows + stmt.executeUpdate(SQL);
}
location = 3100;
strSQL = strSQL.substring(endPosition + 1).trim();
location = 3200;
endPosition = strSQL.indexOf(";");
}
}
else if (strSQL.length() > 0)
{
location = 4000;
if (debug)
Logger.printMsg("Executing sql: " + SQL);
//if select, execute query else execute update
if ( (strSQL.toUpperCase()).startsWith("SELECT") )
{
location = 4200;
stmt.execute(strSQL);
//discard results
}
else
{
location = 4300;
numRows = stmt.executeUpdate(strSQL);
}
}
location = 5000;
return numRows;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static String getVariable(Connection conn, String name) throws SQLException
{
String method = "getVariable";
int location = 1000;
try
{
location = 2000;
String value = "";
location = 2100;
Statement stmt = conn.createStatement();
String strSQL = "SELECT os.fn_get_variable('" + name + "')";
if (debug)
Logger.printMsg("Getting Variable: " + strSQL);
location = 2200;
ResultSet rs = stmt.executeQuery(strSQL);
while (rs.next())
{
value = rs.getString(1);
}
location = 2300;
return value;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void executeReplication(Connection conn, String targetSchema, String targetTable, String appendColumnName) throws SQLException
{
String method = "executeReplication";
int location = 1000;
try
{
location = 2000;
Statement stmt = conn.createStatement();
location = 2100;
String externalTable = getExternalTableName(targetSchema, targetTable);
location = 2200;
String stageTable = getStageTableName(targetSchema, targetTable);
location = 2301;
String strSQL = "SELECT os.fn_replication('" + targetSchema + "', '" + targetTable + "', '" +
externalSchema + "', '" + stageTable + "', '" +
appendColumnName + "');";
if (debug)
Logger.printMsg("Executing function: " + strSQL);
location = 2400;
stmt.executeQuery(strSQL);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static String setErrorMessage(String errorMessage) throws SQLException
{
String method = "setErrorMessage";
int location = 1000;
try
{
location = 2000;
errorMessage = errorMessage.replace("\"", "");
location = 2200;
errorMessage = errorMessage.replace("'", "");
location = 2302;
errorMessage = errorMessage.replace("\n", " ");
location = 3000;
return errorMessage;
}
catch (Exception ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
private static String setSQLString(boolean columnValue)
{
String strColumnValue = "";
if (columnValue)
strColumnValue = "true";
else
strColumnValue = "false";
return strColumnValue;
}
private static String setSQLString(int columnValue)
{
String strColumnValue = Integer.toString(columnValue);
return strColumnValue;
}
private static String setSQLString(String columnValue)
{
if (columnValue != null)
{
if (columnValue.equals(""))
columnValue = "null::text";
else
{
columnValue = columnValue.replace("'", "''");
columnValue = "'" + columnValue + "'";
}
}
else
columnValue = "null";
return columnValue;
}
public static String setSQLString(Timestamp columnValue)
{
String strColumnValue = "";
if (columnValue != null)
strColumnValue = "'" + columnValue.toString() + "'::timestamp";
else
strColumnValue = "null::timestamp";
return strColumnValue;
}
public static void updateStatus(Connection conn, int queueId, String status, Timestamp queueDate, Timestamp startDate, String errorMessage, int numRows, int id, String refreshType, String targetSchema, String targetTable, boolean targetAppendOnly, boolean targetCompressed, boolean targetRowOrientation, String sourceType, String sourceServer, String sourceInstance, int sourcePort, String sourceDatabase, String sourceSchema, String sourceTable, String sourceUser, String sourcePass, String columnName, String sqlText, boolean snapshot) throws SQLException
{
String method = "updateStatus";
int location = 1000;
String strQueueId = setSQLString(queueId);
status = setSQLString(status);
String strQueueDate = setSQLString(queueDate);
String strStartDate = setSQLString(startDate);
errorMessage = setSQLString(errorMessage);
String strNumRows = setSQLString(numRows);
String strId = setSQLString(id);
refreshType = setSQLString(refreshType);
targetSchema = setSQLString(targetSchema);
targetTable = setSQLString(targetTable);
String strTargetAppendOnly = setSQLString(targetAppendOnly);
String strTargetCompressed = setSQLString(targetCompressed);
String strTargetRowOrientation = setSQLString(targetRowOrientation);
sourceType = setSQLString(sourceType);
sourceServer = setSQLString(sourceServer);
sourceInstance = setSQLString(sourceInstance);
String strSourcePort = setSQLString(sourcePort);
sourceDatabase = setSQLString(sourceDatabase);
sourceSchema = setSQLString(sourceSchema);
sourceTable = setSQLString(sourceTable);
sourceUser = setSQLString(sourceUser);
sourcePass = setSQLString(sourcePass);
columnName = setSQLString(columnName);
sqlText = setSQLString(sqlText);
String strSnapshot = setSQLString(snapshot);
try
{
location = 2000;
Statement stmt = conn.createStatement();
location = 2400;
String strSQL = "SELECT os.fn_update_status(" + strQueueId + ", " + status + ", " + strQueueDate + ", " + strStartDate + ", ";
strSQL += errorMessage + ", " + strNumRows + ", " + strId + ", " + refreshType + ", " + targetSchema + ", " + targetTable + ", ";
strSQL += strTargetAppendOnly + ", " + strTargetCompressed + ", " + strTargetRowOrientation + ", " + sourceType + ", ";
strSQL += sourceServer + ", " + sourceInstance + ", " + strSourcePort + ", " + sourceDatabase + ", " + sourceSchema + ", ";
strSQL += sourceTable + ", " + sourceUser + ", " + sourcePass + ", " + columnName + ", " + sqlText + ", " + strSnapshot + ")";
if (debug)
Logger.printMsg("Updating Status: " + strSQL);
location = 2500;
stmt.executeQuery(strSQL);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void dropExternalReplTable(Connection conn, String sourceType, String targetSchema, String targetTable, String sourceTable) throws SQLException
{
String method = "dropExternalReplTable";
int location = 1000;
try
{
location = 2000;
String replTargetSchema = externalSchema;
location = 2100;
String replTargetTable = getStageTableName(targetSchema, targetTable);
location = 2200;
String replSourceTable = getReplTableName(sourceType, sourceTable);
location = 2315;
dropExternalTable(conn, replTargetSchema, replTargetTable);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void dropExternalTable(Connection conn, String targetSchema, String targetTable) throws SQLException
{
String method = "dropExternalTable";
int location = 1000;
try
{
location = 2000;
String externalTable = getExternalTableName(targetSchema, targetTable);
location = 2100;
Statement stmt = conn.createStatement();
location = 2200;
String strSQL = "DROP EXTERNAL TABLE IF EXISTS \"" + externalSchema + "\".\"" + externalTable + "\"";
if (debug)
Logger.printMsg("Dropping External Table (if exists): " + strSQL);
location = 2303;
stmt.executeUpdate(strSQL);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static int insertTargetTable(Connection conn, String targetSchema, String targetTable) throws SQLException
{
String method = "insertTargetTable";
int location = 1000;
int numRows = 0;
try
{
location = 2000;
String externalTable = getExternalTableName(targetSchema, targetTable);
location = 2100;
Statement stmt = conn.createStatement();
location = 2200;
String strSQL = "INSERT INTO \"" + targetSchema + "\".\"" + targetTable + "\" \n" +
"SELECT * FROM \"" + externalSchema + "\".\"" + externalTable + "\"";
if (debug)
Logger.printMsg("Executing SQL: " + strSQL);
location = 2304;
numRows = stmt.executeUpdate(strSQL);
location = 2400;
return numRows;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static int insertReplTable(Connection conn, String targetSchema, String targetTable) throws SQLException
{
String method = "insertReplTable";
int location = 1000;
int numRows = 0;
try
{
location = 2000;
String replTargetSchema = externalSchema;
location = 2100;
String replTargetTable = getStageTableName(targetSchema, targetTable);
location = 2200;
String externalTable = getExternalTableName(replTargetSchema, replTargetTable);
location = 2305;
//truncate the stage table before loading
truncateTable(conn, replTargetSchema, replTargetTable);
location = 2400;
Statement stmt = conn.createStatement();
location = 2500;
String strSQL = "INSERT INTO \"" + replTargetSchema + "\".\"" + replTargetTable + "\" \n" +
"SELECT * FROM \"" + externalSchema + "\".\"" + externalTable + "\"";
if (debug)
Logger.printMsg("Executing SQL: " + strSQL);
location = 2600;
numRows = stmt.executeUpdate(strSQL);
location = 2700;
return numRows;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void truncateTable(Connection conn, String schema, String table) throws SQLException
{
String method = "truncateTable";
int location = 1000;
try
{
location = 2000;
Statement stmt = conn.createStatement();
location = 2100;
String strSQL = "truncate table \"" + schema + "\".\"" + table + "\"";
if (debug)
Logger.printMsg("Truncating table: " + strSQL);
location = 2200;
stmt.executeUpdate(strSQL);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static boolean createSchema(Connection conn, String schema) throws SQLException
{
String method = "createSchema";
int location = 1000;
try
{
location = 2000;
boolean found = false;
String strSQL = "SELECT COUNT(*) \n" +
"FROM INFORMATION_SCHEMA.SCHEMATA \n" +
"WHERE SCHEMA_NAME = '" + schema + "'";
location = 2100;
Statement stmt = conn.createStatement();
location = 2200;
ResultSet rs = stmt.executeQuery(strSQL);
location = 2306;
while (rs.next())
{
if (rs.getInt(1) > 0)
found = true;
}
location = 2400;
if (!(found))
{
location = 2500;
String schemaDDL = "CREATE SCHEMA \"" + schema + "\"";;
if (debug)
Logger.printMsg("Schema DDL: " + schemaDDL);
location = 2600;
stmt.executeUpdate(schemaDDL);
}
location = 2700;
return found;
}
catch (SQLException ex)
{
return true;
}
}
public static boolean createTargetTable(Connection conn, String targetSchema, String targetTable, boolean targetAppendOnly, boolean targetCompressed, boolean targetRowOrientation, String sourceType, String sourceServer, String sourceInstance, int sourcePort, String sourceDatabase, String sourceSchema, String sourceTable, String sourceUser, String sourcePass) throws Exception
{
String method = "createTargetTable";
int location = 1000;
try
{
location = 2000;
boolean found = false;
String strSQL = "SELECT COUNT(*) \n" +
"FROM INFORMATION_SCHEMA.TABLES \n" +
"WHERE TABLE_SCHEMA = '" + targetSchema + "' \n" +
" AND TABLE_NAME = '" + targetTable + "'";
location = 2100;
Statement stmt = conn.createStatement();
location = 2200;
ResultSet rs = stmt.executeQuery(strSQL);
location = 2307;
while (rs.next())
{
if (rs.getInt(1) > 0)
found = true;
}
location = 2400;
if (!(found))
{
String tableDDL = CommonDB.getGPTableDDL(sourceType, sourceServer, sourceInstance, sourcePort, sourceDatabase, sourceSchema, sourceTable, sourceUser, sourcePass, targetSchema, targetTable, targetAppendOnly, targetCompressed, targetRowOrientation);
if (debug)
Logger.printMsg("Table DDL: " + tableDDL);
location = 2800;
stmt.executeUpdate(tableDDL);
}
location = 3000;
return found;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static String getReplTableName(String sourceType, String sourceTable) throws SQLException
{
String method = "getReplTableName";
int location = 1000;
try
{
location = 2000;
String tableSuffix = "_OS";
int suffixLength = tableSuffix.length();
int maxLength = 0;
String replSourceTable = sourceTable + tableSuffix;
if (sourceType.equals("oracle"))
{
//max length for Oracle is 30 bytes
//triggers created are t_<tablename><suffix>_aiud which add 7 characters
//make the max length 23 + suffix so that this output can be used for triggers too
maxLength = 23 - suffixLength;
} else if (sourceType.equals("sqlserver"))
{
//max length for SQL Server is 128 characters
//triggers created are t_<tablename><suffix>_i which add 4 characters
//make the max length 124 + suffix so that this output can be used for triggers too
maxLength = 124 - suffixLength;
}
if (sourceTable.length() > maxLength)
{
replSourceTable = sourceTable.substring(0, maxLength) + tableSuffix;
}
return replSourceTable;
}
catch (Exception ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void createReplExternalTable(Connection conn, String osServer, String refreshType, String targetSchema, String targetTable, String sourceType, String sourceTable, String maxId, int queueId, int jobPort) throws SQLException
{
String method = "createReplExternalTable";
int location = 1000;
try
{
location = 2000;
String replTargetSchema = externalSchema;
location = 2100;
String replTargetTable = getStageTableName(targetSchema, targetTable);
location = 2200;
String replSourceTable = getReplTableName(sourceType, sourceTable);
location = 2308;
createExternalTable(conn, osServer, refreshType, replSourceTable, replTargetSchema, replTargetTable, maxId, queueId, jobPort);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void createExternalTable(Connection conn, String osServer, String refreshType, String sourceTable, String targetSchema, String targetTable, String maxId, int queueId, int jobPort) throws SQLException
{
String method = "createExternalTable";
int location = 1000;
try
{
location = 2000;
String externalTable = getExternalTableName(targetSchema, targetTable);
location = 2100;
Statement stmt = conn.createStatement();
String createSQL = "CREATE EXTERNAL TABLE \"" + externalSchema + "\".\"" + externalTable + "\" \n (";
location = 2309;
String strSQL = "SELECT c.column_name, \n" +
" CASE WHEN c.data_type = 'character' THEN c.data_type || '(' || c.character_maximum_length || ')' ELSE c.data_type END AS data_type \n" +
"FROM INFORMATION_SCHEMA.COLUMNS c \n" +
"WHERE table_schema = '" + targetSchema + "' \n" +
" AND table_name = '" + targetTable + "' \n" +
"ORDER BY ordinal_position";
location = 2400;
ResultSet rs = stmt.executeQuery(strSQL);
location = 2500;
while (rs.next())
{
location = 2600;
if (rs.getRow() == 1)
{
location = 2700;
createSQL = createSQL + "\"" + rs.getString(1) + "\" " + rs.getString(2);
}
else
{
location = 2800;
createSQL = createSQL + ", \n \"" + rs.getString(1) + "\" " + rs.getString(2);
}
}
location = 2900;
createSQL = createSQL + ") \n";
////////////////////////////////////////////
//Create location for External Table
////////////////////////////////////////////
location = 3000;
//replace space in the maxId because this could now be a date
maxId = maxId.replace(" ", "SPACE");
location = 3100;
String extLocation = "LOCATION ('gpfdist://" + osServer + ":" + jobPort +
"/config.properties+" + queueId + "+" + maxId + "+" + refreshType + "+" + sourceTable + "#transform=externaldata" + "')";
location = 3400;
extLocation = extLocation + "\n" + "FORMAT 'TEXT' (delimiter '|' null 'null')";
////////////////////////////////////////////
//Add createSQL with Java Command to exec.
////////////////////////////////////////////
location = 3500;
createSQL = createSQL + extLocation;
////////////////////////////////////////////
//Create new external web table
////////////////////////////////////////////
location = 4000;
if (debug)
Logger.printMsg("Creating External Table: " + createSQL);
stmt.executeUpdate(createSQL);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
catch (Exception e)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + e.getMessage() + ")");
}
}
private static String getExternalTableName(String targetSchema, String targetTable) throws SQLException
{
String method = "getExternalTableName";
int location = 1000;
try
{
location = 2000;
String returnString = targetSchema + "_" + targetTable;
return returnString;
}
catch (Exception ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
private static String getArchTableName(String targetSchema, String targetTable) throws SQLException
{
String method = "getArchTableName";
int location = 1000;
try
{
location = 2000;
String returnString = targetSchema + "_" + targetTable + "_arch";;
return returnString;
}
catch (Exception ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
private static String getStageTableName(String targetSchema, String targetTable) throws SQLException
{
String method = "getStageTableName";
int location = 1000;
try
{
location = 2000;
String returnString = targetSchema + "_" + targetTable + "_stage";;
return returnString;
}
catch (Exception ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static boolean checkStageTable(Connection conn, String targetSchema, String targetTable) throws SQLException
{
String method = "checkStageTable";
int location = 1000;
try
{
location = 2000;
boolean found = false;
String stageTable = getStageTableName(targetSchema, targetTable);
location = 2100;
String strSQL = "SELECT NULL \n" +
"FROM INFORMATION_SCHEMA.TABLES \n" +
"WHERE table_schema = '" + externalSchema + "' \n" +
" AND table_name = '" + stageTable + "'";
if (debug)
Logger.printMsg("Executing sql: " + strSQL);
location = 2200;
Statement stmt = conn.createStatement();
location = 2310;
ResultSet rs = stmt.executeQuery(strSQL);
location = 2400;
while (rs.next())
{
found = true;
}
location = 2500;
return found;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static boolean checkArchTable(Connection conn, String targetSchema, String targetTable) throws SQLException
{
String method = "checkArchTable";
int location = 1000;
try
{
location = 2000;
boolean found = false;
String archTable = getArchTableName(targetSchema, targetTable);
location = 2100;
String strSQL = "SELECT NULL \n" +
"FROM INFORMATION_SCHEMA.TABLES \n" +
"WHERE table_schema = '" + externalSchema + "' \n" +
" AND table_name = '" + archTable + "'";
if (debug)
Logger.printMsg("Executing sql: " + strSQL);
location = 2200;
Statement stmt = conn.createStatement();
location = 2311;
ResultSet rs = stmt.executeQuery(strSQL);
location = 2400;
while (rs.next())
{
found = true;
}
location = 2500;
return found;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static void setupReplicationTables(Connection conn, String targetSchema, String targetTable, String columnName) throws SQLException
{
String method = "setupReplicationTables";
int location = 1000;
try
{
location = 2000;
String archTable = getArchTableName(targetSchema, targetTable);
location = 2100;
String stageTable = getStageTableName(targetSchema, targetTable);
location = 2200;
String strSQL = "SELECT os.fn_replication_setup('" + targetSchema + "', '" + targetTable + "', '" +
externalSchema + "', '" + stageTable + "', '" + archTable + "', '" + columnName + "')";
location = 2312;
Statement stmt = conn.createStatement();
location = 2400;
stmt.executeQuery(strSQL);
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static String getMax(Connection conn, String schema, String table, String columnName) throws SQLException
{
String method = "getMax";
int location = 1000;
try
{
location = 2000;
String strSQL = "SELECT MAX(\"" + columnName.toLowerCase() + "\") \n" +
"FROM \"" + schema + "\".\"" + table + "\"";
if (debug)
Logger.printMsg("Executing sql: " + strSQL);
String max = "-1";
location = 2100;
Statement stmt = conn.createStatement();
location = 2200;
ResultSet rs = stmt.executeQuery(strSQL);
while (rs.next())
{
max = rs.getString(1);
}
location = 2313;
if (max == null)
{
max = "-1";
}
return max;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static String getArchMax(Connection conn, String targetSchema, String targetTable, String columnName) throws SQLException
{
String method = "getArchMax";
int location = 1000;
try
{
location = 2000;
String archTable = getArchTableName(targetSchema, targetTable);
location = 2100;
String max = getMax(conn, externalSchema, archTable, columnName);
location = 2200;
return max;
}
catch (SQLException ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static String getQueueDetails(Connection conn, int queueId) throws SQLException
{
String method = "getQueueDetails";
int location = 1000;
String strSQL = "";
try
{
location = 2000;
strSQL = "SELECT refresh_type, source_type, source_server_name, source_instance_name, source_port, source_database_name, " +
"source_schema_name, source_table_name, source_user_name, source_pass, column_name \n" +
"FROM os.queue \n" +
"WHERE queue_id = " + queueId + "\n" +
"AND status = 'processing'";
//added processing check
location = 3000;
return strSQL;
}
catch (Exception ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
public static String getCustomSQLDetails(Connection conn, int customSQLId) throws SQLException
{
String method = "getCustomSQLDetails";
int location = 1000;
String strSQL = "";
try
{
location = 2000;
strSQL = "SELECT source_type, source_server_name, source_instance_name, source_port, \n" +
" source_database_name, source_user_name, source_pass, sql_text \n" +
"FROM os.custom_sql \n" +
"WHERE id = " + customSQLId;
location = 3000;
return strSQL;
}
catch (Exception ex)
{
throw new SQLException("(" + myclass + ":" + method + ":" + location + ":" + ex.getMessage() + ")");
}
}
}
| RunningJon/outsourcer | GP.java |
1,029 | import java.util.concurrent.BlockingQueue;
import java.io.*;
/**
* A class that represents a ls command object that extends Filter class and
* that contains main functionality of ls command.
* @author michaelroytman
*/
public class Ls extends Filter {
private int counter; //count of how many files have been sent to output queue
File location; //current working directory
String[] filesAndDirs; //an array of Strings representing the files and directories in the
//in the current working directory
/**
* Constructor for Ls object, which takes input and output BlockingQueues, and a String representing the current directory
* @param in input BlockingQueue from which Ls takes input
* @param out output BlockingQueue to which Ls sends output
* @param currentDir String representing the current directory
*/
public Ls(BlockingQueue<Object> out, CurrentDir dir) {
super(null, out); //calls super constructor of Filter class; no input queue
counter = 0;
location = new File(dir.getDir()); //creates a file object in the current working directory
filesAndDirs = location.list(); //creates an array of Strings representing the files and directories in location
}
/**
* @overrun
* Transform method that sends String representation of files and
* directories in the location one by one; returns an EndOfFileMarker
* to signal end of output otherwise.
* @return Object o is a file in the current directory
*/
public Object transform(Object o) {
//if there are still files/directories not sent to output queue
if (counter < filesAndDirs.length) {
o = filesAndDirs[counter];
counter++;
return o;
}
//all files/directories sent to output queue
else {
this.done = true; //end of loop
return new EndOfFileMarker(); //signals end of output
}
}
}
| MichaelRoytman/UnixShell | Ls.java |
1,030 | import java.util.Random;
import java.util.UUID;
public class ze
extends ro
implements ahf, zd
{
private static final ke<Integer> bw = kh.a(ze.class, kg.b);
private int bx;
private boolean by;
private boolean bz;
vp bv;
private zj bA;
private ahh bB;
private int bC;
private boolean bD;
private boolean bE;
private int bF;
private String bG;
private int bH;
private int bI;
private boolean bJ;
private boolean bK;
private qv bL = new qv("Items", false, 8);
public ze(aht β)
{
this(β, 0);
}
public ze(aht β, int β)
{
super(β);
l(β);
a(0.6F, 1.95F);
((ve)x()).a(true);
l(true);
}
protected void r()
{
this.bp.a(0, new th(this));
this.bp.a(1, new ta(this, za.class, 8.0F, 0.6D, 0.6D));
this.bp.a(1, new uq(this));
this.bp.a(1, new tq(this));
this.bp.a(2, new tt(this));
this.bp.a(3, new uj(this));
this.bp.a(4, new ub(this, true));
this.bp.a(5, new tw(this, 0.6D));
this.bp.a(6, new tr(this));
this.bp.a(7, new uo(this));
this.bp.a(9, new tn(this, zj.class, 3.0F, 1.0F));
this.bp.a(9, new ur(this));
this.bp.a(9, new ug(this, 0.6D));
this.bp.a(10, new tp(this, sb.class, 8.0F));
}
private void dj()
{
if (this.bK) {
return;
}
this.bK = true;
if (m_()) {
this.bp.a(8, new ud(this, 0.32D));
} else if (cZ() == 0) {
this.bp.a(6, new tm(this, 0.6D));
}
}
protected void o()
{
if (cZ() == 0) {
this.bp.a(8, new tm(this, 0.6D));
}
super.o();
}
protected void bA()
{
super.bA();
a(yt.d).a(0.5D);
}
protected void M()
{
if (--this.bx <= 0)
{
cj β = new cj(this);
this.l.ai().a(β);
this.bx = (70 + this.S.nextInt(50));
this.bv = this.l.ai().a(β, 32);
if (this.bv == null)
{
cX();
}
else
{
cj β = this.bv.a();
a(β, this.bv.b());
if (this.bJ)
{
this.bJ = false;
this.bv.b(5);
}
}
}
if ((!dc()) && (this.bC > 0))
{
this.bC -= 1;
if (this.bC <= 0)
{
if (this.bD)
{
for (ahg β : this.bB) {
if (β.h()) {
β.a(this.S.nextInt(6) + this.S.nextInt(6) + 2);
}
}
dk();
this.bD = false;
if ((this.bv != null) && (this.bG != null))
{
this.l.a(this, (byte)14);
this.bv.a(this.bG, 1);
}
}
c(new rl(rm.j, 200, 0));
}
}
super.M();
}
public boolean a(zj β, qm β, adq β)
{
boolean β = (β != null) && (β.b() == ads.bT);
if ((!β) && (au()) && (!dc()) && (!m_()))
{
if ((!this.l.E) && ((this.bB == null) || (!this.bB.isEmpty())))
{
a_(β);
β.a(this);
}
β.b(nt.H);
return true;
}
return super.a(β, β, β);
}
protected void i()
{
super.i();
this.Z.a(bw, Integer.valueOf(0));
}
public void b(dn β)
{
super.b(β);
β.a("Profession", cZ());
β.a("Riches", this.bF);
β.a("Career", this.bH);
β.a("CareerLevel", this.bI);
β.a("Willing", this.bE);
if (this.bB != null) {
β.a("Offers", this.bB.a());
}
du β = new du();
for (int β = 0; β < this.bL.u_(); β++)
{
adq β = this.bL.a(β);
if (β != null) {
β.a(β.b(new dn()));
}
}
β.a("Inventory", β);
}
public void a(dn β)
{
super.a(β);
l(β.h("Profession"));
this.bF = β.h("Riches");
this.bH = β.h("Career");
this.bI = β.h("CareerLevel");
this.bE = β.p("Willing");
if (β.b("Offers", 10))
{
dn β = β.o("Offers");
this.bB = new ahh(β);
}
du β = β.c("Inventory", 10);
for (int β = 0; β < β.c(); β++)
{
adq β = adq.a(β.b(β));
if (β != null) {
this.bL.a(β);
}
}
l(true);
dj();
}
protected boolean K()
{
return false;
}
protected nf G()
{
if (dc()) {
return ng.gt;
}
return ng.gp;
}
protected nf bR()
{
return ng.gr;
}
protected nf bS()
{
return ng.gq;
}
public void l(int β)
{
this.Z.b(bw, Integer.valueOf(β));
}
public int cZ()
{
return Math.max(((Integer)this.Z.a(bw)).intValue() % 5, 0);
}
public boolean da()
{
return this.by;
}
public void o(boolean β)
{
this.by = β;
}
public void p(boolean β)
{
this.bz = β;
}
public boolean db()
{
return this.bz;
}
public void a(sa β)
{
super.a(β);
if ((this.bv != null) && (β != null))
{
this.bv.a(β);
if ((β instanceof zj))
{
int β = -1;
if (m_()) {
β = -3;
}
this.bv.a(β.h_(), β);
if (au()) {
this.l.a(this, (byte)13);
}
}
}
}
public void a(rc β)
{
if (this.bv != null)
{
rr β = β.j();
if (β != null)
{
if ((β instanceof zj)) {
this.bv.a(β.h_(), -2);
} else if ((β instanceof yl)) {
this.bv.h();
}
}
else
{
zj β = this.l.a(this, 16.0D);
if (β != null) {
this.bv.h();
}
}
}
super.a(β);
}
public void a_(zj β)
{
this.bA = β;
}
public zj t_()
{
return this.bA;
}
public boolean dc()
{
return this.bA != null;
}
public boolean q(boolean β)
{
if ((!this.bE) && (β) && (df()))
{
boolean β = false;
for (int β = 0; β < this.bL.u_(); β++)
{
adq β = this.bL.a(β);
if (β != null) {
if ((β.b() == ads.R) && (β.b >= 3))
{
β = true;
this.bL.a(β, 3);
}
else if (((β.b() == ads.cc) || (β.b() == ads.cb)) && (β.b >= 12))
{
β = true;
this.bL.a(β, 12);
}
}
if (β)
{
this.l.a(this, (byte)18);
this.bE = true;
break;
}
}
}
return this.bE;
}
public void r(boolean β)
{
this.bE = β;
}
public void a(ahg β)
{
β.g();
this.a_ = (-C());
a(ng.gu, cd(), ce());
int β = 3 + this.S.nextInt(4);
if ((β.e() == 1) || (this.S.nextInt(5) == 0))
{
this.bC = 40;
this.bD = true;
this.bE = true;
if (this.bA != null) {
this.bG = this.bA.h_();
} else {
this.bG = null;
}
β += 5;
}
if (β.a().b() == ads.bY) {
this.bF += β.a().b;
}
if (β.j()) {
this.l.a(new rx(this.l, this.p, this.q + 0.5D, this.r, β));
}
}
public void a(adq β)
{
if ((!this.l.E) && (this.a_ > -C() + 20))
{
this.a_ = (-C());
if (β != null) {
a(ng.gu, cd(), ce());
} else {
a(ng.gs, cd(), ce());
}
}
}
public ahh b_(zj β)
{
if (this.bB == null) {
dk();
}
return this.bB;
}
private void dk()
{
ze.f[][][] β = bM[cZ()];
if ((this.bH == 0) || (this.bI == 0))
{
this.bH = (this.S.nextInt(β.length) + 1);
this.bI = 1;
}
else
{
this.bI += 1;
}
if (this.bB == null) {
this.bB = new ahh();
}
int β = this.bH - 1;
int β = this.bI - 1;
ze.f[][] β = β[β];
if ((β >= 0) && (β < β.length))
{
ze.f[] β = β[β];
for (ze.f β : β) {
β.a(this.bB, this.S);
}
}
}
public void a(ahh β) {}
public eu i_()
{
bbr β = aO();
String β = bf();
if ((β != null) && (!β.isEmpty()))
{
fa β = new fa(bbm.a(β, β));
β.b().a(bk());
β.b().a(bc().toString());
return β;
}
if (this.bB == null) {
dk();
}
String β = null;
switch (cZ())
{
case 0:
if (this.bH == 1) {
β = "farmer";
} else if (this.bH == 2) {
β = "fisherman";
} else if (this.bH == 3) {
β = "shepherd";
} else if (this.bH == 4) {
β = "fletcher";
}
break;
case 1:
β = "librarian";
break;
case 2:
β = "cleric";
break;
case 3:
if (this.bH == 1) {
β = "armor";
} else if (this.bH == 2) {
β = "weapon";
} else if (this.bH == 3) {
β = "tool";
}
break;
case 4:
if (this.bH == 1) {
β = "butcher";
} else if (this.bH == 2) {
β = "leather";
}
break;
}
if (β != null)
{
fb β = new fb("entity.Villager." + β, new Object[0]);
β.b().a(bk());
β.b().a(bc().toString());
if (β != null) {
β.b().a(β.m());
}
return β;
}
return super.i_();
}
public float bn()
{
if (m_()) {
return 0.81F;
}
return 1.62F;
}
private static final ze.f[][][][] bM = { { { { new ze.a(ads.Q, new ze.g(18, 22)), new ze.a(ads.cc, new ze.g(15, 19)), new ze.a(ads.cb, new ze.g(15, 19)), new ze.e(ads.R, new ze.g(-4, -2)) }, { new ze.a(ado.a(aju.aU), new ze.g(8, 13)), new ze.e(ads.ck, new ze.g(-3, -2)) }, { new ze.a(ado.a(aju.bk), new ze.g(7, 12)), new ze.e(ads.e, new ze.g(-5, -7)) }, { new ze.e(ads.bj, new ze.g(-6, -10)), new ze.e(ads.bg, new ze.g(1, 1)) } }, { { new ze.a(ads.H, new ze.g(15, 20)), new ze.a(ads.j, new ze.g(16, 24)), new ze.d(ads.bb, new ze.g(6, 6), ads.bc, new ze.g(6, 6)) }, { new ze.c(ads.aY, new ze.g(7, 8)) } }, { { new ze.a(ado.a(aju.L), new ze.g(16, 22)), new ze.e(ads.bl, new ze.g(3, 4)) }, { new ze.e(new adq(ado.a(aju.L)), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 1), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 2), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 3), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 4), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 5), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 6), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 7), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 8), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 9), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 10), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 11), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 12), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 13), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 14), new ze.g(1, 2)), new ze.e(new adq(ado.a(aju.L), 1, 15), new ze.g(1, 2)) } }, { { new ze.a(ads.H, new ze.g(15, 20)), new ze.e(ads.g, new ze.g(-12, -8)) }, { new ze.e(ads.f, new ze.g(2, 3)), new ze.d(ado.a(aju.n), new ze.g(10, 10), ads.am, new ze.g(6, 10)) } } }, { { { new ze.a(ads.aR, new ze.g(24, 36)), new ze.b() }, { new ze.a(ads.aS, new ze.g(8, 10)), new ze.e(ads.aX, new ze.g(10, 12)), new ze.e(ado.a(aju.X), new ze.g(3, 4)) }, { new ze.a(ads.bX, new ze.g(2, 2)), new ze.e(ads.aZ, new ze.g(10, 12)), new ze.e(ado.a(aju.w), new ze.g(-5, -3)) }, { new ze.b() }, { new ze.b() }, { new ze.e(ads.cy, new ze.g(20, 22)) } } }, { { { new ze.a(ads.bA, new ze.g(36, 40)), new ze.a(ads.m, new ze.g(8, 10)) }, { new ze.e(ads.aE, new ze.g(-4, -1)), new ze.e(new adq(ads.bd, 1, act.l.b()), new ze.g(-2, -1)) }, { new ze.e(ads.bB, new ze.g(4, 7)), new ze.e(ado.a(aju.aX), new ze.g(-3, -1)) }, { new ze.e(ads.bU, new ze.g(3, 11)) } } }, { { { new ze.a(ads.j, new ze.g(16, 24)), new ze.e(ads.aa, new ze.g(4, 6)) }, { new ze.a(ads.l, new ze.g(7, 9)), new ze.e(ads.ab, new ze.g(10, 14)) }, { new ze.a(ads.k, new ze.g(3, 4)), new ze.c(ads.af, new ze.g(16, 19)) }, { new ze.e(ads.Z, new ze.g(5, 7)), new ze.e(ads.Y, new ze.g(9, 11)), new ze.e(ads.W, new ze.g(5, 7)), new ze.e(ads.X, new ze.g(11, 15)) } }, { { new ze.a(ads.j, new ze.g(16, 24)), new ze.e(ads.c, new ze.g(6, 8)) }, { new ze.a(ads.l, new ze.g(7, 9)), new ze.c(ads.n, new ze.g(9, 10)) }, { new ze.a(ads.k, new ze.g(3, 4)), new ze.c(ads.w, new ze.g(12, 15)), new ze.c(ads.z, new ze.g(9, 12)) } }, { { new ze.a(ads.j, new ze.g(16, 24)), new ze.c(ads.a, new ze.g(5, 7)) }, { new ze.a(ads.l, new ze.g(7, 9)), new ze.c(ads.b, new ze.g(9, 11)) }, { new ze.a(ads.k, new ze.g(3, 4)), new ze.c(ads.y, new ze.g(12, 15)) } } }, { { { new ze.a(ads.an, new ze.g(14, 18)), new ze.a(ads.br, new ze.g(14, 18)) }, { new ze.a(ads.j, new ze.g(16, 24)), new ze.e(ads.ao, new ze.g(-7, -5)), new ze.e(ads.bs, new ze.g(-8, -6)) } }, { { new ze.a(ads.aM, new ze.g(9, 12)), new ze.e(ads.U, new ze.g(2, 4)) }, { new ze.c(ads.T, new ze.g(7, 12)) }, { new ze.e(ads.aC, new ze.g(8, 10)) } } } };
static class g
extends ou<Integer, Integer>
{
public g(int β, int β)
{
super(Integer.valueOf(β));
}
public int a(Random β)
{
if (((Integer)a()).intValue() >= ((Integer)b()).intValue()) {
return ((Integer)a()).intValue();
}
return ((Integer)a()).intValue() + β.nextInt(((Integer)b()).intValue() - ((Integer)a()).intValue() + 1);
}
}
static abstract interface f
{
public abstract void a(ahh paramahh, Random paramRandom);
}
static class a
implements ze.f
{
public ado a;
public ze.g b;
public a(ado β, ze.g β)
{
this.a = β;
this.b = β;
}
public void a(ahh β, Random β)
{
int β = 1;
if (this.b != null) {
β = this.b.a(β);
}
β.add(new ahg(new adq(this.a, β, 0), ads.bY));
}
}
static class e
implements ze.f
{
public adq a;
public ze.g b;
public e(ado β, ze.g β)
{
this.a = new adq(β);
this.b = β;
}
public e(adq β, ze.g β)
{
this.a = β;
this.b = β;
}
public void a(ahh β, Random β)
{
int β = 1;
if (this.b != null) {
β = this.b.a(β);
}
adq β;
adq β;
adq β;
if (β < 0)
{
adq β = new adq(ads.bY);
β = new adq(this.a.b(), -β, this.a.i());
}
else
{
β = new adq(ads.bY, β, 0);
β = new adq(this.a.b(), 1, this.a.i());
}
β.add(new ahg(β, β));
}
}
static class c
implements ze.f
{
public adq a;
public ze.g b;
public c(ado β, ze.g β)
{
this.a = new adq(β);
this.b = β;
}
public void a(ahh β, Random β)
{
int β = 1;
if (this.b != null) {
β = this.b.a(β);
}
adq β = new adq(ads.bY, β, 0);
adq β = new adq(this.a.b(), 1, this.a.i());
β = ago.a(β, β, 5 + β.nextInt(15), false);
β.add(new ahg(β, β));
}
}
static class b
implements ze.f
{
public void a(ahh β, Random β)
{
agm β = (agm)agm.b.a(β);
int β = on.a(β, β.d(), β.b());
adq β = ads.cn.a(new agp(β, β));
int β = 2 + β.nextInt(5 + β * 10) + 3 * β;
if (β.e()) {
β *= 2;
}
if (β > 64) {
β = 64;
}
β.add(new ahg(new adq(ads.aS), new adq(ads.bY, β), β));
}
}
static class d
implements ze.f
{
public adq a;
public ze.g b;
public adq c;
public ze.g d;
public d(ado β, ze.g β, ado β, ze.g β)
{
this.a = new adq(β);
this.b = β;
this.c = new adq(β);
this.d = β;
}
public void a(ahh β, Random β)
{
int β = 1;
if (this.b != null) {
β = this.b.a(β);
}
int β = 1;
if (this.d != null) {
β = this.d.a(β);
}
β.add(new ahg(new adq(this.a.b(), β, this.a.i()), new adq(ads.bY), new adq(this.c.b(), β, this.c.i())));
}
}
public void a(byte β)
{
if (β == 12) {
a(cy.I);
} else if (β == 13) {
a(cy.u);
} else if (β == 14) {
a(cy.v);
} else {
super.a(β);
}
}
private void a(cy β)
{
for (int β = 0; β < 5; β++)
{
double β = this.S.nextGaussian() * 0.02D;
double β = this.S.nextGaussian() * 0.02D;
double β = this.S.nextGaussian() * 0.02D;
this.l.a(β, this.p + this.S.nextFloat() * this.G * 2.0F - this.G, this.q + 1.0D + this.S.nextFloat() * this.H, this.r + this.S.nextFloat() * this.G * 2.0F - this.G, β, β, β, new int[0]);
}
}
public sd a(ql β, sd β)
{
β = super.a(β, β);
l(this.l.r.nextInt(5));
dj();
return β;
}
public void dd()
{
this.bJ = true;
}
public ze b(ro β)
{
ze β = new ze(this.l);
β.a(this.l.D(new cj(β)), null);
return β;
}
public boolean a(zj β)
{
return false;
}
public void a(ya β)
{
if ((this.l.E) || (this.F)) {
return;
}
yz β = new yz(this.l);
β.b(this.p, this.q, this.r, this.v, this.w);
β.a(this.l.D(new cj(β)), null);
β.m(cR());
if (o_())
{
β.c(bf());
β.i(bg());
}
this.l.a(β);
T();
}
public qv de()
{
return this.bL;
}
protected void a(yd β)
{
adq β = β.k();
ado β = β.b();
if (a(β))
{
adq β = this.bL.a(β);
if (β == null) {
β.T();
} else {
β.b = β.b;
}
}
}
private boolean a(ado β)
{
return (β == ads.R) || (β == ads.cc) || (β == ads.cb) || (β == ads.Q) || (β == ads.P) || (β == ads.cV) || (β == ads.cU);
}
public boolean df()
{
return m(1);
}
public boolean dg()
{
return m(2);
}
public boolean dh()
{
boolean β = cZ() == 0;
if (β) {
return !m(5);
}
return !m(1);
}
private boolean m(int β)
{
boolean β = cZ() == 0;
for (int β = 0; β < this.bL.u_(); β++)
{
adq β = this.bL.a(β);
if (β != null)
{
if (((β.b() == ads.R) && (β.b >= 3 * β)) || ((β.b() == ads.cc) && (β.b >= 12 * β)) || ((β.b() == ads.cb) && (β.b >= 12 * β)) || ((β.b() == ads.cV) && (β.b >= 12 * β))) {
return true;
}
if ((β) &&
(β.b() == ads.Q) && (β.b >= 9 * β)) {
return true;
}
}
}
return false;
}
public boolean di()
{
for (int β = 0; β < this.bL.u_(); β++)
{
adq β = this.bL.a(β);
if ((β != null) && (
(β.b() == ads.P) || (β.b() == ads.cc) || (β.b() == ads.cb) || (β.b() == ads.cU))) {
return true;
}
}
return false;
}
public boolean c(int β, adq β)
{
if (super.c(β, β)) {
return true;
}
int β = β - 300;
if ((β >= 0) && (β < this.bL.u_()))
{
this.bL.a(β, β);
return true;
}
return false;
}
}
| MCLabyMod/LabyMod-1.9 | ze.java |
1,031 | import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import java.util.List;
import java.util.Random;
public class xo
extends yq
implements ys
{
private static final ke<Integer> a = kh.a(xo.class, kg.b);
private static final ke<Integer> b = kh.a(xo.class, kg.b);
private static final ke<Integer> c = kh.a(xo.class, kg.b);
private static final ke<Integer>[] bv = { a, b, c };
private static final ke<Integer> bw = kh.a(xo.class, kg.b);
private float[] bx = new float[2];
private float[] by = new float[2];
private float[] bz = new float[2];
private float[] bA = new float[2];
private int[] bB = new int[2];
private int[] bC = new int[2];
private int bD;
private final ln bE = (ln)new ln(i_(), qe.a.f, qe.b.a).a(true);
private static final Predicate<rr> bF = new Predicate()
{
public boolean a(rr β)
{
return ((β instanceof sa)) && (((sa)β).ca() != sf.b);
}
};
public xo(aht β)
{
super(β);
c(bW());
a(0.9F, 3.5F);
this.Y = true;
((ve)x()).c(true);
this.b_ = 50;
}
protected void r()
{
this.bp.a(0, new xo.a());
this.bp.a(1, new th(this));
this.bp.a(2, new uh(this, 1.0D, 40, 20.0F));
this.bp.a(5, new ug(this, 1.0D));
this.bp.a(6, new tp(this, zj.class, 8.0F));
this.bp.a(7, new uf(this));
this.bq.a(1, new uv(this, false, new Class[0]));
this.bq.a(2, new uy(this, sb.class, 0, false, false, bF));
}
protected void i()
{
super.i();
this.Z.a(a, Integer.valueOf(0));
this.Z.a(b, Integer.valueOf(0));
this.Z.a(c, Integer.valueOf(0));
this.Z.a(bw, Integer.valueOf(0));
}
public void b(dn β)
{
super.b(β);
β.a("Invul", cZ());
}
public void a(dn β)
{
super.a(β);
l(β.h("Invul"));
}
protected nf G()
{
return ng.gE;
}
protected nf bR()
{
return ng.gH;
}
protected nf bS()
{
return ng.gG;
}
public void n()
{
this.t *= 0.6000000238418579D;
if ((!this.l.E) && (m(0) > 0))
{
rr β = this.l.a(m(0));
if (β != null)
{
if ((this.q < β.q) || ((!da()) && (this.q < β.q + 5.0D)))
{
if (this.t < 0.0D) {
this.t = 0.0D;
}
this.t += (0.5D - this.t) * 0.6000000238418579D;
}
double β = β.p - this.p;
double β = β.r - this.r;
double β = β * β + β * β;
if (β > 9.0D)
{
double β = on.a(β);
this.s += (β / β * 0.5D - this.s) * 0.6000000238418579D;
this.u += (β / β * 0.5D - this.u) * 0.6000000238418579D;
}
}
}
if (this.s * this.s + this.u * this.u > 0.05000000074505806D) {
this.v = ((float)on.b(this.u, this.s) * 57.295776F - 90.0F);
}
super.n();
for (int β = 0; β < 2; β++)
{
this.bA[β] = this.by[β];
this.bz[β] = this.bx[β];
}
for (int β = 0; β < 2; β++)
{
int β = m(β + 1);
rr β = null;
if (β > 0) {
β = this.l.a(β);
}
if (β != null)
{
double β = n(β + 1);
double β = o(β + 1);
double β = p(β + 1);
double β = β.p - β;
double β = β.q + β.bn() - β;
double β = β.r - β;
double β = on.a(β * β + β * β);
float β = (float)(on.b(β, β) * 57.2957763671875D) - 90.0F;
float β = (float)-(on.b(β, β) * 57.2957763671875D);
this.bx[β] = b(this.bx[β], β, 40.0F);
this.by[β] = b(this.by[β], β, 10.0F);
}
else
{
this.by[β] = b(this.by[β], this.aM, 10.0F);
}
}
boolean β = da();
for (int β = 0; β < 3; β++)
{
double β = n(β);
double β = o(β);
double β = p(β);
this.l.a(cy.l, β + this.S.nextGaussian() * 0.30000001192092896D, β + this.S.nextGaussian() * 0.30000001192092896D, β + this.S.nextGaussian() * 0.30000001192092896D, 0.0D, 0.0D, 0.0D, new int[0]);
if ((β) && (this.l.r.nextInt(4) == 0)) {
this.l.a(cy.p, β + this.S.nextGaussian() * 0.30000001192092896D, β + this.S.nextGaussian() * 0.30000001192092896D, β + this.S.nextGaussian() * 0.30000001192092896D, 0.699999988079071D, 0.699999988079071D, 0.5D, new int[0]);
}
}
if (cZ() > 0) {
for (int β = 0; β < 3; β++) {
this.l.a(cy.p, this.p + this.S.nextGaussian(), this.q + this.S.nextFloat() * 3.3F, this.r + this.S.nextGaussian(), 0.699999988079071D, 0.699999988079071D, 0.8999999761581421D, new int[0]);
}
}
}
protected void M()
{
if (cZ() > 0)
{
int β = cZ() - 1;
if (β <= 0)
{
this.l.a(this, this.p, this.q + bn(), this.r, 7.0F, false, this.l.U().b("mobGriefing"));
this.l.a(1023, new cj(this), 0);
}
l(β);
if (this.T % 10 == 0) {
b(10.0F);
}
return;
}
super.M();
for (int β = 1; β < 3; β++) {
if (this.T >= this.bB[(β - 1)])
{
this.bB[(β - 1)] = (this.T + 10 + this.S.nextInt(10));
if ((this.l.ae() == qk.c) || (this.l.ae() == qk.d))
{
int tmp188_187 = (β - 1); int[] tmp188_182 = this.bC; int tmp190_189 = tmp188_182[tmp188_187];tmp188_182[tmp188_187] = (tmp190_189 + 1);
if (tmp190_189 > 15)
{
float β = 10.0F;
float β = 5.0F;
double β = on.a(this.S, this.p - β, this.p + β);
double β = on.a(this.S, this.q - β, this.q + β);
double β = on.a(this.S, this.r - β, this.r + β);
a(β + 1, β, β, β, true);
this.bC[(β - 1)] = 0;
}
}
int β = m(β);
if (β > 0)
{
rr β = this.l.a(β);
if ((β == null) || (!β.au()) || (h(β) > 900.0D) || (!D(β)))
{
a(β, 0);
}
else if (((β instanceof zj)) && (((zj)β).bJ.a))
{
a(β, 0);
}
else
{
a(β + 1, (sa)β);
this.bB[(β - 1)] = (this.T + 40 + this.S.nextInt(20));
this.bC[(β - 1)] = 0;
}
}
else
{
List<sa> β = this.l.a(sa.class, bl().b(20.0D, 8.0D, 20.0D), Predicates.and(bF, rv.e));
for (int β = 0; (β < 10) && (!β.isEmpty()); β++)
{
sa β = (sa)β.get(this.S.nextInt(β.size()));
if ((β != this) && (β.au()) && (D(β)))
{
if ((β instanceof zj))
{
if (((zj)β).bJ.a) {
break;
}
a(β, β.O()); break;
}
a(β, β.O());
break;
}
β.remove(β);
}
}
}
}
if (A() != null) {
a(0, A().O());
} else {
a(0, 0);
}
if (this.bD > 0)
{
this.bD -= 1;
if ((this.bD == 0) && (this.l.U().b("mobGriefing")))
{
int β = on.c(this.q);
int β = on.c(this.p);
int β = on.c(this.r);
boolean β = false;
for (int β = -1; β <= 1; β++) {
for (int β = -1; β <= 1; β++) {
for (int β = 0; β <= 3; β++)
{
int β = β + β;
int β = β + β;
int β = β + β;
cj β = new cj(β, β, β);
arc β = this.l.o(β);
ajt β = β.t();
if ((β.a() != axe.a) && (a(β))) {
β = (this.l.b(β, true)) || (β);
}
}
}
}
if (β) {
this.l.a(null, 1022, new cj(this), 0);
}
}
}
if (this.T % 20 == 0) {
b(1.0F);
}
this.bE.a(bQ() / bW());
}
public static boolean a(ajt β)
{
return (β != aju.h) && (β != aju.bF) && (β != aju.bG) && (β != aju.bX) && (β != aju.dc) && (β != aju.dd) && (β != aju.cv);
}
public void o()
{
l(220);
c(bW() / 3.0F);
}
public void aQ() {}
public void b(lr β)
{
super.b(β);
this.bE.a(β);
}
public void c(lr β)
{
super.c(β);
this.bE.b(β);
}
private double n(int β)
{
if (β <= 0) {
return this.p;
}
float β = (this.aM + 180 * (β - 1)) * 0.017453292F;
float β = on.b(β);
return this.p + β * 1.3D;
}
private double o(int β)
{
if (β <= 0) {
return this.q + 3.0D;
}
return this.q + 2.2D;
}
private double p(int β)
{
if (β <= 0) {
return this.r;
}
float β = (this.aM + 180 * (β - 1)) * 0.017453292F;
float β = on.a(β);
return this.r + β * 1.3D;
}
private float b(float β, float β, float β)
{
float β = on.g(β - β);
if (β > β) {
β = β;
}
if (β < -β) {
β = -β;
}
return β + β;
}
private void a(int β, sa β)
{
a(β, β.p, β.q + β.bn() * 0.5D, β.r, (β == 0) && (this.S.nextFloat() < 0.001F));
}
private void a(int β, double β, double β, double β, boolean β)
{
this.l.a(null, 1024, new cj(this), 0);
double β = n(β);
double β = o(β);
double β = p(β);
double β = β - β;
double β = β - β;
double β = β - β;
aae β = new aae(this.l, this, β, β, β);
if (β) {
β.a(true);
}
β.q = β;
β.p = β;
β.r = β;
this.l.a(β);
}
public void a(sa β, float β)
{
a(0, β);
}
public boolean a(rc β, float β)
{
if (b(β)) {
return false;
}
if ((β == rc.f) || ((β.j() instanceof xo))) {
return false;
}
if ((cZ() > 0) && (β != rc.k)) {
return false;
}
if (da())
{
rr β = β.i();
if ((β instanceof zm)) {
return false;
}
}
rr β = β.j();
if ((β != null) &&
(!(β instanceof zj)) &&
((β instanceof sa)) && (((sa)β).ca() == ca())) {
return false;
}
if (this.bD <= 0) {
this.bD = 20;
}
for (int β = 0; β < this.bC.length; β++) {
this.bC[β] += 3;
}
return super.a(β, β);
}
protected void b(boolean β, int β)
{
yd β = a(ads.cj, 1);
if (β != null) {
β.v();
}
if (!this.l.E) {
for (zj β : this.l.a(zj.class, bl().b(50.0D, 100.0D, 50.0D))) {
β.b(nk.J);
}
}
}
protected void L()
{
this.aU = 0;
}
public int d(float β)
{
return 15728880;
}
public void e(float β, float β) {}
public void c(rl β) {}
protected void bA()
{
super.bA();
a(yt.a).a(300.0D);
a(yt.d).a(0.6000000238418579D);
a(yt.b).a(40.0D);
a(yt.g).a(4.0D);
}
public float a(int β)
{
return this.by[β];
}
public float b(int β)
{
return this.bx[β];
}
public int cZ()
{
return ((Integer)this.Z.a(bw)).intValue();
}
public void l(int β)
{
this.Z.b(bw, Integer.valueOf(β));
}
public int m(int β)
{
return ((Integer)this.Z.a(bv[β])).intValue();
}
public void a(int β, int β)
{
this.Z.b(bv[β], Integer.valueOf(β));
}
public boolean da()
{
return bQ() <= bW() / 2.0F;
}
public sf ca()
{
return sf.b;
}
protected boolean n(rr β)
{
return false;
}
public boolean aV()
{
return false;
}
class a
extends tk
{
public a()
{
a(7);
}
public boolean a()
{
return xo.this.cZ() > 0;
}
}
}
| MCLabyMod/LabyMod-1.9 | xo.java |
1,032 | import java.util.Random;
public class yi
extends yq
{
private static final ke<Integer> a = kh.a(yi.class, kg.b);
private static final ke<Boolean> b = kh.a(yi.class, kg.h);
private static final ke<Boolean> c = kh.a(yi.class, kg.h);
private int bv;
private int bw;
private int bx = 30;
private int by = 3;
private int bz = 0;
public yi(aht β)
{
super(β);
a(0.6F, 1.7F);
}
protected void r()
{
this.bp.a(1, new th(this));
this.bp.a(2, new un(this));
this.bp.a(3, new ta(this, wb.class, 6.0F, 1.0D, 1.2D));
this.bp.a(4, new ts(this, 1.0D, false));
this.bp.a(5, new ug(this, 0.8D));
this.bp.a(6, new tp(this, zj.class, 8.0F));
this.bp.a(6, new uf(this));
this.bq.a(1, new uy(this, zj.class, true));
this.bq.a(2, new uv(this, false, new Class[0]));
}
protected void bA()
{
super.bA();
a(yt.d).a(0.25D);
}
public int aW()
{
if (A() == null) {
return 3;
}
return 3 + (int)(bQ() - 1.0F);
}
public void e(float β, float β)
{
super.e(β, β);
this.bw = ((int)(this.bw + β * 1.5F));
if (this.bw > this.bx - 5) {
this.bw = (this.bx - 5);
}
}
protected void i()
{
super.i();
this.Z.a(a, Integer.valueOf(-1));
this.Z.a(b, Boolean.valueOf(false));
this.Z.a(c, Boolean.valueOf(false));
}
public void b(dn β)
{
super.b(β);
if (((Boolean)this.Z.a(b)).booleanValue()) {
β.a("powered", true);
}
β.a("Fuse", (short)this.bx);
β.a("ExplosionRadius", (byte)this.by);
β.a("ignited", db());
}
public void a(dn β)
{
super.a(β);
this.Z.b(b, Boolean.valueOf(β.p("powered")));
if (β.b("Fuse", 99)) {
this.bx = β.g("Fuse");
}
if (β.b("ExplosionRadius", 99)) {
this.by = β.f("ExplosionRadius");
}
if (β.p("ignited")) {
dc();
}
}
public void m()
{
if (au())
{
this.bv = this.bw;
if (db()) {
a(1);
}
int β = da();
if ((β > 0) && (this.bw == 0)) {
a(ng.at, 1.0F, 0.5F);
}
this.bw += β;
if (this.bw < 0) {
this.bw = 0;
}
if (this.bw >= this.bx)
{
this.bw = this.bx;
df();
}
}
super.m();
}
protected nf bR()
{
return ng.as;
}
protected nf bS()
{
return ng.ar;
}
public void a(rc β)
{
super.a(β);
if (this.l.U().b("doMobLoot")) {
if ((β.j() instanceof yw))
{
int β = ado.a(ads.cA);
int β = ado.a(ads.cL);
int β = β + this.S.nextInt(β - β + 1);
a(ado.c(β), 1);
}
else if (((β.j() instanceof yi)) &&
(β.j() != this) && (((yi)β.j()).o()) && (((yi)β.j()).dd()))
{
((yi)β.j()).de();
a(new adq(ads.ch, 1, 4), 0.0F);
}
}
}
public boolean B(rr β)
{
return true;
}
public boolean o()
{
return ((Boolean)this.Z.a(b)).booleanValue();
}
public float a(float β)
{
return (this.bv + (this.bw - this.bv) * β) / (this.bx - 2);
}
protected kk J()
{
return azt.p;
}
public int da()
{
return ((Integer)this.Z.a(a)).intValue();
}
public void a(int β)
{
this.Z.b(a, Integer.valueOf(β));
}
public void a(ya β)
{
super.a(β);
this.Z.b(b, Boolean.valueOf(true));
}
protected boolean a(zj β, qm β, adq β)
{
if ((β != null) && (β.b() == ads.d))
{
this.l.a(β, this.p, this.q, this.r, ng.bw, bz(), 1.0F, this.S.nextFloat() * 0.4F + 0.8F);
β.a(β);
if (!this.l.E)
{
dc();
β.a(1, β);
return true;
}
}
return super.a(β, β, β);
}
private void df()
{
if (!this.l.E)
{
boolean β = this.l.U().b("mobGriefing");
float β = o() ? 2.0F : 1.0F;
this.aT = true;
this.l.a(this, this.p, this.q, this.r, this.by * β, β);
T();
}
}
public boolean db()
{
return ((Boolean)this.Z.a(c)).booleanValue();
}
public void dc()
{
this.Z.b(c, Boolean.valueOf(true));
}
public boolean dd()
{
return (this.bz < 1) && (this.l.U().b("doMobLoot"));
}
public void de()
{
this.bz += 1;
}
}
| MCLabyMod/LabyMod-1.9 | yi.java |
1,033 | package com.xworkz.dharsh;
public class J8 {
private String type;
String madeBy;
String mode;
String commander;
String commanderName; // im not initilizing any variables
String origin;
String use; // variable with out a specifer // we cant modify this variables in different packages
// we can only read it in diffrent packages
long cost;
String machNo;
boolean combat;
int Crew;
public void display()
{
System.out.println("type :"+type);
System.out.println("madeBy :"+madeBy);
System.out.println("mode :"+mode);
System.out.println("commander :"+commander);
System.out.println("origin :"+origin);
System.out.println("use :"+use);
System.out.println("cost :"+cost);
System.out.println("machNo :"+machNo);
System.out.println("combat :"+combat);
System.out.println("Crew :"+Crew);
}
void settype(String type)
{
this.type=type;
}
public void getType()
{
System.out.println("type :"+type);
}
}
| VikramDharsh/CaptainRohith | J8.java |
Subsets and Splits