Eclipse要求我把它抽象化?

时间:2015-09-04 15:45:13

标签: java eclipse abstract

我需要生成两个独立的jar文件,它们彼此交互但是做不同的事情。我有两个项目加载到Eclipse中,但都使用了大量相同的导入,因此我将它们放在同一工作区下的子文件夹中。

当我尝试运行它时,其中一个得不到"java class xxxx

当我试图解决这个问题时,我正在比较这两个项目并发现文件夹是工作文件夹的外部构建路径的一部分,而不是非工作文件夹。我把它添加到非工作的那个并打破了工作。

现在工作的那个在主类名上有错误。我调用程序ZSTATEngine,所以类是

public class ZSTATEngine implements ETOSFilterEngine 

现在该名称已突出显示,当我将鼠标悬停在其上时说:"the type ZSTATEngine必须实现继承的抽象方法ETOSFilterEngine.doFilter(MessageBlock)"

有什么可以改变的?之前工作正常,代码本身没有任何改变。我不明白引用的库是如何工作的,但至少在以前工作的项目中它们的结构没有任何变化。

好的一些进一步的信息:我确实在该课程中有一个部分:

public MessageBlock doFilter(MessageBlock msgBlock)

所以我正在实现那个方法......但是这个方法现在里面有一个错误,

  

“FilterFramework类型中的方法addFilteredMessage(MessageBlock)不适用或参数(MessageBlock)......

那怎么可能变坏了?它工作得很好。

这是完整的代码:

package com.ibm.tpf.internal;

import java.awt.Color;  
/*import java.util.ArrayList;*/
/*import java.util.*;*/

import com.ibm.tpf.etos.TPFFilter.*;
//import com.ibm.tpf.etos.TPFFilter.TernarySwitch;

import com.ibm.tpf.etos.api.*;
/*
import com.ibm.tpf.etos.api.Constants;
import com.ibm.tpf.etos.api.MessageBlock;
*/
import com.ibm.tpf.etos.filter.*;
/*
import com.ibm.tpf.etos.filter.ETOSFilterEngine;
import com.ibm.tpf.etos.filter.FilterConfigurationException;
import com.ibm.tpf.etos.filter.FilterFramework;
import com.ibm.tpf.etos.filter.FilterRuntimeException;
*/

public class ZSTATEngine implements ETOSFilterEngine {
    FilterFramework fw = null;
    String[] names = null;

    public ZSTATEngine(FilterFramework filFW, String[] parms) {
        super();
        this.fw = filFW;
    }

    /* AAES0009I 13.45.01 FROM TA 05 : AUTC0000I TOSFCOLOR_GREEN TOSBCOLOR_NONE TOSHOLD_0 TOSSAVE_0 TOSALERT_0 AUTC1111I 12.04.41 OK */
    public MessageBlock doFilter(MessageBlock msgBlock) throws FilterRuntimeException {
        if(msgBlock.getMsgID().equals("AAES0009I")) { /* only handle messages that start with AAES0009I */
            if(msgBlock.getMsg().indexOf("ZUVRT") != -1) { /* if the message contains "ZUVRT" then let it through.  We want to react to the result of it, not the ZUVRT itself. */
                return msgBlock;
            }
            if(msgBlock.getMsg().indexOf("AUTC0000I") != -1) {        /* search string to see if "AUTC0000I is in it.  If it is then do..." */ 
                String myString = msgBlock.getMsg();
                Color fColor = Color.WHITE;                           /* set default colors */
                Color bColor = Color.BLACK;
                msgBlock.setSuppressed(TernarySwitch.ON);             /* suppress original message to display new one */
                String[] myStringParts = myString.split("\\s+",13);   /* divide message into 13 parts.  The 13th part is everything remaining. */
                String finalPart = myStringParts[12].toString();      /* print last part to the screen */
                MessageBlock mb = new MessageBlock(finalPart, Constants.ETOS_ONE_MSG);
                String fColorMsg     = myStringParts[7].toString();   /* Process the foreground color portion */
                if (!fColorMsg.contains("NONE")) {
                    fColor = ColorStringInterpreter(fColorMsg);
                    mb.setForeground(fColor);
                }
                String bColorMsg     = myStringParts[8].toString();   /* Process the background color portion */
                if (!bColorMsg.contains("NONE")) {
                    bColor = ColorStringInterpreter(bColorMsg);
                    mb.setBackground(bColor);
                }
                String holdMsg = myStringParts[9].toString();         /* Process the hold message portion */
                if (holdMsg.toUpperCase().startsWith("TOS")) {        /* if it starts with TOS, grab only the number at the end */
                    String[] holdPart = holdMsg.split("_",2);
                    if (holdPart[1].toString().equals("1")) {
                        mb.setHeld(TernarySwitch.ON);   
                    }   
                }
                else {
                    if (holdMsg.equals("1")) {                        /* otherwise, just use the number */
                        mb.setHeld(TernarySwitch.ON);   
                    }
                }
                String saveMsg = myStringParts[10].toString();        /* Process the save areas.  These have two formats currently: TOSSAVE_X_X_X_X and BBBBBBBBB, where X is a digit 1-32, and B is binary. */
                if (saveMsg.toUpperCase().startsWith("TOS")) {         
                    String[] savePart = saveMsg.split("_");           /* handle the multiple digit save areas, and ignore the first split which is TOSSAVE */
                    if (!savePart[1].toString().equals("0")) {
                        long areaBits = 0;
                        for (int i=1; i<savePart.length; i++) {
                            areaBits |= 1L << Integer.parseInt(savePart[i]);
                        }   
                        mb.setSave(areaBits);
                    }
                }
                else {                                               /* otherwise, just use the binary string directly */
                    long areaBits = Long.parseLong(myStringParts[10].toString(), 2);
                    mb.setSave(areaBits);
                }
                fw.addFilteredMessage(mb);                           /* this is the command that pieces the whole message together */
            }
        }
        int plusLocation = msgBlock.getMsg().lastIndexOf('+');
        if (plusLocation > 0) {
            MessageBlock mb1 = new MessageBlock(msgBlock.getMsg(), msgBlock.getFlag());
            fw.addFilteredMessage(mb1);
            msgBlock.setSuppressed(TernarySwitch.ON);
            MessageBlock mb2 = new MessageBlock("", Constants.ETOS_ONE_MSG);
            fw.addFilteredMessage(mb2);
        }
        return msgBlock;                                             /* whatever gets returned is what the system prints */
    }

