KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > kelp > common > map > MapEntry


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  */

22
23  package org.enhydra.kelp.common.map;
24
25 // Standard imports
26
import java.util.ArrayList JavaDoc;
27 import java.util.Arrays JavaDoc;
28
29 //
30
public class MapEntry {
31     private String JavaDoc from = new String JavaDoc();
32     private String JavaDoc to = new String JavaDoc();
33
34
35     public MapEntry(String JavaDoc f, String JavaDoc t) {
36         from = f.trim();
37         to = t.trim();
38     }
39
40     public String JavaDoc getFrom() {
41       return from.trim();
42     }
43
44     public String JavaDoc getTo() {
45       return to.trim();
46     }
47
48     public boolean equals(Object JavaDoc o) {
49         boolean eq = false;
50
51         if (o instanceof MapEntry) {
52             MapEntry e = (MapEntry) o;
53
54             eq = e.from.equals(from) && e.to.equals(to);
55         }
56         return eq;
57     }
58
59     /**
60      *
61      */

62     public boolean canReduce(MapEntry e) {
63         boolean reduce = false;
64         String JavaDoc fromRemains = new String JavaDoc();
65         String JavaDoc toRemains = new String JavaDoc();
66
67         if (from.length() >= e.from.length()
68                 || to.length() >= e.to.length()) {
69             reduce = false;
70         } else if (e.from.startsWith(from) && e.to.startsWith(to)) {
71             fromRemains = e.from.substring(from.length());
72             toRemains = e.to.substring(to.length());
73             fromRemains = fromRemains.replace('/', '.');
74             reduce = fromRemains.equals(toRemains);
75         }
76         return reduce;
77     }
78
79 }
80
Popular Tags