MatchPattern.java revision fb379c70e3fd8a537f311b99be4759ae41e02750
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * The contents of this file are subject to the terms
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * of the Common Development and Distribution License
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * (the License). You may not use this file except in
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * compliance with the License.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * You can obtain a copy of the License at
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * https://opensso.dev.java.net/public/CDDLv1.0.html or
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * See the License for the specific language governing
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * permission and limitations under the License.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * When distributing Covered Code, include this CDDL
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * Header Notice in each file and include the License file
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * If applicable, add the following below the CDDL Header,
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * with the fields enclosed by brackets [] replaced by
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * your own identifying information:
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * "Portions Copyrighted [year] [name of copyright owner]"
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major * $Id: MatchPattern.java,v 1.2 2008/06/25 05:51:29 qcheng Exp $
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public MatchPattern(String pattern, int matchType) {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major boolean matchFound = false;
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major matchFound = lineData.regionMatches(isIgnoreCase(), 0,
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major } else if (isMatchFromEnd()) {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major matchFound = lineData.regionMatches(isIgnoreCase(), frmOff,
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major } else if (isIgnoreCase()) {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major } else if (lineData.indexOf(getPattern()) >= 0) {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public boolean isMatchForLastOccurranceInFile() {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public boolean isActive() {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public int getMatchType() {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public void setLastOccurranceInFile(boolean flag) {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major sb.append(", matchFromStart=").append(isMatchFromStart());
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major sb.append(", matchFromEnd=").append(isMatchFromEnd());
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major sb.append(", ignoreCase=").append(isIgnoreCase());
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private boolean isMatchFromStart() {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major return (getMatchType() == INT_MATCH_FROM_START);
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private boolean isMatchFromEnd() {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private boolean isIgnoreCase() {
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major if ((type == INT_MATCH_FROM_START) || (type == INT_MATCH_FROM_END)
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major throw new IllegalArgumentException("Invalid argument for match"
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // Intially will be true. Once found it becomes inactive.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private boolean isActive;
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major // If true only the last occurrance will be removed. Otherwise the first.
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private boolean lastOccurranceInFile;
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major private boolean ignoreCase;
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public static final int INT_MATCH_OCCURRANCE = 0;
fb379c70e3fd8a537f311b99be4759ae41e02750Peter Major public static final int INT_MATCH_FROM_START = 1;