    private Color ColorStringInterpreter(String colorMsg) throws FilterRuntimeException {
        if (colorMsg.toUpperCase().startsWith("TOS")) {              /* if it starts with TOS, then we're using color names */
            String[] colorParts = colorMsg.split("_",2);
            String colorTxt     = colorParts[1].toString().trim();
            if (colorTxt.toUpperCase() != "NONE") {
                Color finalColor = Colors.fromString(colorTxt);
                return finalColor;
            }
        }
        else {
            String[] colorParts = colorMsg.split("_",3);            /* otherwise we're using RGB values */
            String sRed = colorParts[0].toString().trim();
            String sGreen = colorParts[1].toString().trim();
            String sBlue = colorParts[2].toString().trim();
            /*mb = new MessageBlock(sRed, Constants.ETOS_ONE_MSG);*/
            int iRed = Integer.parseInt(sRed);
            int iGreen = Integer.parseInt(sGreen);
            int iBlue = Integer.parseInt(sBlue);
            Color finalColor = new Color (iRed, iGreen, iBlue);
            return finalColor;
        }
        return null;
    }

    public String getName() {
        return null;
    }

    public void modifyState(Object[] newParams) throws FilterConfigurationException, FilterRuntimeException {
    }

    public boolean isActive() {
        return false;
    }

    public void shutdown() {
    }
}

2 个答案:

答案 0 :(得分:2)

public class ZSTATEngine implements ETOSFilterEngine

根据上面的代码,你的类ZSTATEngine正在实现一个接口ETOSFilterEngine,这意味着你的类需要实现ETOSFilterEngine的所有抽象方法。

来自Java doc

  

接口形成了班级与外界的契约,   此合同在编译时在构建时强制执行。如果你的   class声称实现了一个接口,所有方法都是由它定义的   接口必须在类之前出现在其源代码中   成功编译。

检查链接:http://www-01.ibm.com/support/knowledgecenter/SSB23S_1.1.0.9/com.ibm.tpfops.doc_1112/aaeo1/fengapi.html?cp=SSB23S_1.1.0.9%2F2-3-10-3

以下是您需要实现的ETOSFilterEngine中存在的5种方法。

public MessageBlock doFilter (MessageBlock) throws
          FilterRuntimeException;
     public void modifyState (Object[ ]) throws
          FilterConfigurationException,
          FilterRuntimeException;
     public boolean isActive();
     public void shutdown();
     public String getName();

上面的链接有一个关于如何正确实现此接口的代码示例。您可以看到示例中的类ZSTATEngine正在实现ETOSFilterEngine提供的所有5种方法。

  

检查导入中MessageBlock的类型,它应该是导入的   com.ibm.tpf.etos.api.MessageBlock;我可以看到你已经评论了你的导入错误。

     

取消注释该行:import com.ibm.tpf.etos.api.MessageBlock;

答案 1 :(得分:1)

AS“Jakub Zaverka”提到,也许你在classpath或build路径中有两个版本。检查jar命令,是否选择正确的类......即使没有代码更改也会发生。

找到它的一种方法是,只需在ETOSFilterEngine上执行F3,然后单击包浏览器中的“使用编辑器链接”选项。它将显示.class文件和从中拾取的jar。如果它来自错误的jar或旧jar,只需转到Project&gt; Properties&gt; Build Path&gt; Order and Export并将右jar的顺序更改为顶部,点击顶部按钮..

相关问题