/** * Finds a {@code Unit} based on a type. If the {@code Unit} is not found, * it will be created and added to the list of all units under a null name. * * @param type the type of the {@code Unit} to find * * @return the {@code Unit} */ static synchronized Unit find(long type) { if (base == null) { int size = allUnits.length; base = new Hashtable(size << 1); for (int i = 0; i < size; i++) { base.put(allUnits[i], allUnits[i]); } } Unit unit = new Unit(null, type); Unit out = (Unit) base.get(unit); if (out == null) { base.put(unit, unit); out = unit; } return out; }
/** * Finds a <code>Unit</code> based on a type. If the <code>Unit</code> is not * found, it will be created and added to the list of all units under a null * name. * * @param type the type of the <code>Unit</code> to find * * @return the <code>Unit</code> */ static synchronized Unit find(long type) { if (base == null) { int size = allUnits.length; base = new Hashtable(size << 1); for (int i = 0; i < size; i++) { base.put(allUnits[i], allUnits[i]); } } Unit unit = new Unit(null, type); Unit out = (Unit) base.get(unit); if (out == null) { base.put(unit, unit); out = unit; } return out; }
public class TestUnit { //You can create a reference to handle your Unit instance private Unit myunit; //Provide a constructor to assign a unit you create public TestUnit(Unit myunit) { this.myunit = myunit; } //Or provide a default constructor which instances a default one public TestUnit() { this.myunit = new Unit(); } }
public static final Parcelable.Creator<Unit> CREATOR = new Parcelable.Creator<Unit>() { public Unit createFromParcel(Parcel in) { return new Unit(in); } public Unit[] newArray(int size) { return new Unit[size]; } };
public class TestUnit{ private Unit unit; public TestUnit(){ unit = new Unit(); } }
public class TestUnit{ private Unit unit; public TestUnit(){ this.unit=new Unit();} } }
public static final Parcelable.Creator<Unit> CREATOR = new Parcelable.Creator<Unit>() { public Unit createFromParcel(Parcel in) { Unit u = new Unit(); u.setUnitName(in.readString()); //... //populate all atributes return u; } public Unit[] newArray(int size) { return new Unit[size]; } };
Double carray[]; //class variable (array) Unit(Double[] array) //constructor { this.carray=array; this.carray={3.145,4.12345.....}; //passing an array means, you are actually passing the value of it's reference. //In this case, `carray` of the object ob points to the same reference as the one passed } public static void main(String[] args) { Double[] arr=new Double[5]; Unit ob=new Unit(arr); //passes `reference` or `address` of arr to the constructor. }
@XmlRegistry public class ObjectFactory { /** * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.foo.bar * */ public ObjectFactory() { } /** * Create an instance of {@link Unit } * */ public Unit createUnit() { return new Unit(); } }
Character.prototype = new Unit(0,0,0); // or whatever defaults if you want them
var coolUnit = new Unit(); Unit.actions.moveUp.call(coolUnit);
public static void main(String[] argv) { UnitList myUnitList = new UnitList(); myUnitList.add(new Unit(...)); myUnitList.print(); }
private Unit getUnitObject(String unit1Code) { Unit selectedUnit = new Unit(); for (int i = 0; i < units.size(); i++) { Unit currUnit = units.get(i); String unitCode = currUnit.getUnitCode(); if (unit1Code.compareTo(unitCode)) { selectedUnit = currUnit; } } return selectedUnit; }
/** * Finds a {@code Unit} based on a type. If the {@code Unit} is not found, * it will be created and added to the list of all units under a null name. * * @param type the type of the {@code Unit} to find * * @return the {@code Unit} */ static synchronized Unit find(long type) { if (base == null) { int size = allUnits.length; base = new Hashtable(size << 1); for (int i = 0; i < size; i++) { base.put(allUnits[i], allUnits[i]); } } Unit unit = new Unit(null, type); Unit out = (Unit) base.get(unit); if (out == null) { base.put(unit, unit); out = unit; } return out; }
/** * Finds a {@code Unit} based on a type. If the {@code Unit} is not * found, it will be created and added to the list of all units under a null * name. * * @param type the type of the {@code Unit} to find * * @return the {@code Unit} */ static synchronized Unit find(long type) { if (base == null) { int size = allUnits.length; base = new Hashtable(size << 1); for (int i = 0; i < size; i++) { base.put(allUnits[i], allUnits[i]); } } Unit unit = new Unit(null, type); Unit out = (Unit) base.get(unit); if (out == null) { base.put(unit, unit); out = unit; } return out; }
/** * Finds a {@code Unit} based on a type. If the {@code Unit} is not found, * it will be created and added to the list of all units under a null name. * * @param type the type of the {@code Unit} to find * * @return the {@code Unit} */ static synchronized Unit find(long type) { if (base == null) { int size = allUnits.length; base = new Hashtable(size << 1); for (int i = 0; i < size; i++) { base.put(allUnits[i], allUnits[i]); } } Unit unit = new Unit(null, type); Unit out = (Unit) base.get(unit); if (out == null) { base.put(unit, unit); out = unit; } return out; }
/** * Finds a {@code Unit} based on a type. If the {@code Unit} is not found, * it will be created and added to the list of all units under a null name. * * @param type the type of the {@code Unit} to find * * @return the {@code Unit} */ static synchronized Unit find(long type) { if (base == null) { int size = allUnits.length; base = new HashMap<>(size << 1); for (int i = 0; i < size; i++) { base.put(allUnits[i], allUnits[i]); } } Unit unit = new Unit(null, type); Unit out = base.get(unit); if (out == null) { base.put(unit, unit); out = unit; } return out; }
public class SimpleBoardGame { private static Land[] ar = new Land[3]; public static Land[] getAr() { return ar; } public static void main(String[] args) { Land One = new Land(1, 0, 0, 0, 1, new int[]{2, 3}); Land Two = new Land(0, 1, 0, 0, 2, new int[]{1, 3}); Land Three = new Land(0, 0, 1, 0, 3, new int[]{1, 2}); ar[0] = One; ar[1] = Two; ar[2] = Three; // When you pass the parameter for 'y' please make sure it already minus by one. // If not, will occur the 'java.lang.ArrayIndexOutOfBoundsException' Unit Footman = new Unit(1, 0); Unit Knight = new Unit(2, 2); Unit Siege = new Unit(3, 1); } }
public class Course { ... @OneToMany(mappedBy = "course", cascade = CascadeType.ALL, orphanRemoval = true) private List<Unit> units = new ArrayList<>(); public int getCourseUnits() { return units.size(); } public void setCourseUnits(int numberOfUnits) { if (units.size() > numberOfUnits) { units.sublist(numberOfUnits, units.size()).clear(); } else { for (int i = units.size(); i < numberOfUnits; i++) { Unit unit = new Unit(); unit.setUnitNumber(i); units.add(unit); } } } }
Unit fish = new Unit(); Unit fatFish = new FatFish(); fish.swim(); //regular function is called fatFish.swim(); //special function is called