PageRenderTime 11ms CodeModel.GetById 5ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/edu/uncc/parsets/data/CategoryHandle.java

https://code.google.com/p/parsets/
Java | 103 lines | 57 code | 16 blank | 30 comment | 2 complexity | c36960ed9615240be3bd19ff096af335 MD5 | raw file
  1package edu.uncc.parsets.data;
  2
  3/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
  4 * Copyright (c) 2009, Robert Kosara, Caroline Ziemkiewicz,
  5 *                     and others (see Authors.txt for full list)
  6 * All rights reserved.
  7 * 
  8 * Redistribution and use in source and binary forms, with or without
  9 * modification, are permitted provided that the following conditions are met:
 10 * 
 11 *    * Redistributions of source code must retain the above copyright
 12 *      notice, this list of conditions and the following disclaimer.
 13 *    * Redistributions in binary form must reproduce the above copyright
 14 *      notice, this list of conditions and the following disclaimer in the
 15 *      documentation and/or other materials provided with the distribution.
 16 *    * Neither the name of UNC Charlotte nor the names of its contributors
 17 *      may be used to endorse or promote products derived from this software
 18 *      without specific prior written permission.
 19 *      
 20 * THIS SOFTWARE IS PROVIDED BY ITS AUTHORS ''AS IS'' AND ANY
 21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 31
 32public class CategoryHandle implements Comparable<CategoryHandle> {
 33
 34	private String name;
 35	private String handle;
 36	private int num;
 37	private DimensionHandle dimension;
 38	private int apriori;
 39	// used for comparing categories, so that the same name in different
 40	// dimensions doesn't look like the same handle
 41	private String categoryID;
 42	
 43	public CategoryHandle(String name, String handle, int num, DimensionHandle dim, int count) {
 44		this.name = name;
 45		this.handle = handle;
 46		this.num = num;
 47		dimension = dim;
 48		apriori = count;
 49		categoryID = dim.getHandle()+":"+handle;
 50	}
 51	
 52	public String getName() {
 53		return name;
 54	}
 55	
 56	@Override
 57	public String toString() {
 58		return name;
 59	}
 60	
 61	public String getHandle() {
 62		return handle;
 63	}
 64	
 65	public int getCategoryNum() {
 66		return num;
 67	}
 68	
 69	public int getCount() {
 70		return apriori;
 71	}
 72        
 73        public void setCount(int count){
 74            this.apriori = count;
 75        }
 76	
 77	public float getMarginalFrequency() {
 78		return (float)apriori/dimension.getDataSet().getNumRecords();
 79	}
 80	
 81	public DimensionHandle getDimension() {
 82		return dimension;
 83	}
 84	
 85	public int compareTo(CategoryHandle o) {
 86		return categoryID.compareTo(o.categoryID);
 87	}
 88
 89	@Override
 90	public boolean equals(Object o) {
 91		if (o instanceof CategoryHandle)
 92			return compareTo((CategoryHandle)o) == 0;
 93		else
 94			return false;
 95	}
 96	
 97	@Override
 98	public int hashCode() {
 99		assert false : "hashCode not designed";
100		return 42; // any arbitrary constant will do
101	}
102	
103}