home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-05-08 | 2.5 KB | 93 lines |
- /*
- * Copyright (c) 1997-1998 Borland International, Inc. All Rights Reserved.
- *
- * This SOURCE CODE FILE, which has been provided by Borland as part
- * of a Borland product for use ONLY by licensed users of the product,
- * includes CONFIDENTIAL and PROPRIETARY information of Borland.
- *
- * USE OF THIS SOFTWARE IS GOVERNED BY THE TERMS AND CONDITIONS
- * OF THE LICENSE STATEMENT AND LIMITED WARRANTY FURNISHED WITH
- * THE PRODUCT.
- *
- * IN PARTICULAR, YOU WILL INDEMNIFY AND HOLD BORLAND, ITS RELATED
- * COMPANIES AND ITS SUPPLIERS, HARMLESS FROM AND AGAINST ANY CLAIMS
- * OR LIABILITIES ARISING OUT OF THE USE, REPRODUCTION, OR DISTRIBUTION
- * OF YOUR PROGRAMS, INCLUDING ANY CLAIMS OR LIABILITIES ARISING OUT OF
- * OR RESULTING FROM THE USE, MODIFICATION, OR DISTRIBUTION OF PROGRAMS
- * OR FILES CREATED FROM, BASED ON, AND/OR DERIVED FROM THIS SOURCE
- * CODE FILE.
- */
- package visibroker.samples.pass_by_value.list;
-
- public class ListServer extends _ListUtilityImplBase {
-
- ListServer(String name) {
- super(name);
- }
-
- public int length(List list) {
- int result = 0;
- for( ; list != null; list = list.next()) {
- result++;
- }
- return result;
- }
-
- public List reverse(List list) {
- List result = null;
- for( ; list != null; list = list.next()) {
- result = new List(list.data(), result);
- }
- return result;
- }
-
- public List sort(List list) {
- int length = length(list);
- if(length <= 1) {
- return list;
- }
- // split the list in half
- List lhs = list;
- for(int i = 0; i < length / 2 - 1; i++) {
- list = list.next();
- }
- List rhs = list.next();
- // this actually splits the lists
- list.next(null);
- // sort and merge the two halves
- return merge(sort(lhs), sort(rhs));
- }
-
- public List merge(List lhs, List rhs) {
- if(lhs == null) {
- return rhs;
- }
- if(rhs == null) {
- return lhs;
- }
- // figure out which side is next
- List head;
- if(lhs.data().compareTo(rhs.data()) < 0) {
- head = lhs;
- lhs = lhs.next();
- }
- else {
- head = rhs;
- rhs = rhs.next();
- }
- head.next(merge(lhs, rhs));
- return head;
- }
-
- public static void main(String[] args) {
- org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args,null);
- org.omg.CORBA.BOA boa = orb.BOA_init();
- ListUtility impl = new ListServer("demo");
- boa.obj_is_ready(impl);
- System.out.println(impl + " is ready.");
- boa.impl_is_ready();
- }
-
- }
-
-