working on it ...

Filters

Explore Public Snippets

Sort by

Found 3,171 snippets matching: classes

    public by JonahM modified May 19, 2014  275523  4  7  4

    Fluid CSS Rows

    I've realised in my coding experience that I need to To allow for space in the div or row tags when using text. Because everything is responsive on a web page, it's a good idea to use these classes. They work really well. Example: http://j.mp/1oilINn
    
    
    .strip-md{
    	padding-top:80px;
    	padding-bottom:80px;
    	position:relative;
    	overflow:hidden;
    }
    
    .strip-sm{
    	padding-top:30px;
    	padding-bottom:30px;
    }
    
    

    public by cghersi modified Dec 5, 2012  179356  5  7  0

    Apache Cayenne: how to select with Joins

    This is how to create simple queries that use JOIN among several tables. Such tables must be modelled as related in Cayenne modeler. In the example, we have 4 classes in JOIN chain. We want to retrieve all the objects of the 4th class that match the join with the object of the first class with the given id.
    ObjectContext context = getMyContext();
    int id = ...; //the pk of the FirstClass table
    FirstClass n = Cayenne.objectForPK(context, FirstClass.class, id);
    Expression qualifier = ExpressionFactory.matchExp(FourthClass.THIRD_CLASS_PROPERTY + "." + 
    					ThirdClass.SECOND_CLASS_PROPERTY + "." + SecondClass.FIRST_CLASS_PROPERTY, n);
    SelectQuery select = new SelectQuery(FourthClass.class, qualifier);
    List<FourthClass> result = context.performQuery(select);

    public by micurs modified Sep 23, 2014  12167  4  10  4

    Typescript + underscore: serializing objects

    This little example runs on node.js and assumes you have the typescript type-definition file in the types subdirectory. The example defines two classes one representing a undergrad course in computer science and another one representing possible students for the course. Few things are interesting here: 1 - the overloading of the toString()
    ///<reference path='../types/node.d.ts'/>
    ///<reference path='../types/underscore.d.ts'/>
    
    import _ = require("underscore");
    
    function write(msg) {
        process.stdout.write(msg+'\n');
    }
    
    class Student {
      firstName : string;
      lastName : string;
    
      constructor( n: string, v: string ) {
        this.firstName = n;
        this.lastName = v;
      }
    
      toString() : string {
        return '[ ' + this.firstName + ' ' + this.lastName + ' ]';
      }
    }
    
    class Class {
      title : string = "Computer Science 101";
      participants : Student[] = new Array();
    
      addStudent( s : Student ) : any {
        this.participants.push(s);
      }
    
      toString() : string {
        return this.title + '\n\t' 
              + _.reduce( this.participants, (acc,s) => acc += '\n\t'+ s );
      }
    
    }
    
    var firstSemesterClass : Class = new Class();
    
    firstSemesterClass.addStudent( new Student("John","Smith"));
    firstSemesterClass.addStudent( new Student("Frank","Gehry"));
    
    write( firstSemesterClass );
    
        

    public by micurs modified Mar 6, 2014  3365  0  7  2

    Typescript basic class

    Classes in typescript can contain properties and functions and can be instantiated by typescript code or directly in javascript.
    // TypeScript
    class Student {
    
      // Properties are public by default
      firstName: string;
      lastName: string;
      id: int;   
    
      // Constructor 
      constructor( name: string, lastName: string, id: int) {
        this.firstName = name;
        this.lastName = lastName;
        this.id = id;
      }
    }  
    
    // You can instantiate the Student from javascript or typescript in 
    // the same way.
    var aStudent = new Student('john','Smith', 1024 );
     
     

    public by lbottaro modified Apr 2, 2014  2429  5  6  0

    Equipment class - Integration of JPA and JAXB Java classes

    The class models an Equipment, referencing its own Network class via ManyToOne and XmlIDREF annotations. It has many Card objects and refers to unique EquipmentController, using annotation OneToOne.
    package com.examples.jpa;
    
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;
    
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.ManyToOne;
    import javax.persistence.OneToMany;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;
    import javax.xml.bind.annotation.*;
    
    @XmlType(propOrder = {"id", "network", "label", "cards", "equipmentController"})
    @XmlAccessorType(XmlAccessType.FIELD)
    @Entity
    @Table(name = "EQUIPMENT")
    public class Equipment implements Serializable {
    
    	@XmlElement(name = "equipment-ID")
    	@XmlID
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private String id;
    	
    	@ManyToOne
    	@XmlIDREF
    	private Network network;
    	
    	@XmlElement(name = "equipment-label")
        @Column(name = "LABEL", length = 125)
        private String label;
    	
    	@XmlElementWrapper(name = "cards")
    	@XmlElement(name = "equipment-cards")
        @OneToMany(mappedBy = "equipment", cascade = CascadeType.ALL, orphanRemoval = true)
        private List<Card> cards;
    	
    	@XmlElement(name = "equipment-controller")
        @OneToOne(cascade = CascadeType.ALL)
        private EquipmentController equipmentController;
    
        public Equipment() {
        }
    
        public Equipment(String label) {
            this.label = label;
        }
    
        public String getId() {
            return id;
        }
    
        public void setId(String id) {
            this.id = id;
        }
    
        public void addCard(Card card) {
            if (cards == null) {
                this.cards = new ArrayList();
            }
            card.setEquipment(this);
            cards.add(card);
        }
    
        public List<Card> getCards() {
            return cards;
        }
    
        public void setCards(List<Card> cards) {
            this.cards = cards;
        }
    
        public String getLabel() {
            return label;
        }
    
        public void setLabel(String label) {
            this.label = label;
        }
    
        public EquipmentController getEquipmentController() {
            return equipmentController;
        }
    
        public void setEquipmentController(EquipmentController equipmentController) {
            this.equipmentController = equipmentController;
            equipmentController.setEquipment(this);
        }
    
        @Override
        public String toString() {
            return "Equipment{" + "id=" + id + ", label=" + label + ", equipmentController=" + equipmentController + '}';
        }
    
    	/**
    	 * @return the network
    	 */
    	public Network getNetwork() {
    		return network;
    	}
    
    	/**
    	 * @param network the network to set
    	 */
    	public void setNetwork(Network network) {
    		this.network = network;
    	}
    
    	
        
    }
    

    public by lbottaro modified Apr 4, 2014  2641  1  6  0

    Ethernet java class - Integration of JPA and JAXB Java classes

    The class extends the abstract Port class, integratin both JPA and JAX-B java api.
    package com.examples.jpa;
    
    import javax.persistence.Column;
    import javax.persistence.DiscriminatorValue;
    import javax.persistence.Entity;
    import javax.persistence.Table;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    @Entity
    @Table(name = "ETHERNET_PORT")
    @DiscriminatorValue("ETHERNET")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlRootElement(name="eth-port")
    public class EthernetPort extends Port {
    
    	@XmlElement(name = "mtu")
        @Column(name = "MTU_SIZE")
        private int mtuSize;
    	
        @Column(name = "SPEED")
    	@XmlElement(name = "speed")
        private int speed;
        
    	@XmlElement(name = "auton")
        @Column(name = "AUTONEGOTATION")
        private boolean autonegotiation;
    
        public EthernetPort() {
        }
    
        public EthernetPort(String label) {
            super(label);
        }
    
        public EthernetPort(String label, int mtuSize, int speed, boolean autonegotiation) {
            super(label);
            this.mtuSize = mtuSize;
            this.speed = speed;
            this.autonegotiation = autonegotiation;
        }
    
        public int getMtuSize() {
            return mtuSize;
        }
    
        public void setMtuSize(int mtuSize) {
            this.mtuSize = mtuSize;
        }
    
        public int getSpeed() {
            return speed;
        }
    
        public void setSpeed(int speed) {
            this.speed = speed;
        }
    
        public boolean isAutonegotiation() {
            return autonegotiation;
        }
    
        public void setAutonegotiation(boolean autonegotiation) {
            this.autonegotiation = autonegotiation;
        }
    
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		return "EthernetPort [mtuSize=" + mtuSize + ", speed=" + speed
    				+ ", autonegotiation=" + autonegotiation + "]";
    	}
        
        
    
    }
    

    public by lbottaro modified Apr 4, 2014  2380  1  6  0

    Sdh Port java class - Integration of JPA and JAXB Java classes

    This class extends Port class and integrate JPA and JAXB techniques.
    package com.examples.jpa;
    
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Enumerated;
    import javax.persistence.Table;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlType;
    
    @Entity
    @Table(name = "OPTICAL_PORT")
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlRootElement(name="sdh-port")
    public class SdhPort extends Port {
    
    	@XmlElement(name = "framing")
        @Column(name = "GENERIC_FRAMING_PROCEDURE")
        private boolean genericFramingProcedure;
    	
    	@XmlElement(name = "vc")
        @Column(name = "VIRTUAL_CONTAINER")
        @Enumerated
        private VirtualContainer virtualContainer;
    	
    	@XmlElement(name = "bandwidth")
        @Column(name = "BANDWIDTH")
        private long bandwidth;
    
        public SdhPort() {
        }
    
        public SdhPort(String label) {
            super(label);
        }
    
        public SdhPort(String label, boolean genericFramingProcedure, long bandwidth, VirtualContainer virtualContainer) {
            super(label);
            this.genericFramingProcedure = genericFramingProcedure;
            this.bandwidth = bandwidth;
            this.virtualContainer = virtualContainer;
        }
    
        public boolean isGenericFramingProcedure() {
            return genericFramingProcedure;
        }
    
        public void setGenericFramingProcedure(boolean genericFramingProcedure) {
            this.genericFramingProcedure = genericFramingProcedure;
        }
    
        public VirtualContainer getVirtualContainer() {
            return virtualContainer;
        }
    
        public void setVirtualContainer(VirtualContainer virtualContainer) {
            this.virtualContainer = virtualContainer;
        }
    
        public long getBandwidth() {
            return bandwidth;
        }
    
        public void setBandwidth(long bandwidth) {
            this.bandwidth = bandwidth;
        }
    
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		return "SdhPort [genericFramingProcedure=" + genericFramingProcedure
    				+ ", virtualContainer=" + virtualContainer + ", bandwidth="
    				+ bandwidth + "]";
    	}
        
        
    
    }
    

    public by lbottaro modified Apr 6, 2014  2258  0  6  1

    EquipmentController java class - Integration of JPA and JAXB Java classes

    This class refers to a unique Equipment class, using OneToOne annotation.
    package com.examples.jpa;
    
    import java.io.Serializable;
    
    import javax.persistence.Column;
    import javax.persistence.Embedded;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToOne;
    import javax.persistence.Table;
    import javax.xml.bind.annotation.*;
    
    @XmlAccessorType(XmlAccessType.FIELD)
    @Entity
    @Table(name = "EQUIPMENT_CONTROLLER")
    public class EquipmentController implements Serializable {
    
    	@XmlElement(name = "id")
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;
    	
    	@XmlElement(name = "label")
        @Column(name = "LABEL", length = 125)
        private String label;
    	
    	@XmlTransient
        @OneToOne
        private Equipment equipment;
    	
    	@XmlElement(name = "controllerAddress")
        @Embedded
        private ControllerAddress controllerAddress;
    
        public EquipmentController() {
        }
    
        public EquipmentController(String label) {
            this.label = label;
        }
    
        public Long getId() {
            return id;
        }
    
        public void setId(Long id) {
            this.id = id;
        }
    
        public String getLabel() {
            return label;
        }
    
        public void setLabel(String label) {
            this.label = label;
        }
    
        public Equipment getEquipment() {
            return equipment;
        }
    
        public void setEquipment(Equipment equipment) {
            this.equipment = equipment;
        }
    
        public ControllerAddress getControllerAddress() {
            return controllerAddress;
        }
    
        public void setControllerAddress(ControllerAddress controllerAddress) {
            this.controllerAddress = controllerAddress;
        }
    
    	/* (non-Javadoc)
    	 * @see java.lang.Object#toString()
    	 */
    	@Override
    	public String toString() {
    		return "EquipmentController [id=" + id + ", label=" + label
    				+ ", controllerAddress="
    				+ controllerAddress + "]";
    	}
        
        
    
    }
    

    public by cghersi @ Abodata DEV Team modified Nov 14, 2013  3245  1  5  0

    Apache Cayenne: correctly load classes under OSGI environment

    This step is required to correctly use Cayenne framework under OSGi environment. Simply adjust the class-loading issues that can arise in OSGi.
    private void initCayenneClasses() {
    	String packageName = "myPackage.with.cayenne.autogenerated.classes";
    	List<Class<?>> classes = getClassesOfPackage(FrameworkUtil.getBundle(this.getClass()), packageName);
    	for (Class<?> cl : classes) {
    		ClassRegistry.unRegisterClass(cl);
    	}
    	for (Class<?> cl : classes) {
    		ClassRegistry.registerClass(cl);
    	}
    }

    public by cghersi @ Abodata DEV Team modified Nov 14, 2013  2978  3  5  0

    How to Retrieve the list of classes in a package under OSGi

    This method lists the classes contained in a package of the given bundle under OSGi environment.
    public List<Class<?>> getClassesOfPackage(Bundle b, String packageName) {
    	BundleWiring wiring = b.adapt(BundleWiring.class);
    	Collection<String> classNames = wiring.listResources(packageName.replace('.', '/'), null, 
    				BundleWiring.LISTRESOURCES_LOCAL);
    	List<Class<?>> result = new ArrayList<Class<?>>();
    	for (String cName : classNames) {
    		Class<?> c = null;
    		try {
    			c = b.loadClass(cName.replace(".class", "").replace('/', '.'));
    		} catch (ClassNotFoundException e) {
    			continue;
    		}
    		if (c != null)
    			result.add(c);
    	}
    	return result;
    }
    • Public Snippets
    • Channels Snippets