# ユーザー定義インジケーターのJavaアーカイブを作成

利用対象...

* Big Data Platform
* Cloud API Services Platform
* Cloud Big Data Platform
* Cloud Data Fabric
* Cloud Data Management Platform
* Data Fabric
* Data Management Platform
* Data Services Platform
* MDM Platform
* Real-Time Big Data Platform

ユーザー定義インジケーターにJavaアーカイブを作成する前に、ワークスペースプラグインのコンパイルとテストの対象となるターゲットプラットフォームをEclipseで定義する必要があります。

## 始める前に

Profilingパースペクティブを選択済みであること。

## 手順

1. ターゲットプラットフォームを定義します。
   1. Eclipseで、[Preferences] (環境設定)を選択して[Preferences] (環境設定)ウィンドウを表示します。
   2. [Plug-in Development] (プラグイン開発)を展開して[Target Platform] (ターゲットプラットフォーム)を選択し、[Add...] (追加...)をクリックしてターゲット定義を作成するためのビューを開きます。
   3. [Nothing: Start with an empty target definition] (なし: 空のターゲット定義で始める)オプションを選択し、[Next] (次へ)をクリックします。

      ![](https://help.qlik.com/talend/ja-JP/studio-user-guide/Resources/images/Java_target_platform2.png)
   4. [Name] (名前)フィールドに新しいターゲット定義の名前を入力し、[Next] (次へ)をクリックします。

      ![](https://help.qlik.com/talend/ja-JP/studio-user-guide/Resources/images/Java_target_platform3.png)
   5. [Add Content] (コンテンツを追加)リストから[Installation] (インストール)を選択し、[Next] (次へ)をクリックします。

      ![](https://help.qlik.com/talend/ja-JP/studio-user-guide/Resources/images/Java_target_platform4.png)
   6. [Browse...] (参照...)ボタンを使ってインストールディレクトリーのパスを設定し、[Next] (次へ)をクリックします。

      ![](https://help.qlik.com/talend/ja-JP/studio-user-guide/Resources/images/Java_target_platform5.png)

      場所のリストに新しいターゲット定義が表示されます。

      場所のリストに新しいターゲット定義が表示されます。 ![](https://help.qlik.com/talend/ja-JP/studio-user-guide/Resources/images/Java_target_platform6.png)
   7. [Finish] (終了)をクリックしてダイアログボックスを閉じます。
2. ユーザー定義インジケーターのJavaアーカイブを作成
   1. Eclipseでは、[project from GIT](https://github.com/Talend/tdq-studio-se/tree/master/sample/test.myudi) (英語のみ)をご覧ください。

      このJavaプロジェクトには、インジケーターエディターの[Indicator Category] (インジケーターカテゴリー)ビューにリスト表示されたインジケーターカテゴリーに対応する4つのJavaクラスがあります。

      このJavaプロジェクトには、インジケーターエディターの[Indicator Category] (インジケーターカテゴリー)[Indicator Category] (インジケーターカテゴリー)ビューにリスト表示されたインジケーターカテゴリーに対応する4つのJavaクラスがあります。 ![](https://help.qlik.com/talend/ja-JP/studio-user-guide/Resources/images/Java_Classes.png)

      どのJavaクラスもUserDefIndicatorImplインジケーターを拡張します。下の図は、MyAvgLength Javaクラスを使った例を示したものです。

      どのJavaクラスもUserDefIndicatorImplUserDefIndicatorImplインジケーターを拡張します。下の図は、MyAvgLengthMyAvgLength Javaクラスを使った例を示したものです。
      ```
      package test.udi;

      import org.talend.dataquality.indicators.sql.impl.UserDefIndicatorImpl;

      /**
       * @author mzhao
       * 
       * A very simple example of a java implementation of a user defined indicator. This indicator returns a user defined
       * real value. It implements the minimum number of required methods.
       */
      public class MyAvgLength extends UserDefIndicatorImpl {

          private double length = 0;

          @Override
          public boolean reset() {
              super.reset();
              length = 0;
              return true;
          }

          @Override
          public boolean handle(Object data) {
              super.handle(data);
              // an indicator which computes the average text length on data which are more than 2 characters (this means that
              // text values with less than 2 characters are not taken into account).
              int dataLength = (data != null) ? data.toString().length() : 0;
              if (dataLength > 2) {
                  length += dataLength;
              }
              return true;
          }

          /*
           * (non-Javadoc)
           * 
           * @see org.talend.dataquality.indicators.impl.IndicatorImpl#finalizeComputation()
           */
          @Override
          public boolean finalizeComputation() {
              value = String.valueOf(this.length / (this.getCount() - this.getNullCount()));
              return super.finalizeComputation();
          }

      }
      ```

      `package test.udi;

      import org.talend.dataquality.indicators.sql.impl.UserDefIndicatorImpl;

      /**
       * @author mzhao
       * 
       * A very simple example of a java implementation of a user defined indicator. This indicator returns a user defined
       * real value. It implements the minimum number of required methods.
       */
      public class MyAvgLength extends UserDefIndicatorImpl {

          private double length = 0;

          @Override
          public boolean reset() {
              super.reset();
              length = 0;
              return true;
          }

          @Override
          public boolean handle(Object data) {
              super.handle(data);
              // an indicator which computes the average text length on data which are more than 2 characters (this means that
              // text values with less than 2 characters are not taken into account).
              int dataLength = (data != null) ? data.toString().length() : 0;
              if (dataLength > 2) {
                  length += dataLength;
              }
              return true;
          }

          /*
           * (non-Javadoc)
           * 
           * @see org.talend.dataquality.indicators.impl.IndicatorImpl#finalizeComputation()
           */
          @Override
          public boolean finalizeComputation() {
              value = String.valueOf(this.length / (this.getCount() - this.getNullCount()));
              return super.finalizeComputation();
          }

      }`
      ```
      package test.udi;

      import org.talend.dataquality.indicators.sql.impl.UserDefIndicatorImpl;

      /**
       * @author mzhao
       * 
       * A very simple example of a java implementation of a user defined indicator. This indicator returns a user defined
       * real value. It implements the minimum number of required methods.
       */
      public class MyAvgLength extends UserDefIndicatorImpl {

          private double length = 0;

          @Override
          public boolean reset() {
              super.reset();
              length = 0;
              return true;
          }

          @Override
          public boolean handle(Object data) {
              super.handle(data);
              // an indicator which computes the average text length on data which are more than 2 characters (this means that
              // text values with less than 2 characters are not taken into account).
              int dataLength = (data != null) ? data.toString().length() : 0;
              if (dataLength > 2) {
                  length += dataLength;
              }
              return true;
          }

          /*
           * (non-Javadoc)
           * 
           * @see org.talend.dataquality.indicators.impl.IndicatorImpl#finalizeComputation()
           */
          @Override
          public boolean finalizeComputation() {
              value = String.valueOf(this.length / (this.getCount() - this.getNullCount()));
              return super.finalizeComputation();
          }

      }
      ```

      `package test.udi;

      import org.talend.dataquality.indicators.sql.impl.UserDefIndicatorImpl;

      /**
       * @author mzhao
       * 
       * A very simple example of a java implementation of a user defined indicator. This indicator returns a user defined
       * real value. It implements the minimum number of required methods.
       */
      public class MyAvgLength extends UserDefIndicatorImpl {

          private double length = 0;

          @Override
          public boolean reset() {
              super.reset();
              length = 0;
              return true;
          }

          @Override
          public boolean handle(Object data) {
              super.handle(data);
              // an indicator which computes the average text length on data which are more than 2 characters (this means that
              // text values with less than 2 characters are not taken into account).
              int dataLength = (data != null) ? data.toString().length() : 0;
              if (dataLength > 2) {
                  length += dataLength;
              }
              return true;
          }

          /*
           * (non-Javadoc)
           * 
           * @see org.talend.dataquality.indicators.impl.IndicatorImpl#finalizeComputation()
           */
          @Override
          public boolean finalizeComputation() {
              value = String.valueOf(this.length / (this.getCount() - this.getNullCount()));
              return super.finalizeComputation();
          }

      }``package test.udi;

      import org.talend.dataquality.indicators.sql.impl.UserDefIndicatorImpl;

      /**
       * @author mzhao
       * 
       * A very simple example of a java implementation of a user defined indicator. This indicator returns a user defined
       * real value. It implements the minimum number of required methods.
       */
      public class MyAvgLength extends UserDefIndicatorImpl {

          private double length = 0;

          @Override
          public boolean reset() {
              super.reset();
              length = 0;
              return true;
          }

          @Override
          public boolean handle(Object data) {
              super.handle(data);
              // an indicator which computes the average text length on data which are more than 2 characters (this means that
              // text values with less than 2 characters are not taken into account).
              int dataLength = (data != null) ? data.toString().length() : 0;
              if (dataLength > 2) {
                  length += dataLength;
              }
              return true;
          }

          /*
           * (non-Javadoc)
           * 
           * @see org.talend.dataquality.indicators.impl.IndicatorImpl#finalizeComputation()
           */
          @Override
          public boolean finalizeComputation() {
              value = String.valueOf(this.length / (this.getCount() - this.getNullCount()));
              return super.finalizeComputation();
          }

      }`package test.udi; import org.talend.dataquality.indicators.sql.impl.UserDefIndicatorImpl; /\*\* \* @author mzhao \* \* A very simple example of a java implementation of a user defined indicator. This indicator returns a user defined \* real value. It implements the minimum number of required methods. \*/ public class MyAvgLength extends UserDefIndicatorImpl { private double length = 0; @Override public boolean reset() { super.reset(); length = 0; return true; } @Override public boolean handle(Object data) { super.handle(data); // an indicator which computes the average text length on data which are more than 2 characters (this means that // text values with less than 2 characters are not taken into account). int dataLength = (data != null) ? data.toString().length() : 0; if (dataLength &gt; 2) { length += dataLength; } return true; } /\* \* (non-Javadoc) \* \* @see org.talend.dataquality.indicators.impl.IndicatorImpl#finalizeComputation() \*/ @Override public boolean finalizeComputation() { value = String.valueOf(this.length / (this.getCount() - this.getNullCount())); return super.finalizeComputation(); } }
   2. 必要に応じて、各@Overrideに続くメソッドのコードを編集してください。
   3. オプション: 次のメソッドをコードで使い、インジケーターのパラメーターを取得します。
      | メソッド | 説明 |
      | --- | --- |
      | ndicatorParameters | IndicatorParametersオブジェクトを返します |
      | omain | ドメインオブジェクトを返します |
      | JavaUDIIndicatorParameter | パラメーターを定義するキー/値の各ペアを保存するJavaUDIIndicatorParameterのリストを返します。 |
   4. 変更を保存します。
   5. Eclipseを使用してこの新しいJavaアーカイブをエクスポートします。

## タスクの結果

以上で、Profilingパースペクティブで作成するどのJavaインジケーターにもJavaアーカイブを添付できるようになります。