001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.geronimo.samples.daytrader.client; 018 019 import java.util.*; 020 021 public class TradeQuoteAuditStatsComparator implements Comparator { 022 private int index; 023 024 public TradeQuoteAuditStatsComparator(int index) { 025 this.index = index; 026 } 027 028 public int compare(Object o1, Object o2) { 029 TradeStreamerQuoteDataBean bean1 = (TradeStreamerQuoteDataBean)o1; 030 TradeStreamerQuoteDataBean bean2 = (TradeStreamerQuoteDataBean)o2; 031 032 switch (index) { 033 case TradeQuoteAuditStats.SYMBOL_COL: { 034 return bean1.getSymbol().compareTo(bean2.getSymbol()); 035 } 036 case TradeQuoteAuditStats.COMPANY_COL: { 037 return bean1.getCompanyName().compareTo(bean2.getCompanyName()); 038 } 039 case TradeQuoteAuditStats.PRICE_COL: { 040 return bean1.getPrice().compareTo(bean2.getPrice()); 041 } 042 case TradeQuoteAuditStats.AUDIT_PRICE_COL: { 043 return bean1.getAuditPrice().compareTo(bean2.getAuditPrice()); 044 } 045 case TradeQuoteAuditStats.VOLUME_COL: { 046 return (int)(bean1.getVolume() - bean2.getVolume()); 047 } 048 case TradeQuoteAuditStats.AUDIT_VOLUME_COL: { 049 return (int)(bean1.getAuditVolume() - bean2.getAuditVolume()); 050 } 051 case TradeQuoteAuditStats.OPEN_COL: { 052 return bean1.getOpen().compareTo(bean2.getOpen()); 053 } 054 case TradeQuoteAuditStats.LOW_COL: { 055 return bean1.getLow().compareTo(bean2.getLow()); 056 } 057 case TradeQuoteAuditStats.HIGH_COL: { 058 return bean1.getHigh().compareTo(bean2.getHigh()); 059 } 060 case TradeQuoteAuditStats.CHANGE_COL: { 061 return (int)(bean1.getChange() - bean2.getChange()); 062 } 063 case TradeQuoteAuditStats.UPDATE_COL: { 064 return bean1.getLastUpdate().compareTo(bean2.getLastUpdate()); 065 } 066 default: { 067 throw new IllegalArgumentException(); 068 } 069 } 070 } 071 }